From b971c4c754ce95085b0a4e5d1e26b8919c7d8b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sat, 19 Nov 2022 19:52:59 +0100 Subject: [PATCH] Fixed Move/Copy tag to action on tag scripts Refreshing pin path Fixed pin after move to action --- CHANGELOG.md | 1 + .../jpexs/decompiler/flash/gui/PinButton.java | 26 +++++++++++++--- .../jpexs/decompiler/flash/gui/PinsPanel.java | 30 ++++++++----------- .../flash/gui/tagtree/TagTreeContextMenu.java | 25 ++++++++-------- 4 files changed, 48 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3052858a5..0aed7ab1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ All notable changes to this project will be documented in this file. - Header of display panel not visible on certain color schemes - Move tag to action did not remove original tag - Show in tag list from tag scripts +- Move/Copy tag to action on tag scripts ### Changed - GFX - DefineExternalImage2 no longer handled as character diff --git a/src/com/jpexs/decompiler/flash/gui/PinButton.java b/src/com/jpexs/decompiler/flash/gui/PinButton.java index 810119a8f..51c6885d5 100644 --- a/src/com/jpexs/decompiler/flash/gui/PinButton.java +++ b/src/com/jpexs/decompiler/flash/gui/PinButton.java @@ -36,6 +36,7 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import javax.swing.tree.TreePath; import org.pushingpixels.substance.api.ColorSchemeAssociationKind; import org.pushingpixels.substance.api.ComponentState; import org.pushingpixels.substance.api.DecorationAreaType; @@ -113,9 +114,8 @@ public class PinButton extends JPanel { label = new JLabel(); - label.setIcon(AbstractTagTree.getIconFor(item)); - label.setText(mainPanel.itemToString(item)); - + label.setIcon(AbstractTagTree.getIconFor(item)); + refresh(); button = new JLabel(); button.setMinimumSize(new Dimension(10 + 16, 16)); button.setPreferredSize(new Dimension(10 + 16, 16)); @@ -175,6 +175,8 @@ public class PinButton extends JPanel { }; addMouseListener(adapter); addMouseMotionListener(adapter); + label.addMouseListener(adapter); + label.addMouseMotionListener(adapter); button.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); @@ -233,7 +235,7 @@ public class PinButton extends JPanel { setLayout(new BorderLayout()); add(label, BorderLayout.CENTER); - add(button, BorderLayout.EAST); + add(button, BorderLayout.EAST); } private void updateIcon() { @@ -318,8 +320,24 @@ public class PinButton extends JPanel { g.drawLine(0, 2, getWidth() - 1, 2); } } + + private String getTreeItemPath(TreeItem item) { + TreePath path = mainPanel.getCurrentTree().getModel().getTreePath(item); + if (path == null) { + return ""; + } + StringBuilder pathString = new StringBuilder(); + for (int i = 1; i < path.getPathCount(); i++) { + if (pathString.length() > 0) { + pathString.append(" / "); + } + pathString.append(mainPanel.itemToString((TreeItem) path.getPathComponent(i))); + } + return pathString.toString(); + } public void refresh() { label.setText(mainPanel.itemToString(item)); + label.setToolTipText(getTreeItemPath(item)); } } diff --git a/src/com/jpexs/decompiler/flash/gui/PinsPanel.java b/src/com/jpexs/decompiler/flash/gui/PinsPanel.java index f8b6f8d50..b25b4d961 100644 --- a/src/com/jpexs/decompiler/flash/gui/PinsPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/PinsPanel.java @@ -136,21 +136,7 @@ public class PinsPanel extends JPanel { rebuild(); } - - private String getTreeItemPath(TreeItem item) { - TreePath path = mainPanel.getCurrentTree().getModel().getTreePath(item); - if (path == null) { - return ""; - } - StringBuilder pathString = new StringBuilder(); - for (int i = 1; i < path.getPathCount(); i++) { - if (pathString.length() > 0) { - pathString.append(" / "); - } - pathString.append(mainPanel.itemToString((TreeItem) path.getPathComponent(i))); - } - return pathString.toString(); - } + private void rebuild() { removeAll(); @@ -159,7 +145,6 @@ public class PinsPanel extends JPanel { boolean currentPinned = false; for (TreeItem item : items) { PinButton pinButton = new PinButton(mainPanel, item, true); - pinButton.setToolTipText(getTreeItemPath(item)); pinButton.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { @@ -247,7 +232,6 @@ public class PinsPanel extends JPanel { currentUnpinnedButton = new PinButton(mainPanel, current, false); lastSelectedButton = currentUnpinnedButton; add(currentUnpinnedButton); - currentUnpinnedButton.setToolTipText(getTreeItemPath(current)); currentUnpinnedButton.setSelected(true); currentUnpinnedButton.addChangeListener(new ChangeListener() { @Override @@ -395,8 +379,18 @@ public class PinsPanel extends JPanel { } public void replaceItem(TreeItem oldItem, TreeItem newItem) { + + TreeItem oldItemNoTs = oldItem; + if (oldItem instanceof TagScript) { + oldItemNoTs = ((TagScript) oldItem).getTag(); + } + for (int i = 0; i < items.size(); i++) { - if (items.get(i) == oldItem) { + TreeItem item2NoTs = items.get(i); + if (item2NoTs instanceof TagScript) { + item2NoTs = ((TagScript) item2NoTs).getTag(); + } + if (item2NoTs == oldItemNoTs) { items.set(i, newItem); rebuild(); break; diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java index dc400cb66..9beb7af1d 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java @@ -959,15 +959,16 @@ public class TagTreeContextMenu extends JPopupMenu { copyTagToMenu.removeAll(); copyTagToWithDependenciesMenu.removeAll(); - if (allSelectedIsTag) { - List tagItems = new ArrayList<>(); - for (TreeItem item : items) { - if (item instanceof TagScript) { - tagItems.add(((TagScript) item).getTag()); - } else { - tagItems.add((Tag) item); - } + List tagItems = new ArrayList<>(); + for (TreeItem item : items) { + if (item instanceof TagScript) { + tagItems.add(((TagScript) item).getTag()); + } else { + tagItems.add((Tag) item); } + } + if (allSelectedIsTag) { + JMenuItem copyToClipboardMenuItem = new JMenuItem(AppStrings.translate("contextmenu.clipboard") + " (CTRL+C)", View.getIcon("clipboard16")); copyToClipboardMenuItem.addActionListener(new ActionListener() { @Override @@ -999,10 +1000,10 @@ public class TagTreeContextMenu extends JPopupMenu { if ((targetSwfList.size() == 1) && (targetSwfList.get(0) == singleSwf)) { continue; } - addCopyMoveToMenusSwfList(KIND_MOVETO, singleSwf, targetSwfList, moveTagToMenu, items); - addCopyMoveToMenusSwfList(KIND_MOVETODEPS, singleSwf, targetSwfList, moveTagToWithDependenciesMenu, items); - addCopyMoveToMenusSwfList(KIND_COPYTO, singleSwf, targetSwfList, copyTagToMenu, items); - addCopyMoveToMenusSwfList(KIND_COPYTODEPS, singleSwf, targetSwfList, copyTagToWithDependenciesMenu, items); + addCopyMoveToMenusSwfList(KIND_MOVETO, singleSwf, targetSwfList, moveTagToMenu, tagItems); + addCopyMoveToMenusSwfList(KIND_MOVETODEPS, singleSwf, targetSwfList, moveTagToWithDependenciesMenu, tagItems); + addCopyMoveToMenusSwfList(KIND_COPYTO, singleSwf, targetSwfList, copyTagToMenu, tagItems); + addCopyMoveToMenusSwfList(KIND_COPYTODEPS, singleSwf, targetSwfList, copyTagToWithDependenciesMenu, tagItems); } moveTagToMenu.setVisible(true); moveTagToWithDependenciesMenu.setVisible(true);