From 93b2ceca26c86e35ca2b66502833378e980b4060 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Thu, 21 May 2015 20:35:19 +0200 Subject: [PATCH] save last selected path for each swf --- .../SwfSpecificConfiguration.java | 4 +-- src/com/jpexs/decompiler/flash/gui/Main.java | 22 +++++++------- .../decompiler/flash/gui/MainFrameRibbon.java | 13 ++------ .../jpexs/decompiler/flash/gui/MainPanel.java | 14 +++++++++ .../decompiler/flash/gui/tagtree/TagTree.java | 30 +++++++++++++++++++ 5 files changed, 58 insertions(+), 25 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/SwfSpecificConfiguration.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/SwfSpecificConfiguration.java index ae77d7dfc..37303d0a2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/SwfSpecificConfiguration.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/SwfSpecificConfiguration.java @@ -26,7 +26,7 @@ import java.util.Map; */ public class SwfSpecificConfiguration implements Serializable { - public final Map fontPairingMap = new HashMap<>(); + public Map fontPairingMap = new HashMap<>(); - public final ConfigurationItem lastSessionData = null; + public String lastSelectedPath = null; } diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index 02a83ff03..cea68a5bc 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.SwfOpenException; import com.jpexs.decompiler.flash.Version; import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.configuration.SwfSpecificConfiguration; import com.jpexs.decompiler.flash.console.CommandLineArgumentParser; import com.jpexs.decompiler.flash.console.ContextMenuTools; import com.jpexs.decompiler.flash.gui.pipes.FirstInstance; @@ -33,7 +34,6 @@ import com.jpexs.decompiler.flash.gui.proxy.ProxyFrame; import com.jpexs.decompiler.flash.helpers.SWFDecompilerPlugin; import com.jpexs.decompiler.flash.tags.base.FontTag; import com.jpexs.decompiler.flash.treeitems.SWFList; -import com.jpexs.decompiler.flash.treeitems.TreeItem; import com.jpexs.helpers.Cache; import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; @@ -98,7 +98,6 @@ import javax.swing.SwingWorker; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.filechooser.FileFilter; -import javax.swing.tree.TreePath; /** * Main executable class @@ -515,6 +514,14 @@ public class Main { mainFrame.getPanel().gotoDocumentClass(fswf); } + if (mainFrame != null && fswf != null) { + SwfSpecificConfiguration swfConf = Configuration.getSwfSpecificConfiguration(fswf.getShortFileName()); + if (swfConf != null) { + String pathStr = swfConf.lastSelectedPath; + mainFrame.getPanel().tagTree.setSelectionPathString(pathStr); + } + } + if (executeAfterOpen != null) { executeAfterOpen.run(); } @@ -1126,16 +1133,7 @@ public class Main { openFile(sourceInfos, () -> { // last part contains the selected node in the tagtree String pathStr = filesToOpen[filesToOpen.length - 1]; - if (pathStr.length() > 0) { - String[] path = pathStr.split("\\|"); - - MainPanel mainPanel = mainFrame.getPanel(); - TreePath tp = View.getTreePathByPathStrings(mainPanel.tagTree, Arrays.asList(path)); - if (tp != null) { - // the current view is the Resources view, otherwise tp is null - mainPanel.setTagTreeSelectedNode((TreeItem) tp.getLastPathComponent()); - } - } + mainFrame.getPanel().tagTree.setSelectionPathString(pathStr); }); } } diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java index 0534ba5db..fc6665539 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java @@ -33,7 +33,6 @@ import java.awt.event.WindowStateListener; import java.io.File; import java.util.List; import javax.swing.JFrame; -import javax.swing.tree.TreePath; import org.pushingpixels.flamingo.api.ribbon.JRibbon; import org.pushingpixels.flamingo.internal.ui.ribbon.appmenu.JRibbonApplicationMenuButton; @@ -127,17 +126,9 @@ public final class MainFrameRibbon extends AppRibbonFrame { } } - TreePath path = panel.tagTree.getLeadSelectionPath(); + String path = panel.tagTree.getSelectionPathString(); if (path != null) { - boolean first = true; - for (Object p : path.getPath()) { - if (!first) { - sb.append("|"); - } - - first = false; - sb.append(p.toString()); - } + sb.append(path); } Configuration.lastSessionData.set(sb.toString()); diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index b873c218f..0a1acd402 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -28,6 +28,7 @@ import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.configuration.ConfigurationItem; +import com.jpexs.decompiler.flash.configuration.SwfSpecificConfiguration; import com.jpexs.decompiler.flash.dumpview.DumpInfo; import com.jpexs.decompiler.flash.dumpview.DumpInfoSwfNode; import com.jpexs.decompiler.flash.exporters.BinaryDataExporter; @@ -2808,6 +2809,19 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se treeItem = (TreeItem) treePath.getLastPathComponent(); } + // save last selected node to config + if (treeItem != null) { + SWF swf = treeItem.getSwf(); + if (swf != null) { + swf = swf.getRootSwf(); + } + + if (swf != null) { + SwfSpecificConfiguration swfConf = Configuration.getOrCreateSwfSpecificConfiguration(swf.getShortFileName()); + swfConf.lastSelectedPath = tagTree.getSelectionPathString(); + } + } + if (!forceReload && (treeItem == oldItem)) { return; } diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java index 9d70646fd..b49aeccad 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java @@ -621,4 +621,34 @@ public class TagTree extends JTree { expandPath(new TreePath(new Object[]{root, ttm.getChild(root, i)})); } } + + public String getSelectionPathString() { + StringBuilder sb = new StringBuilder(); + TreePath path = getSelectionPath(); + if (path != null) { + boolean first = true; + for (Object p : path.getPath()) { + if (!first) { + sb.append("|"); + } + + first = false; + sb.append(p.toString()); + } + } + + return sb.toString(); + } + + public void setSelectionPathString(String pathStr) { + if (pathStr != null && pathStr.length() > 0) { + String[] path = pathStr.split("\\|"); + + TreePath tp = View.getTreePathByPathStrings(this, Arrays.asList(path)); + if (tp != null) { + // the current view is the Resources view, otherwise tp is null + mainPanel.setTagTreeSelectedNode((TreeItem) tp.getLastPathComponent()); + } + } + } }