From 0fc21ee68937e488c4eddbb28daf67db1dea0cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sun, 20 Nov 2022 19:23:26 +0100 Subject: [PATCH] AS3 - Correct hilighting class after direct editation --- .../decompiler/flash/gui/abc/ABCPanel.java | 150 ++++++++++++------ .../decompiler/flash/gui/abc/UsageFrame.java | 2 +- 2 files changed, 106 insertions(+), 46 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index 41013651f..a0254aa96 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -71,6 +71,7 @@ import com.jpexs.decompiler.flash.gui.abc.tablemodels.StringTableModel; import com.jpexs.decompiler.flash.gui.abc.tablemodels.UIntTableModel; import com.jpexs.decompiler.flash.gui.controls.JPersistentSplitPane; import com.jpexs.decompiler.flash.gui.editor.LinkHandler; +import com.jpexs.decompiler.flash.gui.tagtree.AbstractTagTree; import com.jpexs.decompiler.flash.gui.tagtree.AbstractTagTreeModel; import com.jpexs.decompiler.flash.gui.tagtree.TagTreeModel; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; @@ -84,6 +85,8 @@ import com.jpexs.decompiler.flash.search.ScriptSearchListener; import com.jpexs.decompiler.flash.search.ScriptSearchResult; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.flash.tags.Tag; +import com.jpexs.decompiler.flash.timeline.AS3Package; +import com.jpexs.decompiler.flash.treeitems.AS3ClassTreeItem; import com.jpexs.decompiler.flash.treeitems.Openable; import com.jpexs.decompiler.flash.treeitems.TreeItem; import com.jpexs.helpers.CancellableWorker; @@ -139,6 +142,7 @@ import javax.swing.event.TreeModelEvent; import javax.swing.event.TreeModelListener; import javax.swing.table.DefaultTableModel; import javax.swing.text.Highlighter; +import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import jsyntaxpane.Token; import jsyntaxpane.TokenType; @@ -160,9 +164,9 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener libraryComboBox; - + public final DecompiledEditorPane decompiledTextArea; public final JScrollPane decompiledScrollPane; @@ -232,7 +236,7 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener(); libraryComboBox.addItem("AIR (airglobal.swc)"); libraryComboBox.addItem("Flash (playerglobal.swc)"); - libraryComboBox.setSelectedIndex(Main.LIBRARY_FLASH); + libraryComboBox.setSelectedIndex(Main.LIBRARY_FLASH); libraryComboBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { @@ -981,13 +984,13 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener allAbcs = new ArrayList<>(); + for (ABCContainerTag container : swf.getAbcList()) { + allAbcs.add(container.getABC()); } - - ClassPath classPath = item.getClassPath(); - - // first check the className to avoid calling unnecessary toString - if (name.endsWith(classPath.className + classPath.namespaceSuffix) && classPath.toRawString().equals(name)) { - pack = item; - break; + loopcontainer: for (ABCContainerTag container : swf.getAbcList()) { + List packs = container.getABC().getScriptPacks(null, allAbcs); + for (ScriptPack pack : packs) { + ClassPath classPath = pack.getClassPath(); + if (name.endsWith(classPath.className + classPath.namespaceSuffix) && classPath.toRawString().equals(name)) { + scriptNode = (Tag) container; + break loopcontainer; + } + } } } - - if (pack != null) { - if (mainPanel.getCurrentView() != MainPanel.VIEW_RESOURCES) { - mainPanel.showView(MainPanel.VIEW_RESOURCES); - } - hilightScript(pack); - } + } else if (openable instanceof ABC) { + scriptNode = (ABC) openable; } + + if (scriptNode != null) { + hilightScript(openable, name, scriptNode); + } + } + + public void hilightScript(Openable openable, String name, TreeItem scriptNode) { + View.checkAccess(); + + 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 = scriptNode; + } + + AbstractTagTree tree = mainPanel.getCurrentTree(); + + String pkg = name.contains(".") ? name.substring(0, name.lastIndexOf(".")) : ""; + String parts[] = name.split("\\."); + + 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())) { + item = ti; + break; + } + } + } + } + mainPanel.setTagTreeSelectedNode(mainPanel.getCurrentTree(), (TreeItem) item); } public void hilightScript(ScriptPack pack) { @@ -1483,11 +1530,11 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener