Skip to content

Commit

Permalink
Merge pull request RipMeApp#1407 from Isaaku/issues/1402_confirm_clear
Browse files Browse the repository at this point in the history
Issues/1402 confirm clear
  • Loading branch information
cyian-1756 authored Sep 3, 2019
2 parents 2ec067f + 557a8be commit 5f3533e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 26 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Java CI

on: [push, pull_request]

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
java: [1.8, 1.9]

steps:
- uses: actions/checkout@v1
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: Build with Maven
run: mvn package --file pom.xml
20 changes: 15 additions & 5 deletions src/main/java/com/rarchives/ripme/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,13 @@ private void updateQueue(DefaultListModel<Object> model) {
if (model == null)
model = queueListModel;

Utils.setConfigList("Queue", (Enumeration<Object>) model.elements());
if (model.size() > 0) {
Utils.setConfigList("queue", (Enumeration<Object>) model.elements());
Utils.saveConfig();

MainWindow.optionQueue.setText(String.format("%s%s", Utils.getLocalizedString("queue"),
model.size() == 0 ? "" : "(" + model.size() + ")"));
MainWindow.optionQueue.setText(String.format("%s%s", Utils.getLocalizedString("queue"),
model.size() == 0 ? "" : "(" + model.size() + ")"));
}
}

private void updateQueue() {
Expand Down Expand Up @@ -259,6 +262,7 @@ private void pack() {

private boolean isCollapsed() {
return (!logPanel.isVisible() && !historyPanel.isVisible() && !queuePanel.isVisible()

&& !configurationPanel.isVisible());
}

Expand Down Expand Up @@ -479,8 +483,10 @@ public void setValueAt(Object value, int row, int col) {
queueListModel = new DefaultListModel();
JList queueList = new JList(queueListModel);
queueList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
queueList.addMouseListener(queueMenuMouseListener = new QueueMenuMouseListener());
queueList.addMouseListener(
queueMenuMouseListener = new QueueMenuMouseListener(d -> updateQueue(queueListModel)));
JScrollPane queueListScroll = new JScrollPane(queueList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,

JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
for (String item : Utils.getConfigList("queue")) {
queueListModel.addElement(item);
Expand Down Expand Up @@ -856,6 +862,7 @@ private void update() {
}
if (added == 0) {
JOptionPane.showMessageDialog(null, Utils.getLocalizedString("history.load.none.checked"),

"RipMe Error", JOptionPane.ERROR_MESSAGE);
}
});
Expand Down Expand Up @@ -1026,6 +1033,7 @@ public void windowIconified(WindowEvent e) {
MenuItem trayMenuAbout = new MenuItem("About " + mainFrame.getTitle());
trayMenuAbout.addActionListener(arg0 -> {
StringBuilder about = new StringBuilder();

about.append("<html><h1>").append(mainFrame.getTitle()).append("</h1>");
about.append("Download albums from various websites:");
try {
Expand Down Expand Up @@ -1164,6 +1172,7 @@ private void loadHistory() {
LOGGER.error("Failed to load history from file " + historyFile, e);
JOptionPane.showMessageDialog(null,
String.format(Utils.getLocalizedString("history.load.failed.warning"), e.getMessage()),

"RipMe - history load failure", JOptionPane.ERROR_MESSAGE);
}
} else {
Expand Down Expand Up @@ -1202,7 +1211,6 @@ private void saveHistory() {
}
}

@SuppressWarnings("unchecked")
private void ripNextAlbum() {
isRipping = true;
// Save current state of queue to configuration.
Expand Down Expand Up @@ -1445,6 +1453,8 @@ private synchronized void handleEvent(StatusEvent evt) {
}
/*
* content key %path% the path to the album folder %url% is the album url
*
*
*/
if (Utils.getConfigBoolean("enable.finish.command", false)) {
try {
Expand Down
45 changes: 24 additions & 21 deletions src/main/java/com/rarchives/ripme/ui/QueueMenuMouseListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,33 @@
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Enumeration;
import java.util.function.Consumer;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;

import com.rarchives.ripme.utils.Utils;

class QueueMenuMouseListener extends MouseAdapter {
private JPopupMenu popup = new JPopupMenu();
private JList queueList;
private DefaultListModel queueListModel;
private JList<Object> queueList;
private DefaultListModel<Object> queueListModel;
private Consumer<DefaultListModel<Object>> updateQueue;

@SuppressWarnings("serial")
public QueueMenuMouseListener() {
public QueueMenuMouseListener(Consumer<DefaultListModel<Object>> updateQueue) {
this.updateQueue = updateQueue;
updateUI();
}

@SuppressWarnings("serial")
public void updateUI() {
popup.removeAll();

Action removeSelected = new AbstractAction("Remove Selected") {
Action removeSelected = new AbstractAction(Utils.getLocalizedString("queue.remove.selected")) {
@Override
public void actionPerformed(ActionEvent ae) {
Object o = queueList.getSelectedValue();
Expand All @@ -35,36 +43,31 @@ public void actionPerformed(ActionEvent ae) {
};
popup.add(removeSelected);

Action clearQueue = new AbstractAction("Remove All") {
Action clearQueue = new AbstractAction(Utils.getLocalizedString("queue.remove.all")) {
@Override
public void actionPerformed(ActionEvent ae) {
queueListModel.removeAllElements();
updateUI();
if (JOptionPane.showConfirmDialog(null, Utils.getLocalizedString("queue.validation"), "RipMe",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
queueListModel.removeAllElements();
updateUI();
}
}
};
popup.add(clearQueue);

updateQueue.accept(queueListModel);
}

private void updateUI() {
Utils.setConfigList("queue", (Enumeration<Object>) queueListModel.elements());

if (queueListModel.size() == 0) {
MainWindow.optionQueue.setText("Queue");
}
else {
MainWindow.optionQueue.setText("Queue (" + queueListModel.size() + ")");
}
}
@SuppressWarnings("unchecked")
@Override
public void mouseClicked(MouseEvent e) {
if (e.getModifiers() == InputEvent.BUTTON3_MASK) {
if (!(e.getSource() instanceof JList)) {
return;
}

queueList = (JList) e.getSource();
queueListModel = (DefaultListModel) queueList.getModel();
queueList = (JList<Object>) e.getSource();
queueListModel = (DefaultListModel<Object>) queueList.getModel();
queueList.requestFocus();

int nx = e.getX();
Expand Down

0 comments on commit 5f3533e

Please sign in to comment.