From 5a88cb276ba92b9a7d1b40081614c74d89359b5e Mon Sep 17 00:00:00 2001 From: skylarmt Date: Fri, 9 Jan 2015 01:03:56 -0700 Subject: [PATCH] Recent list no longer has empty entries for missing files --- src/net/apocalypselabs/symat/MainGUI.java | 29 ++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/net/apocalypselabs/symat/MainGUI.java b/src/net/apocalypselabs/symat/MainGUI.java index c9a10f2..f7c404e 100644 --- a/src/net/apocalypselabs/symat/MainGUI.java +++ b/src/net/apocalypselabs/symat/MainGUI.java @@ -61,7 +61,7 @@ public class MainGUI extends javax.swing.JFrame { public static boolean skipEditor = false; // Skip editor init on start? private static boolean recentItemsMinimized = false; - + private static final int RECENT_FILES = 10; /** @@ -199,17 +199,30 @@ public class MainGUI extends javax.swing.JFrame { return; } String[] fileList = files.split("\n"); - KeyValListItem[] items = new KeyValListItem[fileList.length]; - for (int i = 0; i < fileList.length; i++) { - if (i < RECENT_FILES) { - File file = new File(fileList[i]); - if (file.isFile()) { - items[i] = new KeyValListItem(file.getName(), file.getPath()); - } + int neededLength = 0; + for (String file : fileList) { + if ((new File(file)).isFile()) { + neededLength++; + } + } + KeyValListItem[] items = new KeyValListItem[neededLength]; + int i = 0; + for (String f : fileList) { + File file = new File(f); + if (file.isFile()) { + items[i] = new KeyValListItem(file.getName(), file.getPath()); + i++; } } recentFileList.setListData(items); + + // Re-save list to remove bad entries + String list = ""; + for (KeyValListItem item : items) { + list += item.getValue() + "\n"; + } + PrefStorage.saveSetting("recentfiles", list); } public static void addRecentFile(String file) {