From cd91e3c3d2191c87818f728745238db085aaa801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Thu, 15 May 2025 22:50:13 +0200 Subject: [PATCH] Fixed: [#1962] Close button could close more than one file at once Fixed: Simple editor - Selecting previous SWF when swf close Changed: An item selected in the tag tree is needed for actions to be available. Also SWF node is selected by default on first SWF opening. --- CHANGELOG.md | 7 ++ .../decompiler/flash/easygui/EasyPanel.java | 22 +++++ .../decompiler/flash/easygui/TabSwitcher.java | 13 +++ src/com/jpexs/decompiler/flash/gui/Main.java | 20 ++++- .../decompiler/flash/gui/MainFrameMenu.java | 23 +++-- .../jpexs/decompiler/flash/gui/MainPanel.java | 85 ++++++++++++++----- 6 files changed, 139 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a17d81ab..6eda536a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,12 @@ All notable changes to this project will be documented in this file. - Filters - image bounds - Simple editor - Exceptions caused by not setting timelined when modifying PlaceObject - [#2455] Commandline export ConcurrentModificationException +- [#1962] Close button could close more than one file at once +- Simple editor - Selecting previous SWF when swf close + +### Changed +- An item selected in the tag tree is needed for actions to be available. + Also SWF node is selected by default on first SWF opening. ### Removed - Option to preview flash items via ActiveX component is no longer available. @@ -3799,6 +3805,7 @@ Major version of SWF to XML export changed to 2. [#2419]: https://www.free-decompiler.com/flash/issues/2419 [#2454]: https://www.free-decompiler.com/flash/issues/2454 [#2455]: https://www.free-decompiler.com/flash/issues/2455 +[#1962]: https://www.free-decompiler.com/flash/issues/1962 [#2375]: https://www.free-decompiler.com/flash/issues/2375 [#2374]: https://www.free-decompiler.com/flash/issues/2374 [#2389]: https://www.free-decompiler.com/flash/issues/2389 diff --git a/src/com/jpexs/decompiler/flash/easygui/EasyPanel.java b/src/com/jpexs/decompiler/flash/easygui/EasyPanel.java index 68922bb1c..32c78f86e 100644 --- a/src/com/jpexs/decompiler/flash/easygui/EasyPanel.java +++ b/src/com/jpexs/decompiler/flash/easygui/EasyPanel.java @@ -59,8 +59,30 @@ public class EasyPanel extends JPanel { tabSwitcher.setValue(swf); } + public int indexOf(SWF swf) { + return tabSwitcher.indexOf(swf); + } + + public void setSwfIndex(int index) { + if (index < 0) { + return; + } + if (index >= tabSwitcher.getValueCount()) { + return; + } + tabSwitcher.setSelectedIndex(index); + } + + public SWF getSwfAtIndex(int index) { + if (index < 0 || index >= tabSwitcher.getValueCount()) { + return null; + } + return tabSwitcher.getValueAtIndex(index); + } + public void setNoSwf() { easySwfPanel.setTimelined(null); + tabSwitcher.setValue(null); } public SWF getSwf() { diff --git a/src/com/jpexs/decompiler/flash/easygui/TabSwitcher.java b/src/com/jpexs/decompiler/flash/easygui/TabSwitcher.java index 4aeb92042..412d33d6b 100644 --- a/src/com/jpexs/decompiler/flash/easygui/TabSwitcher.java +++ b/src/com/jpexs/decompiler/flash/easygui/TabSwitcher.java @@ -146,11 +146,24 @@ public class TabSwitcher extends JPanel { tabbedPane.setSelectedIndex(index); } + public int getSelectedIndex() { + return tabbedPane.getSelectedIndex(); + } + public void setValue(E value) { + if (value == null) { + setSelectedIndex(-1); + return; + } int index = values.indexOf(value); setSelectedIndex(index); } + + public int indexOf(E value) { + return values.indexOf(value); + } + public E getSelectedValue() { int index = tabbedPane.getSelectedIndex(); if (index == -1) { diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index df8fe8ae9..df53114f9 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -53,6 +53,7 @@ import com.jpexs.decompiler.flash.gui.pipes.FirstInstance; import com.jpexs.decompiler.flash.gui.soleditor.CookiesChangedListener; import com.jpexs.decompiler.flash.gui.soleditor.SharedObjectsStorage; import com.jpexs.decompiler.flash.gui.soleditor.SolEditorFrame; +import com.jpexs.decompiler.flash.gui.tagtree.AbstractTagTreeModel; import com.jpexs.decompiler.flash.helpers.SWFDecompilerPlugin; import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag; import com.jpexs.decompiler.flash.tags.DefineVideoStreamTag; @@ -150,6 +151,7 @@ import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.WindowConstants; import javax.swing.filechooser.FileFilter; +import javax.swing.tree.TreePath; import jsyntaxpane.DefaultSyntaxKit; import org.pushingpixels.substance.api.SubstanceLookAndFeel; @@ -1817,8 +1819,22 @@ public class Main { } if (isInited()) { - mainFrame.getPanel().tagTree.setSelectionPathString(resourcesPathStr); - mainFrame.getPanel().tagListTree.setSelectionPathString(tagListPathStr); + if (resourcesPathStr == null) { + TreePath tp = mainFrame.getPanel().tagTree.getFullModel().getTreePath(fopenable); + if (tp != null) { + mainFrame.getPanel().tagTree.setSelectionPath(tp); + } + } else { + mainFrame.getPanel().tagTree.setSelectionPathString(resourcesPathStr); + } + if (tagListPathStr == null) { + TreePath tp = mainFrame.getPanel().tagListTree.getFullModel().getTreePath(fopenable); + if (tp != null) { + mainFrame.getPanel().tagListTree.setSelectionPath(tp); + } + } else { + mainFrame.getPanel().tagListTree.setSelectionPathString(tagListPathStr); + } } else { mainFrame.getPanel().tagTree.setExpandPathString(resourcesPathStr); mainFrame.getPanel().tagListTree.setExpandPathString(tagListPathStr); diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java index d60ba9042..8cd016043 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java @@ -307,23 +307,30 @@ public abstract class MainFrameMenu implements MenuBuilder { } Set listsToClose = new LinkedHashSet<>(); List binaryDataClosedSwfs = new ArrayList<>(); - - for (TreeItem item : mainFrame.getPanel().getCurrentTree().getSelected()) { - if (item instanceof OpenableList) { - listsToClose.add((OpenableList) item); - } else { - Openable itemOpenable = item.getOpenable(); - enumerateListsToClose(listsToClose, itemOpenable, binaryDataClosedSwfs); + + if (mainFrame.getPanel().getCurrentView() == MainPanel.VIEW_EASY) { + Openable itemOpenable = mainFrame.getPanel().easyPanel.getSwf(); + enumerateListsToClose(listsToClose, itemOpenable, binaryDataClosedSwfs); + } else { + for (TreeItem item : mainFrame.getPanel().getCurrentTree().getSelected()) { + if (item instanceof OpenableList) { + listsToClose.add((OpenableList) item); + } else { + Openable itemOpenable = item.getOpenable(); + enumerateListsToClose(listsToClose, itemOpenable, binaryDataClosedSwfs); + } } } if (openable != null && !binaryDataClosedSwfs.contains(openable)) { enumerateListsToClose(listsToClose, openable, binaryDataClosedSwfs); } + openable = null; + for (OpenableList list : listsToClose) { Main.closeFile(list); } mainFrame.getPanel().refreshTree(); - openable = null; + Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 8c439909d..9740f449a 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -1461,7 +1461,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se easyPanel.setSwf((SWF) openable); } if (openable != null) { - updateUi(openable); + //updateUi(openable); } gcClipboard(); @@ -1481,11 +1481,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se easyPanel.setSwfs(new ArrayList<>(getAllSwfs())); - Openable openable = newOpenables.size() > 0 ? newOpenables.get(0) : null; - if (openable != null) { - updateUi(openable); - } - + hideWelcomeScreen(); + gcClipboard(); reload(false); @@ -1521,6 +1518,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se if (resourcesOpenable != null) { updateUi(resourcesOpenable); } + } else { + updateUi(null); } break; case VIEW_TAGLIST: @@ -1530,6 +1529,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se if (tagListOpenable != null) { updateUi(tagListOpenable); } + } else { + updateUi(null); } break; case VIEW_DUMP: @@ -1539,6 +1540,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se if (dumpOpenable != null) { updateUi(dumpOpenable); } + } else { + updateUi(null); } break; case VIEW_EASY: @@ -1546,10 +1549,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se break; } } - - private void updateUi(final Openable openable) { - View.checkAccess(); - + + private void hideWelcomeScreen() { if (isWelcomeScreen) { if (currentView == VIEW_EASY) { showContentPanelCard(EASY_PANEL); @@ -1558,6 +1559,10 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se } isWelcomeScreen = false; } + } + + private void updateUi(final Openable openable) { + View.checkAccess(); SWF swf = null; if (openable instanceof SWF) { swf = (SWF) openable; @@ -1767,6 +1772,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se i--; } } + int minEasyIndex = Integer.MAX_VALUE; for (SWF swf : swfsToClose) { Main.searchResultsStorage.destroySwf(swf); pinsPanel.removeOpenable(swf); @@ -1786,14 +1792,41 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se if (breakpointsListDialog != null) { breakpointsListDialog.setVisible(false); breakpointsListDialogs.remove(swf); + } + int index = easyPanel.indexOf(swf); + if (index < minEasyIndex) { + minEasyIndex = index; + } + } + + minEasyIndex--; + if (minEasyIndex < 0) { + minEasyIndex = 0; + SWF s = easyPanel.getSwfAtIndex(minEasyIndex); + while (s != null && swfsToClose.contains(s)) { + minEasyIndex++; + s = easyPanel.getSwfAtIndex(minEasyIndex); } } - + openables.remove(openableList); oldItem = null; clear(); - updateUi(); - + + easyPanel.setSwfIndex(minEasyIndex); + + SWF newEasySwf = easyPanel.getSwf(); + + if (currentView == VIEW_EASY) { + Set swfs = getAllSwfs(); + easyPanel.setSwfs(new ArrayList<>(swfs)); + easyPanel.setSwf(newEasySwf); + updateUi(newEasySwf); + } else { + updateUi(); + } + + for (SWF swf : swfsToClose) { swf.clearTagSwfs(); } @@ -1802,7 +1835,11 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se gcClipboard(); - mainMenu.updateComponents(null); + if (currentView == VIEW_EASY) { + mainMenu.updateComponents(easyPanel.getSwf()); + } else { + mainMenu.updateComponents(); + } previewPanel.clear(); dumpPreviewPanel.clear(); doFilter(); @@ -5414,9 +5451,11 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se } private void valueChanged(Object source, TreePath selectedPath) { - TreeItem treeItem = (TreeItem) selectedPath.getLastPathComponent(); + TreeItem treeItem = selectedPath == null ? null : (TreeItem) selectedPath.getLastPathComponent(); if (treeItem == null) { + updateUi(null); + reload(false); return; } @@ -5426,13 +5465,14 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se // show welcome panel after closing swfs updateUi(); } else { - if (openable == null && openables.get(0) != null) { + /*if (openable == null && openables.get(0) != null) { openable = openables.get(0).get(0); - } + }*/ - if (openable != null) { + /*if (openable != null) { updateUi(openable); - } + }*/ + updateUi(openable); } } else { updateUi(); @@ -5464,8 +5504,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se @Override public void valueChanged(TreeSelectionEvent e) { - Object source = e.getSource(); - valueChanged(source, e.getPath()); + JTree source = (JTree) e.getSource(); + valueChanged(source, source.getSelectionPath()); } private int getFrameForTreeItem(TreeItem treeItem) { @@ -5672,6 +5712,9 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se Configuration.lastView.set(currentView); Set swfs = getAllSwfs(); easyPanel.setSwfs(new ArrayList<>(swfs)); + if (swf == null && !swfs.isEmpty()) { + swf = swfs.iterator().next(); + } easyPanel.setSwf(swf); if (!isWelcomeScreen) { showContentPanelCard(EASY_PANEL);