Skip to content

Commit

Permalink
- delete selected list entries via DELETE key
Browse files Browse the repository at this point in the history
  • Loading branch information
derreisende77 committed Aug 18, 2024
1 parent 920ca4f commit e38a3e3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
66 changes: 49 additions & 17 deletions src/main/java/mediathek/gui/tabs/tab_film/EditHistoryDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +32,18 @@ public class EditHistoryDialog extends JDialog {
private final EventList<String> eventList;
private final Function<Integer,Integer> inc_op = f -> f + 1;
private final Function<Integer,Integer> 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<String> eventList) {
super(owner);
Expand All @@ -55,23 +69,7 @@ public void windowClosed(WindowEvent e) {
});
adjustButtons();

btnDeleteEntries.addActionListener(l -> {
var changeList = new ArrayList<String>();
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();
Expand All @@ -88,6 +86,24 @@ public void windowClosed(WindowEvent e) {
restorePosition();
}

private void deleteEntries() {
var changeList = new ArrayList<String>();
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<Integer,Integer> operator) {
var lock = eventList.getReadWriteLock().writeLock();
lock.lock();
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit e38a3e3

Please sign in to comment.