From 8125ecf7ef5a0cfb8cbba20c619b00e8528a4361 Mon Sep 17 00:00:00 2001 From: Honfika Date: Sun, 10 Nov 2013 17:40:47 +0100 Subject: [PATCH] show recent files in main menu --- .../flash/configuration/Configuration.java | 26 ++++++++++++++ .../com/jpexs/decompiler/flash/gui/Main.java | 1 + .../jpexs/decompiler/flash/gui/MainFrame.java | 36 ++++++++++++++++++- .../flash/gui/RecentFilesButton.java | 34 ++++++++++++++++++ .../flash/gui/locales/MainFrame.properties | 1 + 5 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 trunk/src/com/jpexs/decompiler/flash/gui/RecentFilesButton.java diff --git a/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java index b95e7b98e..7b515ae56 100644 --- a/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.configuration; import com.jpexs.decompiler.flash.ApplicationInfo; +import com.jpexs.helpers.Helper; import com.jpexs.proxy.Replacement; import java.io.*; import java.lang.reflect.Field; @@ -24,6 +25,7 @@ import java.lang.reflect.Modifier; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.HashMap; import java.util.List; @@ -130,6 +132,9 @@ public class Configuration { public static final ConfigurationItem locale = null; @ConfigurationDefaultString("_loc%d_") public static final ConfigurationItem registerNameFormat = null; + @ConfigurationDefaultInt(8) + public static final ConfigurationItem maxRecentFileCount = null; + public static final ConfigurationItem recentFiles = null; public static final ConfigurationItem lastUpdatesCheckDate = null; @@ -233,6 +238,27 @@ public class Configuration { return ret; } + public static List getRecentFiles() { + String files = recentFiles.get(); + if (files == null) { + return new ArrayList<>(); + } + return Arrays.asList(recentFiles.get().split("::")); + } + + public static void addRecentFile(String path) { + List recentFilesArray = new ArrayList<>(getRecentFiles()); + int idx = recentFilesArray.indexOf(path); + if (idx != -1) { + recentFilesArray.remove(idx); + } + recentFilesArray.add(path); + while (recentFilesArray.size() >= maxRecentFileCount.get()) { + recentFilesArray.remove(0); + } + recentFiles.set(Helper.joinStrings(recentFilesArray, "::")); + } + /** * Saves replacements to file for future use */ diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java index f781aaabf..bfb204d6b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java @@ -349,6 +349,7 @@ public class Main { public static boolean openFile(String swfFile) { try { + Configuration.addRecentFile(swfFile); boolean ok = openFile(swfFile, new FileInputStream(swfFile)); if (ok) { readOnly = false; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java index 675ecf4dd..71c1a2cbd 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -214,6 +214,7 @@ import org.pushingpixels.flamingo.api.common.CommandButtonDisplayState; import org.pushingpixels.flamingo.api.common.CommandButtonLayoutManager; import org.pushingpixels.flamingo.api.common.JCommandButton; import org.pushingpixels.flamingo.api.common.JCommandButton.CommandButtonKind; +import org.pushingpixels.flamingo.api.common.JCommandButtonPanel; import org.pushingpixels.flamingo.api.common.icon.ResizableIcon; import org.pushingpixels.flamingo.api.ribbon.JRibbon; import org.pushingpixels.flamingo.api.ribbon.JRibbonBand; @@ -221,6 +222,7 @@ import org.pushingpixels.flamingo.api.ribbon.JRibbonComponent; import org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenu; import org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryFooter; import org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryPrimary; +import org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntrySecondary; import org.pushingpixels.flamingo.api.ribbon.RibbonElementPriority; import org.pushingpixels.flamingo.api.ribbon.RibbonTask; import org.pushingpixels.flamingo.api.ribbon.resize.BaseRibbonBandResizePolicy; @@ -543,10 +545,42 @@ public final class MainFrame extends AppRibbonFrame implements ActionListener, T RibbonApplicationMenuEntryPrimary exportSelMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("exportsel32"), translate("menu.file.export.selection"), new ActionRedirector(this, "EXPORTSEL"), CommandButtonKind.ACTION_ONLY); RibbonApplicationMenuEntryPrimary checkUpdatesMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("update32"), translate("menu.help.checkupdates"), new ActionRedirector(this, "CHECKUPDATES"), CommandButtonKind.ACTION_ONLY); RibbonApplicationMenuEntryPrimary aboutMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("about32"), translate("menu.help.about"), new ActionRedirector(this, "ABOUT"), CommandButtonKind.ACTION_ONLY); - // + RibbonApplicationMenuEntryPrimary openFileMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("open32"), translate("menu.file.open"), new ActionRedirector(this, "OPEN"), CommandButtonKind.ACTION_AND_POPUP_MAIN_ACTION); + openFileMenu.setRolloverCallback(new RibbonApplicationMenuEntryPrimary.PrimaryRolloverCallback() { + @Override + public void menuEntryActivated(JPanel targetPanel) { + targetPanel.removeAll(); + JCommandButtonPanel openHistoryPanel = new JCommandButtonPanel(CommandButtonDisplayState.MEDIUM); + String groupName = translate("menu.recentFiles"); + openHistoryPanel.addButtonGroup(groupName); + List recentFiles = Configuration.getRecentFiles(); + int j = 0; + for (int i = recentFiles.size() - 1; i >= 0; i--) { + String path = recentFiles.get(i); + RecentFilesButton historyButton = new RecentFilesButton(j + " " + path, null); + historyButton.fileName = path; + historyButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + RecentFilesButton source = (RecentFilesButton) ae.getSource(); + Main.openFile(source.fileName); + } + }); + j++; + historyButton.setHorizontalAlignment(SwingUtilities.LEFT); + openHistoryPanel.addButtonToLastGroup(historyButton); + } + openHistoryPanel.setMaxButtonColumns(1); + targetPanel.setLayout(new BorderLayout()); + targetPanel.add(openHistoryPanel, BorderLayout.CENTER); + } + }); + RibbonApplicationMenuEntryFooter exitMenu = new RibbonApplicationMenuEntryFooter(View.getResizableIcon("exit32"), translate("menu.file.exit"), new ActionRedirector(this, "EXIT")); + mainMenu.addMenuEntry(openFileMenu); + mainMenu.addMenuSeparator(); mainMenu.addMenuEntry(exportFlaMenu); mainMenu.addMenuEntry(exportAllMenu); mainMenu.addMenuEntry(exportSelMenu); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/RecentFilesButton.java b/trunk/src/com/jpexs/decompiler/flash/gui/RecentFilesButton.java new file mode 100644 index 000000000..7199c20be --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/gui/RecentFilesButton.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2013 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.gui; + +import org.pushingpixels.flamingo.api.common.JCommandButton; +import org.pushingpixels.flamingo.api.common.icon.ResizableIcon; + +/** + * + * @author JPEXS + */ +public class RecentFilesButton extends JCommandButton { + + public String fileName; + + public RecentFilesButton(String title, ResizableIcon icon) { + super(title, icon); + } + +} diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties b/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties index 3af759d2d..40f704a28 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties +++ b/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties @@ -374,3 +374,4 @@ filter.supported = All supported filetypes (*.swf, *.gfx) work.canceled = Canceled work.restoringControlFlow = Restoring control flow menu.advancedsettings.advancedsettings = Advanced Settings +menu.recentFiles = Recent files