From 7e1981614974c9c5d3b8cc65effb3d6d8655bd79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Tue, 22 Nov 2022 07:25:32 +0100 Subject: [PATCH] Fixed #1882 Close button on the menu toolbar --- CHANGELOG.md | 5 +- .../decompiler/flash/gui/MainFrameMenu.java | 58 +++++++++++-------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fe80fab1..836bc69ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. ##[Unreleased] +### Fixed +- [#1882] Close button on the menu toolbar ## [17.0.1] - 2022-11-21 ### Added @@ -2506,7 +2508,7 @@ All notable changes to this project will be documented in this file. ### Added - Initial public release -[Unreleased]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version17.0.0...dev +[17.0.1]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version17.0.0...version17.0.1 [17.0.0]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version16.3.1...version17.0.0 [16.3.1]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version16.3.0...version16.3.1 [16.3.0]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version16.2.0...version16.3.0 @@ -2637,6 +2639,7 @@ All notable changes to this project will be documented in this file. [alpha 9]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha8...alpha9 [alpha 8]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha7...alpha8 [alpha 7]: https://github.com/jindrapetrik/jpexs-decompiler/releases/tag/alpha7 +[#1882]: https://www.free-decompiler.com/flash/issues/1882 [#1880]: https://www.free-decompiler.com/flash/issues/1880 [#1881]: https://www.free-decompiler.com/flash/issues/1881 [#1870]: https://www.free-decompiler.com/flash/issues/1870 diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java index 69c8d42a3..62cf2a519 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java @@ -66,6 +66,9 @@ import javax.swing.JFrame; import javax.swing.JOptionPane; import com.jpexs.decompiler.flash.Bundle; import com.jpexs.decompiler.flash.treeitems.Openable; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Set; /** * @@ -80,9 +83,8 @@ public abstract class MainFrameMenu implements MenuBuilder { private Openable openable; private ConfigurationItemChangeListener configListenerAutoDeobfuscate; - - private ConfigurationItemChangeListener configListenerFlattenASPackages; + private ConfigurationItemChangeListener configListenerFlattenASPackages; private ConfigurationItemChangeListener configListenerSimplifyExpressions; @@ -151,7 +153,7 @@ public abstract class MainFrameMenu implements MenuBuilder { ViewMessages.showMessageDialog(mainFrame.getWindow(), translate("error.readonly.cannotSave"), translate("error"), JOptionPane.ERROR_MESSAGE); } Main.stopSaving(savedFile); - } else if ((openable instanceof SWF) && ((SWF)openable).binaryData != null) { + } else if ((openable instanceof SWF) && ((SWF) openable).binaryData != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { openable.saveTo(baos); @@ -239,23 +241,29 @@ public abstract class MainFrameMenu implements MenuBuilder { if (Main.isWorking()) { return; } - + Set listsToClose = new LinkedHashSet<>(); for (TreeItem item : mainFrame.getPanel().getCurrentTree().getSelected()) { - if (item instanceof SWF) { - SWF swf = (SWF) item; - if (swf.binaryData != null) { - // embedded swf - swf.binaryData.innerSwf = null; - swf.clearTagSwfs(); - } else { - Main.closeFile(swf.openableList); + if (item instanceof OpenableList) { + listsToClose.add((OpenableList) item); + } else { + Openable itemOpenable = item.getOpenable(); + if (itemOpenable instanceof SWF) { + SWF swf = (SWF) itemOpenable; + if (swf.binaryData != null) { + // embedded swf + swf.binaryData.innerSwf = null; + swf.clearTagSwfs(); + } else { + listsToClose.add(swf.openableList); + } + } else if (itemOpenable != null) { + listsToClose.add(itemOpenable.getOpenableList()); } - } else if (item instanceof Openable) { - Main.closeFile(((Openable) item).getOpenableList()); - } else if (item instanceof OpenableList) { - Main.closeFile((OpenableList) item); } } + for (OpenableList list : listsToClose) { + Main.closeFile(list); + } mainFrame.getPanel().refreshTree(); openable = null; Timer timer = new Timer(); @@ -273,8 +281,8 @@ public abstract class MainFrameMenu implements MenuBuilder { } if (openable != null) { - boolean result = Main.closeAll(); - if (result) { + boolean result = Main.closeAll(); + if (result) { openable = null; Timer timer = new Timer(); timer.schedule(new TimerTask() { @@ -312,7 +320,7 @@ public abstract class MainFrameMenu implements MenuBuilder { } mainFrame.getPanel().importImage((SWF) openable); } - + protected void importShapesActionPerformed(ActionEvent evt) { if (Main.isWorking()) { return; @@ -326,7 +334,7 @@ public abstract class MainFrameMenu implements MenuBuilder { } mainFrame.getPanel().importShape((SWF) openable, true); } - + protected void importSymbolClassActionPerformed(ActionEvent evt) { if (Main.isWorking()) { return; @@ -508,7 +516,7 @@ public abstract class MainFrameMenu implements MenuBuilder { protected void clearRecentSearchesActionPerformed(ActionEvent evt) { Main.searchResultsStorage.clear(); } - + protected void clearPinnedItemsActionPerformed(ActionEvent evt) { mainFrame.getPanel().destroyPins(); } @@ -678,7 +686,7 @@ public abstract class MainFrameMenu implements MenuBuilder { Configuration.autoOpenLoadedSWFs.set(selected); } - + protected void flattenASPackagesActionPerformed(ActionEvent evt) { AbstractButton button = (AbstractButton) evt.getSource(); boolean selected = button.isSelected(); @@ -838,7 +846,7 @@ public abstract class MainFrameMenu implements MenuBuilder { allSameOpenable = false; } } - if (firstSwf == null) { + if (firstSwf == null) { if (fopenable instanceof SWF) { firstSwf = (SWF) fopenable; } else { @@ -1133,7 +1141,7 @@ public abstract class MainFrameMenu implements MenuBuilder { addMenuItem("/settings/advancedSettings/advancedSettings", translate("menu.advancedsettings.advancedsettings"), "settings32", this::advancedSettingsActionPerformed, PRIORITY_TOP, null, true, null, false); addMenuItem("/settings/advancedSettings/clearRecentFiles", translate("menu.tools.otherTools.clearRecentFiles"), "clearrecent16", this::clearRecentFilesActionPerformed, PRIORITY_MEDIUM, null, true, null, false); addMenuItem("/settings/advancedSettings/clearRecentSearches", translate("menu.tools.otherTools.clearRecentSearches"), "clearrecent16", this::clearRecentSearchesActionPerformed, PRIORITY_MEDIUM, null, true, null, false); - addMenuItem("/settings/advancedSettings/clearPinnedItems", translate("menu.tools.otherTools.clearPinnedItems"), "clearrecent16", this::clearPinnedItemsActionPerformed, PRIORITY_MEDIUM, null, true, null, false); + addMenuItem("/settings/advancedSettings/clearPinnedItems", translate("menu.tools.otherTools.clearPinnedItems"), "clearrecent16", this::clearPinnedItemsActionPerformed, PRIORITY_MEDIUM, null, true, null, false); finishMenu("/settings/advancedSettings"); finishMenu("/settings"); @@ -1181,7 +1189,7 @@ public abstract class MainFrameMenu implements MenuBuilder { Configuration.autoOpenLoadedSWFs.addListener(configListenerAutoOpenLoadedSWFs = (Boolean newValue) -> { setMenuChecked("/settings/autoOpenLoadedSWFs", newValue); }); - + setMenuChecked("/settings/flattenASPackages", Configuration.flattenASPackages.get()); Configuration.flattenASPackages.addListener(configListenerFlattenASPackages = (Boolean newValue) -> { setMenuChecked("/settings/flattenASPackages", newValue);