From 0fd4843df9a92e7b78d02ca5887aa9aa201500d0 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Mon, 25 May 2015 09:09:52 +0200 Subject: [PATCH] update menu selection when configuration changed in advanced settings --- .../configuration/ConfigurationItem.java | 29 ++++++++++ .../ConfigurationItemChangeListener.java | 28 ++++++++++ .../flash/tags/base/MorphShapeTag.java | 1 - .../flash/gui/AdvancedSettingsDialog.java | 2 +- .../decompiler/flash/gui/ExportDialog.java | 2 - src/com/jpexs/decompiler/flash/gui/Main.java | 3 +- .../decompiler/flash/gui/MainFrameMenu.java | 56 +++++++++++++------ .../flash/gui/ReplaceCharacterDialog.java | 1 - 8 files changed, 100 insertions(+), 22 deletions(-) create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/ConfigurationItemChangeListener.java diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/ConfigurationItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/ConfigurationItem.java index 1ab21a0ae..00604b8e9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/ConfigurationItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/ConfigurationItem.java @@ -16,6 +16,9 @@ */ package com.jpexs.decompiler.flash.configuration; +import java.util.ArrayList; +import java.util.List; + /** * * @author JPEXS @@ -33,6 +36,8 @@ public class ConfigurationItem { private boolean modified; + private List> listeners; + public ConfigurationItem(String name) { this.name = name; } @@ -71,12 +76,14 @@ public class ConfigurationItem { hasValue = true; modified = true; this.value = value; + fireConfigurationItemChanged(value); } public void unset() { hasValue = false; modified = true; this.value = null; + fireConfigurationItemChanged(defaultValue); } public boolean hasValue() { @@ -91,4 +98,26 @@ public class ConfigurationItem { public String toString() { return name; } + + private void fireConfigurationItemChanged(T newValue) { + if (listeners != null) { + for (ConfigurationItemChangeListener listener : listeners) { + listener.configurationItemChanged(newValue); + } + } + } + + public void addListener(ConfigurationItemChangeListener l) { + if (listeners == null) { + listeners = new ArrayList<>(); + } + + listeners.add(l); + } + + public void removeListener(ConfigurationItemChangeListener l) { + if (listeners != null) { + listeners.remove(l); + } + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/ConfigurationItemChangeListener.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/ConfigurationItemChangeListener.java new file mode 100644 index 000000000..6507ea592 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/ConfigurationItemChangeListener.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2010-2015 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; + +/** + * + * @author JPEXS + * @param + */ +@FunctionalInterface +public interface ConfigurationItemChangeListener { + + public void configurationItemChanged(T newValue); +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/MorphShapeTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/MorphShapeTag.java index 734309de4..b5bfe14ea 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/MorphShapeTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/MorphShapeTag.java @@ -23,7 +23,6 @@ import com.jpexs.decompiler.flash.exporters.morphshape.CanvasMorphShapeExporter; import com.jpexs.decompiler.flash.exporters.morphshape.SVGMorphShapeExporter; import com.jpexs.decompiler.flash.exporters.shape.BitmapExporter; import com.jpexs.decompiler.flash.exporters.shape.SVGShapeExporter; -import static com.jpexs.decompiler.flash.tags.base.DrawableTag.PARAMETER_RATIO; import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.ColorTransform; import com.jpexs.decompiler.flash.types.FILLSTYLEARRAY; diff --git a/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java b/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java index f651bb7b1..c67c419b1 100644 --- a/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java @@ -267,7 +267,7 @@ public class AdvancedSettingsDialog extends AppDialog { for (String name : keys) { Field field = fields.get(name); ConfigurationCategory cat = field.getAnnotation(ConfigurationCategory.class); - String scat = cat == null ? "other" : cat.value(); + String scat = (cat == null || cat.value().equals("")) ? "other" : cat.value(); if (!categorized.containsKey(scat)) { categorized.put(scat, new HashMap<>()); } diff --git a/src/com/jpexs/decompiler/flash/gui/ExportDialog.java b/src/com/jpexs/decompiler/flash/gui/ExportDialog.java index 181003a6e..f1a6c51ec 100644 --- a/src/com/jpexs/decompiler/flash/gui/ExportDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/ExportDialog.java @@ -30,8 +30,6 @@ import com.jpexs.decompiler.flash.exporters.modes.ShapeExportMode; import com.jpexs.decompiler.flash.exporters.modes.SoundExportMode; import com.jpexs.decompiler.flash.exporters.modes.SymbolClassExportMode; import com.jpexs.decompiler.flash.exporters.modes.TextExportMode; -import static com.jpexs.decompiler.flash.gui.AppDialog.CANCEL_OPTION; -import static com.jpexs.decompiler.flash.gui.AppDialog.OK_OPTION; import com.jpexs.decompiler.flash.gui.tagtree.TagTreeModel; import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag; import com.jpexs.decompiler.flash.tags.DefineVideoStreamTag; diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index 7ab9e162b..a144b6da5 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -896,8 +896,9 @@ public class Main { ContextMenuTools.addToContextMenu(true, false); } } + + Configuration.offeredAssociation.set(true); } - Configuration.offeredAssociation.set(true); } public static void initLang() { diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java index 4d915def4..b3d913ff9 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java @@ -22,7 +22,6 @@ import com.jpexs.decompiler.flash.SWFBundle; import com.jpexs.decompiler.flash.SWFSourceInfo; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.console.ContextMenuTools; -import static com.jpexs.decompiler.flash.gui.Main.openFile; import com.jpexs.decompiler.flash.gui.debugger.DebuggerTools; import com.jpexs.decompiler.flash.gui.helpers.CheckResources; import com.jpexs.decompiler.flash.tags.ABCContainerTag; @@ -706,6 +705,7 @@ public abstract class MainFrameMenu implements MenuBuilder { public void createMenuBar() { initMenu(); + if (supportsAppMenu()) { addMenuItem("_", null, null, null, 0, null, false); addMenuItem("_/open", translate("menu.file.open"), "open32", this::openActionPerformed, PRIORITY_TOP, this::loadRecent, false); @@ -733,6 +733,7 @@ public abstract class MainFrameMenu implements MenuBuilder { } else { finishMenu("/file/open"); } + addMenuItem("/file/save", translate("menu.file.save"), "save32", this::saveActionPerformed, PRIORITY_TOP, null, true); addMenuItem("/file/saveAs", translate("menu.file.saveas"), "saveas16", this::saveAsActionPerformed, PRIORITY_MEDIUM, null, true); addMenuItem("/file/saveAsExe", translate("menu.file.saveasexe"), "saveasexe16", this::saveAsExeActionPerformed, PRIORITY_MEDIUM, null, true); @@ -743,7 +744,6 @@ public abstract class MainFrameMenu implements MenuBuilder { addMenuItem("/file/export", translate("menu.export"), null, null, 0, null, false); addMenuItem("/file/export/exportFla", translate("menu.file.export.fla"), "exportfla32", this::exportFlaActionPerformed, PRIORITY_TOP, null, true); addMenuItem("/file/export/exportXml", translate("menu.file.export.xml"), "exportxml32", this::exportXmlActionPerformed, PRIORITY_MEDIUM, null, true); - addMenuItem("/file/export/exportAll", translate("menu.file.export.all"), "export16", this::exportAllActionPerformed, PRIORITY_MEDIUM, null, true); addMenuItem("/file/export/exportSelected", translate("menu.file.export.selection"), "exportsel16", this::exportSelectedActionPerformed, PRIORITY_MEDIUM, null, true); finishMenu("/file/export"); @@ -768,6 +768,7 @@ public abstract class MainFrameMenu implements MenuBuilder { addSeparator("/file"); addMenuItem("/file/exit", translate("menu.file.exit"), "exit32", this::exitActionPerformed, PRIORITY_TOP, null, true); } + finishMenu("/file"); if (Configuration.dumpView.get()) { @@ -805,22 +806,17 @@ public abstract class MainFrameMenu implements MenuBuilder { addMenuItem("/settings", translate("menu.settings"), null, null, 0, null, false); addToggleMenuItem("/settings/autoDeobfuscation", translate("menu.settings.autodeobfuscation"), null, null, this::autoDeobfuscationActionPerformed, 0); - addToggleMenuItem("/settings/internalViewer", translate("menu.settings.internalflashviewer"), null, null, this::internalViewerSwitchActionPerformed, 0); - addToggleMenuItem("/settings/parallelSpeedUp", translate("menu.settings.parallelspeedup"), null, null, this::parallelSpeedUpActionPerformed, 0); - addToggleMenuItem("/settings/disableDecompilation", translate("menu.settings.disabledecompilation"), null, null, this::disableDecompilationActionPerformed, 0); - addToggleMenuItem("/settings/cacheOnDisk", translate("menu.settings.cacheOnDisk"), null, null, this::cacheOnDiskActionPerformed, 0); - addToggleMenuItem("/settings/gotoMainClassOnStartup", translate("menu.settings.gotoMainClassOnStartup"), null, null, this::gotoDucumentClassOnStartupActionPerformed, 0); - addToggleMenuItem("/settings/autoRenameIdentifiers", translate("menu.settings.autoRenameIdentifiers"), null, null, this::autoRenameIdentifiersActionPerformed, 0); if (Platform.isWindows()) { addToggleMenuItem("/settings/associate", translate("menu.settings.addtocontextmenu"), null, null, this::associateActionPerformed, 0); } + addMenuItem("/settings/language", translate("menu.language"), null, null, 0, null, false); addMenuItem("/settings/language/setLanguage", translate("menu.settings.language"), "setlanguage32", this::setLanguageActionPerformed, PRIORITY_TOP, null, true); finishMenu("/settings/language"); @@ -838,22 +834,49 @@ public abstract class MainFrameMenu implements MenuBuilder { addMenuItem("/settings/advancedSettings", translate("menu.advancedsettings.advancedsettings"), null, null, 0, null, false); addMenuItem("/settings/advancedSettings/advancedSettings", translate("menu.advancedsettings.advancedsettings"), "settings32", this::advancedSettingsActionPerformed, PRIORITY_TOP, null, true); addMenuItem("/settings/advancedSettings/clearRecentFiles", translate("menu.tools.otherTools.clearRecentFiles"), "clearrecent16", this::clearRecentFilesActionPerformed, PRIORITY_MEDIUM, null, true); - finishMenu("/settings/advancedSettings"); finishMenu("/settings"); setMenuChecked("/settings/autoDeobfuscation", Configuration.autoDeobfuscate.get()); + Configuration.autoDeobfuscate.addListener((Boolean newValue) -> { + setMenuChecked("/settings/autoDeobfuscation", newValue); + }); + setMenuChecked("/settings/internalViewer", Configuration.internalFlashViewer.get() || externalFlashPlayerUnavailable); + Configuration.autoDeobfuscate.addListener((Boolean newValue) -> { + setMenuChecked("/settings/internalViewer", newValue || externalFlashPlayerUnavailable); + }); + setMenuChecked("/settings/parallelSpeedUp", Configuration.parallelSpeedUp.get()); + Configuration.autoDeobfuscate.addListener((Boolean newValue) -> { + setMenuChecked("/settings/parallelSpeedUp", newValue); + }); + setMenuChecked("/settings/disableDecompilation", !Configuration.decompile.get()); - setMenuChecked("/settings/cacheOnDisk", !Configuration.cacheOnDisk.get()); + Configuration.autoDeobfuscate.addListener((Boolean newValue) -> { + setMenuChecked("/settings/disableDecompilation", !newValue); + }); + + setMenuChecked("/settings/cacheOnDisk", Configuration.cacheOnDisk.get()); + Configuration.autoDeobfuscate.addListener((Boolean newValue) -> { + setMenuChecked("/settings/cacheOnDisk", newValue); + }); + setMenuChecked("/settings/gotoMainClassOnStartup", Configuration.gotoMainClassOnStartup.get()); + Configuration.autoDeobfuscate.addListener((Boolean newValue) -> { + setMenuChecked("/settings/gotoMainClassOnStartup", newValue); + }); + setMenuChecked("/settings/autoRenameIdentifiers", Configuration.autoRenameIdentifiers.get()); + Configuration.autoDeobfuscate.addListener((Boolean newValue) -> { + setMenuChecked("/settings/autoRenameIdentifiers", newValue); + }); if (externalFlashPlayerUnavailable) { setMenuEnabled("/settings/internalViewer", false); } + int deobfuscationMode = Configuration.deobfuscationMode.get(); switch (deobfuscationMode) { case 0: @@ -863,10 +886,11 @@ public abstract class MainFrameMenu implements MenuBuilder { setGroupSelection("deobfuscation", "/settings/deobfuscation/new"); break; } + if (Platform.isWindows()) { setMenuChecked("/settings/associate", ContextMenuTools.isAddedToContextMenu()); - } + //Help addMenuItem("/help", translate("menu.help"), null, null, 0, null, false); addMenuItem("/help/helpUs", translate("menu.help.helpus"), "donate32", this::helpUsActionPerformed, PRIORITY_TOP, null, true); @@ -910,12 +934,14 @@ public abstract class MainFrameMenu implements MenuBuilder { }, PRIORITY_MEDIUM, null, true); addMenuItem("/debug/openTestSwfs", "Open test SWFs", "update16", e -> { String path; + SWFSourceInfo[] sourceInfos = new SWFSourceInfo[2]; - path = Main.class.getProtectionDomain().getCodeSource().getLocation().getPath() + "\\..\\..\\libsrc\\ffdec_lib\\testdata\\as2\\as2.swf"; + String mainPath = Main.class.getProtectionDomain().getCodeSource().getLocation().getPath(); + path = mainPath + "\\..\\..\\libsrc\\ffdec_lib\\testdata\\as2\\as2.swf"; sourceInfos[0] = new SWFSourceInfo(null, path, null); - path = Main.class.getProtectionDomain().getCodeSource().getLocation().getPath() + "\\..\\..\\libsrc\\ffdec_lib\\testdata\\as3\\as3.swf"; + path = mainPath + "\\..\\..\\libsrc\\ffdec_lib\\testdata\\as3\\as3.swf"; sourceInfos[1] = new SWFSourceInfo(null, path, null); - openFile(sourceInfos); + Main.openFile(sourceInfos); }, PRIORITY_MEDIUM, null, true); finishMenu("/debug"); } @@ -928,7 +954,6 @@ public abstract class MainFrameMenu implements MenuBuilder { mainFrame.getPanel().showView(MainPanel.VIEW_RESOURCES); setGroupSelection("view", "/file/view/viewResources"); setMenuChecked("/tools/timeline", false); - } private void viewHexActionPerformed(ActionEvent evt) { @@ -989,6 +1014,5 @@ public abstract class MainFrameMenu implements MenuBuilder { finishMenu("/file/" + (supportsMenuAction() ? "open" : "recent")); finishMenu("_/open"); - } } diff --git a/src/com/jpexs/decompiler/flash/gui/ReplaceCharacterDialog.java b/src/com/jpexs/decompiler/flash/gui/ReplaceCharacterDialog.java index 61b506ac1..d838d5da3 100644 --- a/src/com/jpexs/decompiler/flash/gui/ReplaceCharacterDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/ReplaceCharacterDialog.java @@ -17,7 +17,6 @@ package com.jpexs.decompiler.flash.gui; import com.jpexs.decompiler.flash.SWF; -import static com.jpexs.decompiler.flash.gui.AppDialog.ERROR_OPTION; import com.jpexs.decompiler.flash.tags.base.CharacterTag; import java.awt.BorderLayout; import java.awt.Dimension;