mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Added 'Recent Files'
This commit is contained in:
@@ -45,6 +45,7 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
|
||||
public static final String OUTLINE_KEY = "outline";
|
||||
public static final String THEME_KEY = "theme";
|
||||
public static final String RECENT_COMPONENTS_KEY = "recentComponents";
|
||||
public static final String RECENT_FILES_KEY = "recentFiles";
|
||||
public static final String SHOW_RULERS_KEY = "showRulers";
|
||||
public static final String SHOW_GRID_KEY = "showGrid";
|
||||
|
||||
|
||||
@@ -84,6 +84,8 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
public static final int ICON_SIZE = 32;
|
||||
|
||||
private static final int MAX_RECENT_FILES = 5;
|
||||
|
||||
private Project currentProject;
|
||||
private Map<String, List<ComponentType>> componentTypes;
|
||||
/**
|
||||
@@ -248,12 +250,25 @@ public class Presenter implements IPlugInPort {
|
||||
builder.append("</html");
|
||||
view.showMessage(builder.toString(), "Warning", IView.WARNING_MESSAGE);
|
||||
}
|
||||
addToRecentFiles(fileName);
|
||||
} catch (Exception ex) {
|
||||
LOG.error("Could not load file", ex);
|
||||
view.showMessage("Could not open file " + fileName + ". Check the log for details.", "Error", IView.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void addToRecentFiles(String fileName) {
|
||||
List<String> recentFiles = (List<String>) ConfigurationManager.getInstance().readObject(RECENT_FILES_KEY, null);
|
||||
if (recentFiles == null)
|
||||
recentFiles = new ArrayList<String>();
|
||||
recentFiles.remove(fileName);
|
||||
recentFiles.add(0, fileName);
|
||||
while (recentFiles.size() > MAX_RECENT_FILES)
|
||||
recentFiles.remove(recentFiles.size() - 1);
|
||||
ConfigurationManager.getInstance().writeValue(RECENT_FILES_KEY, recentFiles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowFileAction() {
|
||||
if (projectFileManager.isModified()) {
|
||||
@@ -282,6 +297,8 @@ public class Presenter implements IPlugInPort {
|
||||
try {
|
||||
currentProject.setFileVersion(CURRENT_VERSION);
|
||||
projectFileManager.serializeProjectToFile(currentProject, fileName, isBackup);
|
||||
if (!isBackup)
|
||||
addToRecentFiles(fileName);
|
||||
} catch (Exception ex) {
|
||||
LOG.error("Could not save file", ex);
|
||||
if (!isBackup) {
|
||||
|
||||
Reference in New Issue
Block a user