Tag list view - saving last selected items

Saving last selected view
This commit is contained in:
Jindra Petřík
2022-10-30 10:47:28 +01:00
parent 9e771ae9ed
commit 74ff118c22
16 changed files with 179 additions and 63 deletions

View File

@@ -279,7 +279,10 @@ public final class Configuration {
public static ConfigurationItem<HashMap<String, String>> fontPairingMap = null;
public static ConfigurationItem<HashMap<String, SwfSpecificConfiguration>> swfSpecificConfigs = null;
public static ConfigurationItem<HashMap<String, SwfSpecificCustomConfiguration>> swfSpecificCustomConfigs = null;
@ConfigurationDefaultCalendar(0)
public static ConfigurationItem<Calendar> lastUpdatesCheckDate = null;
@@ -525,6 +528,11 @@ public final class Configuration {
public static ConfigurationItem<String> lastSessionFileTitles = null;
public static ConfigurationItem<String> lastSessionSelection = null;
public static ConfigurationItem<String> lastSessionTagListSelection = null;
@ConfigurationDefaultInt(0)
public static ConfigurationItem<Integer> lastView = null;
@ConfigurationDefaultBoolean(true)
@ConfigurationCategory("ui")
@@ -897,6 +905,26 @@ public final class Configuration {
return swfConf;
}
public static SwfSpecificCustomConfiguration getSwfSpecificCustomConfiguration(String fileName) {
HashMap<String, SwfSpecificCustomConfiguration> map = swfSpecificCustomConfigs.get();
if (map == null) {
map = new HashMap<>();
swfSpecificCustomConfigs.set(map);
}
return map.get(fileName);
}
public static SwfSpecificCustomConfiguration getOrCreateSwfSpecificCustomConfiguration(String fileName) {
SwfSpecificCustomConfiguration swfConf = getSwfSpecificCustomConfiguration(fileName);
if (swfConf == null) {
swfConf = new SwfSpecificCustomConfiguration();
swfSpecificCustomConfigs.get().put(fileName, swfConf);
}
return swfConf;
}
private static String getConfigFile() throws IOException {
return getFFDecHome() + CONFIG_NAME;
@@ -933,6 +961,7 @@ public final class Configuration {
oos.writeObject(config);
} catch (IOException ex) {
//TODO: move this to GUI
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "Cannot save configuration.", "Error", JOptionPane.ERROR_MESSAGE);
Logger.getLogger(Configuration.class.getName()).severe("Configuration directory is read only.");
}

View File

@@ -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.configuration;
import java.io.Serializable;
@@ -27,5 +28,5 @@ public class SwfSpecificConfiguration implements Serializable {
public Map<String, String> fontPairingMap = new HashMap<>();
public String lastSelectedPath = null;
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright (C) 2010-2022 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.configuration;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author JPEXS
*/
public class SwfSpecificCustomConfiguration implements Serializable {
private Map<String, String> customData = new HashMap<>();
public static final String KEY_LAST_SELECTED_PATH_RESOURCES = "lastSelectedPath.resources";
public static final String KEY_LAST_SELECTED_PATH_TAGLIST = "lastSelectedPath.taglist";
public String getCustomData(String key, String defaultValue) {
if (customData.containsKey(key)) {
return customData.get(key);
}
return defaultValue;
}
public void setCustomData(String key, String value) {
customData.put(key, value);
}
}

View File

@@ -105,7 +105,7 @@ public class FolderPreviewPanel extends JPanel {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1) {
if (selectedIndex > -1) {
mainPanel.setTagTreeSelectedNode(FolderPreviewPanel.this.items.get(selectedIndex));
mainPanel.setTagTreeSelectedNode(mainPanel.getCurrentTree(), FolderPreviewPanel.this.items.get(selectedIndex));
}
}
}

View File

@@ -37,6 +37,7 @@ 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.configuration.SwfSpecificCustomConfiguration;
import com.jpexs.decompiler.flash.console.CommandLineArgumentParser;
import com.jpexs.decompiler.flash.console.ContextMenuTools;
import com.jpexs.decompiler.flash.exporters.modes.ExeExportMode;
@@ -1310,13 +1311,23 @@ public class Main {
if (mainFrame != null && fswf != null) {
SwfSpecificConfiguration swfConf = Configuration.getSwfSpecificConfiguration(fswf.getShortFileName());
String resourcesPathStr = null;
String tagListPathStr = null;
if (swfConf != null) {
String pathStr = swfConf.lastSelectedPath;
if (isInited()) {
mainFrame.getPanel().tagTree.setSelectionPathString(pathStr);
} else {
mainFrame.getPanel().tagTree.setExpandPathString(pathStr);
}
resourcesPathStr = swfConf.lastSelectedPath;
}
SwfSpecificCustomConfiguration swfCustomConf = Configuration.getSwfSpecificCustomConfiguration(fswf.getShortFileName());
if (swfCustomConf != null) {
resourcesPathStr = swfCustomConf.getCustomData(SwfSpecificCustomConfiguration.KEY_LAST_SELECTED_PATH_RESOURCES, resourcesPathStr);
tagListPathStr = swfCustomConf.getCustomData(SwfSpecificCustomConfiguration.KEY_LAST_SELECTED_PATH_TAGLIST, null);
}
if (isInited()) {
mainFrame.getPanel().tagTree.setSelectionPathString(resourcesPathStr);
mainFrame.getPanel().tagListTree.setSelectionPathString(tagListPathStr);
} else {
mainFrame.getPanel().tagTree.setExpandPathString(resourcesPathStr);
mainFrame.getPanel().tagListTree.setExpandPathString(tagListPathStr);
}
}
@@ -2327,6 +2338,7 @@ public class Main {
openingFiles = true;
openFile(sourceInfos, () -> {
mainFrame.getPanel().tagTree.setSelectionPathString(Configuration.lastSessionSelection.get());
mainFrame.getPanel().tagListTree.setSelectionPathString(Configuration.lastSessionTagListSelection.get());
setSessionLoaded(true);
});
}

View File

@@ -878,10 +878,16 @@ public abstract class MainFrameMenu implements MenuBuilder {
finishMenu("/file");
if (Configuration.dumpView.get()) {
setGroupSelection("view", "/file/view/viewHex");
} else {
setGroupSelection("view", "/file/view/viewResources");
switch(Configuration.lastView.get()){
case MainPanel.VIEW_RESOURCES:
setGroupSelection("view", "/file/view/viewResources");
break;
case MainPanel.VIEW_TAGLIST:
setGroupSelection("view", "/file/view/viewTagList");
break;
case MainPanel.VIEW_DUMP:
setGroupSelection("view", "/file/view/viewHex");
break;
}
/*

View File

@@ -146,9 +146,13 @@ public final class MainFrameRibbon extends AppRibbonFrame {
Configuration.lastSessionFiles.set(sb.toString());
Configuration.lastSessionFileTitles.set(sbt.toString());
String path = panel.tagTree.getSelectionPathString();
if (path != null) {
Configuration.lastSessionSelection.set(path);
String pathResources = panel.tagTree.getSelectionPathString();
if (pathResources != null) {
Configuration.lastSessionSelection.set(pathResources);
}
String pathTagList = panel.tagListTree.getSelectionPathString();
if (pathTagList != null) {
Configuration.lastSessionTagListSelection.set(pathTagList);
}
}

View File

@@ -34,6 +34,7 @@ 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.configuration.SwfSpecificCustomConfiguration;
import com.jpexs.decompiler.flash.dumpview.DumpInfo;
import com.jpexs.decompiler.flash.dumpview.DumpInfoSwfNode;
import com.jpexs.decompiler.flash.exporters.BinaryDataExporter;
@@ -704,11 +705,9 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
dumpTree = new DumpTree(null, this);
dumpTree.addTreeSelectionListener(this);
dumpTree.createContextMenu();
if (Configuration.dumpView.get()) {
currentView = VIEW_DUMP;
}
currentView = Configuration.lastView.get();
statusPanel = new MainFrameStatusPanel(this);
add(statusPanel, BorderLayout.SOUTH);
@@ -1800,7 +1799,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
Timelined t = (Timelined) treeItem;
Frame f = tagTree.getModel().getFrame(treeItem.getSwf(), t, frame);
if (f != null) {
setTagTreeSelectedNode(f);
setTagTreeSelectedNode(getCurrentTree(), f);
}
}
}
@@ -2265,7 +2264,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
public void updateSearchPos(String searchedText, boolean ignoreCase, boolean regExp, TextTag item) {
View.checkAccess();
setTagTreeSelectedNode(item);
setTagTreeSelectedNode(getCurrentTree(), item);
previewPanel.getTextPanel().updateSearchPos();
}
@@ -2280,11 +2279,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
}
}
public void setTagTreeSelectedNode(TreeItem treeItem) {
if (currentView != VIEW_RESOURCES && currentView != VIEW_TAGLIST) {
return;
}
AbstractTagTree tree = getCurrentTree();
public void setTagTreeSelectedNode(AbstractTagTree tree, TreeItem treeItem) {
AbstractTagTreeModel ttm = tree.getModel();
TreePath tp = ttm.getTreePath(treeItem);
if (tp != null) {
@@ -3018,7 +3013,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
if (swf != null) {
SWF treeItemSwf = swf.getRootSwf();
if (this.swfs.contains(treeItemSwf.swfList)) {
setTagTreeSelectedNode(treeItem);
setTagTreeSelectedNode(getCurrentTree(), treeItem);
}
}
}
@@ -3046,7 +3041,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
if (swf != null) {
SWF treeItemSwf = swf.getRootSwf();
if (this.swfs.contains(treeItemSwf.swfList)) {
setTagTreeSelectedNode(treeItem);
setTagTreeSelectedNode(getCurrentTree(), treeItem);
}
}
}
@@ -3233,7 +3228,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
SWF swf = it.getSwf();
if (newTag != null) {
refreshTree(swf);
setTagTreeSelectedNode(newTag);
setTagTreeSelectedNode(getCurrentTree(), newTag);
}
swf.clearImageCache();
} catch (IOException ex) {
@@ -3260,7 +3255,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
SWF swf = st.getSwf();
if (newTag != null) {
refreshTree(swf);
setTagTreeSelectedNode(newTag);
setTagTreeSelectedNode(getCurrentTree(), newTag);
}
swf.clearImageCache();
@@ -3315,7 +3310,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
SWF swf = st.getSwf();
if (newTag != null) {
refreshTree(swf);
setTagTreeSelectedNode(newTag);
setTagTreeSelectedNode(getCurrentTree(), newTag);
}
swf.clearImageCache();
@@ -3622,14 +3617,14 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
dumpTree.expandFirstLevelNodes();
}
break;
case VIEW_RESOURCES:
case VIEW_RESOURCES:
case VIEW_TAGLIST:
if (tagTree.getModel() == null) {
TagTreeModel ttm = new TagTreeModel(swfs, Configuration.tagTreeShowEmptyFolders.get());
tagTree.setModel(ttm);
tagTree.expandFirstLevelNodes();
}
break;
case VIEW_TAGLIST:
}
if (tagListTree.getModel() == null) {
TagListTreeModel ttm = new TagListTreeModel(swfs);
tagListTree.setModel(ttm);
@@ -3675,6 +3670,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
switch (view) {
case VIEW_DUMP:
currentView = view;
Configuration.lastView.set(currentView);
if (!isWelcomeScreen) {
showContentPanelCard(SPLIT_PANE1);
}
@@ -3685,6 +3681,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
return true;
case VIEW_RESOURCES:
currentView = view;
Configuration.lastView.set(currentView);
if (!isWelcomeScreen) {
showContentPanelCard(SPLIT_PANE1);
}
@@ -3703,6 +3700,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
return true;
case VIEW_TIMELINE:
currentView = view;
Configuration.lastView.set(currentView);
final SWF swf = getCurrentSwf();
if (swf != null) {
TreeItem item = getCurrentTree().getCurrentTreeItem();
@@ -3722,6 +3720,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
return false;
case VIEW_TAGLIST:
currentView = view;
Configuration.lastView.set(currentView);
if (!isWelcomeScreen) {
showContentPanelCard(SPLIT_PANE1);
}
@@ -3924,8 +3923,11 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
}
if (swf != null) {
SwfSpecificConfiguration swfConf = Configuration.getOrCreateSwfSpecificConfiguration(swf.getShortFileName());
swfConf.lastSelectedPath = tagTree.getSelectionPathString();
SwfSpecificCustomConfiguration swfCustomConf = Configuration.getOrCreateSwfSpecificCustomConfiguration(swf.getShortFileName());
//swfConf.lastSelectedPath = tagTree.getSelectionPathString();
swfCustomConf.setCustomData(SwfSpecificCustomConfiguration.KEY_LAST_SELECTED_PATH_RESOURCES, tagTree.getSelectionPathString());
swfCustomConf.setCustomData(SwfSpecificCustomConfiguration.KEY_LAST_SELECTED_PATH_TAGLIST, tagListTree.getSelectionPathString());
}
}

View File

@@ -918,7 +918,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
swf.assignClassesToSymbols();
swf.assignExportNamesToSymbols();
mainPanel.refreshTree(swf);
mainPanel.setTagTreeSelectedNode(tag);
mainPanel.setTagTreeSelectedNode(mainPanel.getCurrentTree(), tag);
genericEditButton.setVisible(true);
genericSaveButton.setVisible(false);
genericCancelButton.setVisible(false);
@@ -949,7 +949,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
SWF swf = tag.getSwf();
tag.getTimelined().resetTimeline();
mainPanel.refreshTree(swf);
mainPanel.setTagTreeSelectedNode(tag);
mainPanel.setTagTreeSelectedNode(mainPanel.getCurrentTree(), tag);
}
placeGenericPanel.setEditMode(false, null);
}

View File

@@ -83,7 +83,7 @@ public class TagInfoPanel extends JPanel {
} else if ("frame".equals(scheme)) {
item = swf.getTimeline().getFrame(id);
}
mainPanel.setTagTreeSelectedNode(item);
mainPanel.setTagTreeSelectedNode(mainPanel.getCurrentTree(), item);
}
}

View File

@@ -491,7 +491,7 @@ public class DumpTree extends JTree {
if (foundTag != null) {
mainPanel.getMainFrame().getMenu().showResourcesView();
mainPanel.setTagTreeSelectedNode(foundTag);
mainPanel.setTagTreeSelectedNode(mainPanel.getCurrentTree(), foundTag);
}
}

View File

@@ -555,3 +555,12 @@ config.description.showImportSymbolClassInfo = Displays some info about how Symb
config.name.showImportXmlInfo = Show information before importing XML
config.description.showImportXmlInfo = Displays some info about how XML importing works after clicking Import XML in the menu.
config.name.lastSessionTagListSelection = Last session tag list selection
config.description.lastSessionTagListSelection = Contains the selection from the last session on the list selection view
config.name.lastView = Last view
config.description.lastView = Last displayed view mode
config.name.swfSpecificCustomConfigs = SWF specific custom configurations
config.description.swfSpecificCustomConfigs = Contains the SWF specific configurations in custom format

View File

@@ -35,4 +35,9 @@ public class TagListTreeRoot implements TreeItem {
public boolean isModified() {
return false;
}
@Override
public String toString() {
return "root";
}
}

View File

@@ -354,7 +354,7 @@ public abstract class AbstractTagTree extends JTree {
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());
mainPanel.setTagTreeSelectedNode(this, (TreeItem) tp.getLastPathComponent());
}
}
}
@@ -502,4 +502,22 @@ public abstract class AbstractTagTree extends JTree {
TreeItem item = (TreeItem) getLastSelectedPathComponent();
return item;
}
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();
}
}

View File

@@ -555,23 +555,7 @@ public class TagTree extends AbstractTagTree {
return (TagTreeModel) super.getModel();
}
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();
}
}

View File

@@ -947,7 +947,7 @@ public class TagTreeContextMenu extends JPopupMenu {
}
CharacterIdTag characterIdTag = (CharacterIdTag) itemj;
mainPanel.setTagTreeSelectedNode(itemj.getSwf().getCharacter(characterIdTag.getCharacterId()));
mainPanel.setTagTreeSelectedNode(mainPanel.getCurrentTree(), itemj.getSwf().getCharacter(characterIdTag.getCharacterId()));
}
private void expandRecursiveActionPerformed(ActionEvent evt) {