diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c48898a8..cb445362e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Added +- [#1898] Keyboard shortcut to remove tags (DEL, SHIFT+DEL) + ### Fixed - [#1897] Close menu button without selecting specific item @@ -2678,6 +2681,7 @@ All notable changes to this project will be documented in this file. [alpha 9]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha8...alpha9 [alpha 8]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha7...alpha8 [alpha 7]: https://github.com/jindrapetrik/jpexs-decompiler/releases/tag/alpha7 +[#1898]: https://www.free-decompiler.com/flash/issues/1898 [#1897]: https://www.free-decompiler.com/flash/issues/1897 [#1888]: https://www.free-decompiler.com/flash/issues/1888 [#1895]: https://www.free-decompiler.com/flash/issues/1895 diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 5a3e1ee26..2a7064fff 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -511,6 +511,21 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se private void handleTreeKeyPressed(KeyEvent e) { AbstractTagTree tree = (AbstractTagTree) e.getSource(); + if ((e.getKeyCode() == KeyEvent.VK_DELETE) && !e.isControlDown() && !e.isAltDown()) { + TreePath[] paths = tree.getSelectionPaths(); + if (paths == null || paths.length == 0) { + return; + } + List items = new ArrayList<>(); + for (TreePath treePath : paths) { + TreeItem item = (TreeItem) treePath.getLastPathComponent(); + items.add(item); + } + if (contextPopupMenu.canRemove(items)) { + contextPopupMenu.update(items); + contextPopupMenu.removeItemActionPerformed(null, e.isShiftDown()); + } + } if ((e.getKeyCode() == 'C' || e.getKeyCode() == 'X') && (e.isControlDown())) { TreePath[] paths = tree.getSelectionPaths(); if (paths == null || paths.length == 0) { diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java index e7d0ffa31..b389f66cc 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java @@ -282,14 +282,14 @@ public class TagTreeContextMenu extends JPopupMenu { } add(changeCharsetMenu); - removeMenuItem = new JMenuItem(mainPanel.translate("contextmenu.remove")); + removeMenuItem = new JMenuItem(mainPanel.translate("contextmenu.remove") + " (DEL)"); removeMenuItem.addActionListener((ActionEvent e) -> { removeItemActionPerformed(e, false); }); removeMenuItem.setIcon(View.getIcon("remove16")); add(removeMenuItem); - removeWithDependenciesMenuItem = new JMenuItem(mainPanel.translate("contextmenu.removeWithDependencies")); + removeWithDependenciesMenuItem = new JMenuItem(mainPanel.translate("contextmenu.removeWithDependencies") + " (SHIFT+DEL)"); removeWithDependenciesMenuItem.addActionListener((ActionEvent e) -> { removeItemActionPerformed(e, true); }); @@ -624,32 +624,14 @@ public class TagTreeContextMenu extends JPopupMenu { return mainPanel.getCurrentTree(); } - public void update(final List items) { - - if (items.isEmpty()) { - return; - } - - this.items = items; - - AbstractTagTree tree = getTree(); - - final List swfs = mainPanel.getSwfs(); - - boolean canRemove = true; - boolean allDoNotHaveDependencies = true; + public boolean canRemove(final List items) { for (TreeItem item : items) { if (!(item instanceof Tag) && !(item instanceof Frame)) { if (item instanceof TagScript) { - Tag tag = ((TagScript) item).getTag(); - if (tag instanceof DoActionTag || tag instanceof DoInitActionTag) { - allDoNotHaveDependencies = false; - } continue; } if (item instanceof AS2Package) { - allDoNotHaveDependencies = false; continue; } @@ -675,10 +657,44 @@ public class TagTreeContextMenu extends JPopupMenu { continue; } - canRemove = false; - break; + return false; + } + } + return true; + } + + public void update(final List items) { + + if (items.isEmpty()) { + return; + } + + this.items = items; + + AbstractTagTree tree = getTree(); + + final List swfs = mainPanel.getSwfs(); + + boolean canRemove = canRemove(items); + boolean allDoNotHaveDependencies = true; + for (TreeItem item : items) { + if (!(item instanceof Tag) && !(item instanceof Frame)) { + if (item instanceof TagScript) { + Tag tag = ((TagScript) item).getTag(); + if (tag instanceof DoActionTag || tag instanceof DoInitActionTag) { + allDoNotHaveDependencies = false; + break; + } + continue; + } + + if (item instanceof AS2Package) { + allDoNotHaveDependencies = false; + break; + } } else { allDoNotHaveDependencies = false; + break; } } @@ -2267,7 +2283,7 @@ public class TagTreeContextMenu extends JPopupMenu { } } - private void removeItemActionPerformed(ActionEvent evt, boolean removeDependencies) { + public void removeItemActionPerformed(ActionEvent evt, boolean removeDependencies) { List tps = new ArrayList<>();