diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java index 67546dc1a..78a09459e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.action; import com.jpexs.decompiler.flash.DisassemblyListener; @@ -342,7 +343,7 @@ public class ActionListReader { return next ? (min < actions.size() ? actions.get(min).getAddress() : -1) - : (max > 0 ? actions.get(max).getAddress() : -1); + : (max >= 0 ? actions.get(max).getAddress() : -1); } private static Map actionListToMap(List actions) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/treeitems/FolderItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/treeitems/FolderItem.java index a90390248..cd1d8e1fb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/treeitems/FolderItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/treeitems/FolderItem.java @@ -56,6 +56,10 @@ public class FolderItem implements TreeItem { @Override public boolean isModified() { + if (subItems == null) { + return false; + } + for (TreeItem ti : subItems) { if (ti.isModified()) { return true; diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 9c878f3af..e22e72aa8 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -617,6 +617,9 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec this.swfs.addCollectionChangedListener((e) -> { TagTreeModel ttm = tagTree.getModel(); if (ttm != null) { + if (getCurrentSwf() == null) { + tagTree.setSelectionPath(ttm.getTreePath(ttm.getRoot())); + } ttm.updateSwfs(e); TreeItem root = ttm.getRoot(); int childCount = ttm.getChildCount(root); diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java index ebbdab26d..5b70bca3a 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java @@ -181,6 +181,7 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi } textWithHex = null; textNoHex = null; + textHexOnly = null; setHex(exportMode, true); } @@ -236,6 +237,9 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi } ((Tag) abc.parentTag).setModified(true); abc.script_info.get(scriptIndex).setModified(true); + textWithHex = null; + textNoHex = null; + textHexOnly = null; } catch (IOException ex) { } catch (InterruptedException ex) { } catch (AVM2ParseException ex) { diff --git a/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java b/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java index 1f04eae60..8ab8ddea3 100644 --- a/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java @@ -681,9 +681,9 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene if (val) { if (rawEdit) { - setText(srcHexOnly, "text/plain"); + setHex(ScriptExportMode.HEX); } else { - setText(srcNoHex, "text/flasm"); + setHex(ScriptExportMode.PCODE); } editor.setEditable(true); saveButton.setVisible(true); diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java index 5a02f6822..a4a1185a7 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java @@ -172,11 +172,16 @@ public class TagTree extends JTree { int row, boolean hasFocus) { + TreeItem val = (TreeItem) value; + if (val.getSwf() == null) { + // SWF was closed + value = null; + } + super.getTreeCellRendererComponent( tree, value, sel, expanded, leaf, row, hasFocus); - TreeItem val = (TreeItem) value; TreeNodeType type = getTreeNodeType(val); if (type == TreeNodeType.FOLDER && expanded) { @@ -560,6 +565,7 @@ public class TagTree extends JTree { if (!mainPanel.folderPreviewPanel.selectedItems.isEmpty()) { return mainPanel.folderPreviewPanel.selectedItems.entrySet().iterator().next().getValue(); } + TreeItem item = (TreeItem) getLastSelectedPathComponent(); return item; } diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java index f636724c5..9ade6a7cf 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java @@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.gui.AppStrings; import com.jpexs.decompiler.flash.gui.TreeNodeType; import com.jpexs.decompiler.flash.gui.abc.ClassesListTreeModel; +import com.jpexs.decompiler.flash.gui.helpers.CollectionChangedAction; import com.jpexs.decompiler.flash.gui.helpers.CollectionChangedEvent; import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag; import com.jpexs.decompiler.flash.tags.DefineSpriteTag; @@ -102,25 +103,7 @@ public class TagTreeModel implements TreeModel { } public void updateSwfs(CollectionChangedEvent e) { - boolean cleanMap = false; - switch (e.getAction()) { - case ADD: { - TreePath rootPath = new TreePath(new Object[]{root}); - fireTreeNodesInserted(new TreeModelEvent(this, rootPath, new int[]{e.getNewIndex()}, new Object[]{e.getNewItem()})); - break; - } - case REMOVE: { - TreePath rootPath = new TreePath(new Object[]{root}); - fireTreeNodesRemoved(new TreeModelEvent(this, rootPath, new int[]{e.getOldIndex()}, new Object[]{e.getOldItem()})); - cleanMap = true; - break; - } - default: - cleanMap = true; - fireTreeStructureChanged(new TreeModelEvent(this, new TreePath(root))); - } - - if (cleanMap) { + if (e.getAction() != CollectionChangedAction.ADD) { List toRemove = new ArrayList<>(); for (SWF swf : swfInfos.keySet()) { SWF swf2 = swf.getRootSwf(); @@ -133,6 +116,21 @@ public class TagTreeModel implements TreeModel { swfInfos.remove(swf); } } + + switch (e.getAction()) { + case ADD: { + TreePath rootPath = new TreePath(new Object[]{root}); + fireTreeNodesInserted(new TreeModelEvent(this, rootPath, new int[]{e.getNewIndex()}, new Object[]{e.getNewItem()})); + break; + } + case REMOVE: { + TreePath rootPath = new TreePath(new Object[]{root}); + fireTreeNodesRemoved(new TreeModelEvent(this, rootPath, new int[]{e.getOldIndex()}, new Object[]{e.getOldItem()})); + break; + } + default: + fireTreeStructureChanged(new TreeModelEvent(this, new TreePath(root))); + } } public void updateSwf(SWF swf) { @@ -602,15 +600,8 @@ public class TagTreeModel implements TreeModel { } if (result instanceof Tag) { Tag resultTag = (Tag) result; - TagScript tagScript = null; - Map currentTagScriptCache = null; - if (swfInfos != null && result.getSwf() != null) { - TagTreeSwfInfo ttsi = swfInfos.get(result.getSwf()); - if (ttsi != null) { - currentTagScriptCache = ttsi.tagScriptCache; - tagScript = currentTagScriptCache.get(resultTag); - } - } + Map currentTagScriptCache = swfInfos.get(result.getSwf()).tagScriptCache; + TagScript tagScript = currentTagScriptCache.get(resultTag); if (tagScript == null) { List subNodes = new ArrayList<>(); if (result instanceof ASMSourceContainer) { @@ -619,9 +610,7 @@ public class TagTreeModel implements TreeModel { } } tagScript = new TagScript(result.getSwf(), resultTag, subNodes); - if (currentTagScriptCache != null) { - currentTagScriptCache.put(resultTag, tagScript); - } + currentTagScriptCache.put(resultTag, tagScript); } result = tagScript; }