From ea9cc3bca720411ad0bd827d79bc4ca2c794bd04 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 22 Nov 2012 14:11:55 +0000 Subject: [PATCH] * Added Revert button for people that can't figure out the Revert ContextMenu --- .../filebot/resources/action.revert.png | Bin 0 -> 1240 bytes .../filebot/ui/rename/HistoryDialog.java | 78 ++++++++++++++---- 2 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 source/net/sourceforge/filebot/resources/action.revert.png diff --git a/source/net/sourceforge/filebot/resources/action.revert.png b/source/net/sourceforge/filebot/resources/action.revert.png new file mode 100644 index 0000000000000000000000000000000000000000..4ef7981af1f07bbd6a3387c5de6eaaddd84a124d GIT binary patch literal 1240 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE(}6TtKSRv1wTBrPm<2pt978NlFP-e`6O$^^Hve~RdEHETwi$}X z!3re}2l;&4W@Wr`>x}O8lrFt8C8^VJsvFa`t3I<3ylV8j}zP^TrhK*B%e6MS4S6}(J zX4;=KtYtR0yjLC--)*#lcg6CazxOwB)a_^2R9Tj~Xo14gl$siuhLa~fbIhbySF_!W znVFib>2GjPZFRYKddT+MXP>ysKmJ&8a=i{?Kt$}b&Hm>C*M?bq`o*y->+mL>J#qS5 z_lewkI(dsrbYQ5Upyux_m49w%ygq80V`k0Zqf zRI~8qVXgyrRy}mf0zc4N-Kyipaw$&T?3#7!w>^YD+3EFV+)9eXFp>r zQ8eV{r(~v8;?^*I$#E?HoS&x< yl98I5dhn-OCQyk2LP>mRkPpmRiA5!P>3R9NsbB{gJ(&pdFoUP7pUXO@geCw~n*H 0) { JPopupMenu menu = new JPopupMenu(); - menu.add(new RevertAction(selection, HistoryDialog.this)); + menu.add(new RevertSelectionAction(selection)); // display popup menu.show(table, e.getX(), e.getY()); @@ -387,22 +387,65 @@ class HistoryDialog extends JDialog { }; - private static class RevertAction extends AbstractAction { + private class RevertCurrentSelectionAction extends RevertAction { + + public RevertCurrentSelectionAction() { + super("Revert Selection", HistoryDialog.this); + } + + + @Override + public List elements() { + List selection = new ArrayList(); + + if (sequenceTable.getSelectedRow() >= 0) { + for (int i : sequenceTable.getSelectedRows()) { + int index = sequenceTable.convertRowIndexToModel(i); + selection.addAll(sequenceModel.getRow(index).elements()); + } + } else if (elementTable.getSelectedRow() >= 0) { + for (int i : elementTable.getSelectedRows()) { + int index = elementTable.convertRowIndexToModel(i); + selection.add(elementModel.getRow(index)); + } + } + + return selection; + } + } + + + private class RevertSelectionAction extends RevertAction { public static final String ELEMENTS = "elements"; + + + public RevertSelectionAction(Collection elements) { + super("Revert...", HistoryDialog.this); + putValue(ELEMENTS, elements.toArray(new Element[0])); + } + + + @Override + public List elements() { + return Arrays.asList((Element[]) getValue(ELEMENTS)); + } + } + + + private static abstract class RevertAction extends AbstractAction { + public static final String PARENT = "parent"; - public RevertAction(Collection elements, HistoryDialog parent) { - putValue(NAME, "Revert..."); - putValue(ELEMENTS, elements.toArray(new Element[0])); + public RevertAction(String name, HistoryDialog parent) { + putValue(NAME, name); + putValue(SMALL_ICON, ResourceManager.getIcon("action.revert")); putValue(PARENT, parent); } - public Element[] elements() { - return (Element[]) getValue(ELEMENTS); - } + public abstract List elements(); public HistoryDialog parent() { @@ -437,6 +480,10 @@ class HistoryDialog extends JDialog { @Override public void actionPerformed(ActionEvent e) { + List elements = elements(); + if (elements.isEmpty()) + return; + // use default directory File directory = null; @@ -451,7 +498,7 @@ class HistoryDialog extends JDialog { Set