show recent files in main menu

This commit is contained in:
Honfika
2013-11-10 17:40:47 +01:00
parent 2f49b47e87
commit 8125ecf7ef
5 changed files with 97 additions and 1 deletions
@@ -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<String> locale = null;
@ConfigurationDefaultString("_loc%d_")
public static final ConfigurationItem<String> registerNameFormat = null;
@ConfigurationDefaultInt(8)
public static final ConfigurationItem<Integer> maxRecentFileCount = null;
public static final ConfigurationItem<String> recentFiles = null;
public static final ConfigurationItem<Calendar> lastUpdatesCheckDate = null;
@@ -233,6 +238,27 @@ public class Configuration {
return ret;
}
public static List<String> getRecentFiles() {
String files = recentFiles.get();
if (files == null) {
return new ArrayList<>();
}
return Arrays.asList(recentFiles.get().split("::"));
}
public static void addRecentFile(String path) {
List<String> 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
*/
@@ -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;
@@ -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<String> 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);
@@ -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 <http://www.gnu.org/licenses/>.
*/
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);
}
}
@@ -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