From e38a3e3863ebf2523e192ba2d933a37ff5dfe631 Mon Sep 17 00:00:00 2001 From: "Christian F." Date: Sun, 18 Aug 2024 22:25:50 +0200 Subject: [PATCH] - delete selected list entries via DELETE key --- CHANGELOG.md | 1 + .../gui/tabs/tab_film/EditHistoryDialog.java | 66 ++++++++++++++----- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b8072b312..d36405a665 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - **BUGFIX:** MV aktualisiert nun vor dem Download mittels `-dq` oder `--download-quit` Parameter die Filmliste. - **BUGFIX:** FlatLaf Regression gelöst, die manchmal zu einer inkorrekten Darstellung der Oberfläche führte. - **FEATURE(Linux/Windows):** Das Aussehen von FlatLaf kann in `.mediathek3/flatlaf` angepasst werden. +- **FEATURE:** Selektierte Einträge in `Suchhistorie bearbeiten`-Dialog können nun mittels Entfernen-Taste gelöscht werden. # **14.1.0** - JDK 21 wird nun mitgeliefert. Behebt primär Darstellungsfehler von Java Apps unter Windows. diff --git a/src/main/java/mediathek/gui/tabs/tab_film/EditHistoryDialog.java b/src/main/java/mediathek/gui/tabs/tab_film/EditHistoryDialog.java index 64f442acd9..93258eca0d 100644 --- a/src/main/java/mediathek/gui/tabs/tab_film/EditHistoryDialog.java +++ b/src/main/java/mediathek/gui/tabs/tab_film/EditHistoryDialog.java @@ -14,6 +14,8 @@ import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.ArrayList; @@ -30,6 +32,18 @@ public class EditHistoryDialog extends JDialog { private final EventList eventList; private final Function inc_op = f -> f + 1; private final Function dec_op = f -> f - 1; + private final DeleteKeyAdapter keyAdapter = new DeleteKeyAdapter(); + private boolean keyAdapterInstalled; + + private class DeleteKeyAdapter extends KeyAdapter { + @Override + public void keyReleased(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_DELETE) { + e.consume(); + deleteEntries(); + } + } + } public EditHistoryDialog(Window owner, JMenuItem menuItem, EventList eventList) { super(owner); @@ -55,23 +69,7 @@ public void windowClosed(WindowEvent e) { }); adjustButtons(); - btnDeleteEntries.addActionListener(l -> { - var changeList = new ArrayList(); - var listModel = list.getModel(); - for (var idx : list.getSelectedIndices()) { - changeList.add(listModel.getElementAt(idx)); - } - - var lock = eventList.getReadWriteLock().writeLock(); - lock.lock(); - try { - changeList.forEach(eventList::remove); - } - finally { - lock.unlock(); - } - changeList.clear(); - }); + btnDeleteEntries.addActionListener(l -> deleteEntries()); btnUp.addActionListener(l -> { var idx = list.getSelectedIndex(); @@ -88,6 +86,24 @@ public void windowClosed(WindowEvent e) { restorePosition(); } + private void deleteEntries() { + var changeList = new ArrayList(); + var listModel = list.getModel(); + for (var idx : list.getSelectedIndices()) { + changeList.add(listModel.getElementAt(idx)); + } + + var lock = eventList.getReadWriteLock().writeLock(); + lock.lock(); + try { + changeList.forEach(eventList::remove); + } + finally { + lock.unlock(); + } + changeList.clear(); + } + private int moveEntry(int idx, Function operator) { var lock = eventList.getReadWriteLock().writeLock(); lock.lock(); @@ -151,6 +167,22 @@ private void adjustButtons() { if (idx == list.getModel().getSize() - 1) //last btnDown.setEnabled(false); } + setupKeyListener(itemCount); + } + + private void setupKeyListener(int itemCount) { + if (itemCount > 0) { + if (!keyAdapterInstalled) { + list.addKeyListener(keyAdapter); + keyAdapterInstalled = true; + } + } + else { + if (keyAdapterInstalled) { + list.removeKeyListener(keyAdapter); + keyAdapterInstalled = false; + } + } } private void initComponents() {