From 76064f46ffc8ab4c4fded84e6074e92d37a0593b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sun, 20 Nov 2022 16:53:17 +0100 Subject: [PATCH] Fixes around adding classes. Adding classes in taglist view. --- .../decompiler/flash/timeline/AS3Package.java | 4 ++ .../flash/gui/abc/AddClassDialog.java | 15 ++++-- .../flash/gui/tagtree/TagTreeContextMenu.java | 48 +++++++++++++++---- 3 files changed, 54 insertions(+), 13 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/AS3Package.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/AS3Package.java index c6a340d1c..515452c74 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/AS3Package.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/AS3Package.java @@ -60,6 +60,10 @@ public class AS3Package extends AS3ClassTreeItem { public boolean isDefaultPackage() { return defaultPackage; } + + public boolean isFlat() { + return flat; + } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/AddClassDialog.java b/src/com/jpexs/decompiler/flash/gui/abc/AddClassDialog.java index 53ee236dc..a9e29c426 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/AddClassDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/AddClassDialog.java @@ -66,15 +66,20 @@ public class AddClassDialog extends AppDialog { private Openable openable; private int abcCount = 0; + + private ABCContainerTag preselectedAbcContainer; private JRadioButton existingAbcTagRadioButton = new JRadioButton(translate("abc.where.existing")); private JRadioButton newAbcTagRadioButton = new JRadioButton(translate("abc.where.new")); - public AddClassDialog(Window owner, Openable openable) { + public AddClassDialog(Window owner, Openable openable, ABCContainerTag abcContainer) { super(owner); this.openable = openable; abcCount = 0; - if (openable instanceof SWF) { + this.preselectedAbcContainer = abcContainer; + if (abcContainer != null) { + abcCount = 1; + } else if (openable instanceof SWF) { SWF swf = (SWF) openable; for (Tag t : swf.getTags()) { if (t instanceof ABCContainerTag) { @@ -118,7 +123,7 @@ public class AddClassDialog extends AppDialog { abcTargetPanel.setVisible(false); } - if (openable instanceof ABC) { + if (preselectedAbcContainer != null) { existingAbcTagRadioButton.setSelected(true); abcTargetPanel.setVisible(false); } @@ -221,8 +226,8 @@ public class AddClassDialog extends AppDialog { return; } setVisible(false); - if (openable instanceof ABC) { - selectedAbcContainer = ((ABC) openable).parentTag; + if (preselectedAbcContainer != null) { + selectedAbcContainer = preselectedAbcContainer; } else { if (existingAbcTagRadioButton.isSelected()) { SelectDoABCDialog selectDoABCDialog = new SelectDoABCDialog(owner, (SWF) openable); diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java index d7f0beaee..f2186282f 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java @@ -1576,6 +1576,9 @@ public class TagTreeContextMenu extends JPopupMenu { if (path[p] instanceof ABC) { break; } + if (path[p] instanceof ABCContainerTag) { + break; + } if (((AS3Package) path[p]).isDefaultPackage()) { break; } @@ -1584,12 +1587,25 @@ public class TagTreeContextMenu extends JPopupMenu { } TreePath scriptsPath = tree.getSelectionPaths()[0]; - while (!(scriptsPath.getLastPathComponent() instanceof ClassesListTreeModel) && !(scriptsPath.getLastPathComponent() instanceof ABC)) { + while (!(scriptsPath.getLastPathComponent() instanceof ClassesListTreeModel) && + !(scriptsPath.getLastPathComponent() instanceof ABC) && + !(scriptsPath.getLastPathComponent() instanceof ABCContainerTag) + ) { scriptsPath = scriptsPath.getParentPath(); } { - AddClassDialog acd = new AddClassDialog(Main.getDefaultDialogsOwner(), openable); + ABCContainerTag preselectedContainer = null; + + TreeItem scriptsNode = (TreeItem) scriptsPath.getLastPathComponent(); + + if (scriptsNode instanceof ABC) { + preselectedContainer = ((ABC)scriptsNode).parentTag; + } else if (scriptsNode instanceof ABCContainerTag) { + preselectedContainer = (ABCContainerTag) scriptsNode; + } + + AddClassDialog acd = new AddClassDialog(Main.getDefaultDialogsOwner(), openable, preselectedContainer); if (acd.showDialog(preselected) != AppDialog.OK_OPTION) { return; } @@ -1647,23 +1663,39 @@ public class TagTreeContextMenu extends JPopupMenu { swf.setModified(true); mainPanel.refreshTree(swf); - Object item = mainPanel.tagTree.getModel().getScriptsNode(swf); + Object item; + + if ((mainPanel.getCurrentView() == MainPanel.VIEW_RESOURCES) && (openable instanceof SWF)) { + item = mainPanel.tagTree.getModel().getScriptsNode((SWF) openable); + } else if (openable instanceof ABC) { + item = openable; + } else { //SWF on taglist, should be DoABCContainer + item = scriptsPath.getLastPathComponent(); + } - TreePath classPath = scriptsPath; - - for (int i = 0; i < parts.length; i++) { + //Object item = scriptsPath.getLastPathComponent(); + loopparts: for (int i = 0; i < parts.length; i++) { for (TreeItem ti : tree.getModel().getAllChildren(item)) { + if ((ti instanceof AS3Package) && ((AS3Package)ti).isFlat()) { + AS3Package pti = (AS3Package) ti; + if ((pkg.isEmpty() && pti.isDefaultPackage()) || (!pti.isDefaultPackage() && pkg.equals(pti.packageName))) { + item = pti; + i = parts.length - 1 - 1; + break; + } + continue; + } if (ti instanceof AS3ClassTreeItem) { AS3ClassTreeItem cti = (AS3ClassTreeItem) ti; + if (parts[i].equals(cti.getNameWithNamespaceSuffix())) { - classPath = classPath.pathByAddingChild(ti); item = ti; break; } } } } - mainPanel.tagTree.setSelectionPath(classPath); + mainPanel.setTagTreeSelectedNode(mainPanel.getCurrentTree(), (TreeItem) item); } } }