Skip to content

Commit 9e330e1

Browse files
committed
RecentFileService: split out persistence methods
1 parent 71ae0d1 commit 9e330e1

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/main/java/org/scijava/io/DefaultRecentFileService.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void add(final String path) {
111111
recentFiles.add(path);
112112

113113
// persist the updated list
114-
prefService.putList(recentFiles, RECENT_FILES_KEY);
114+
saveList();
115115

116116
if (present) {
117117
// path already present; update linked module info
@@ -135,7 +135,7 @@ public boolean remove(final String path) {
135135
final boolean success = recentFiles.remove(path);
136136

137137
// persist the updated list
138-
prefService.putList(recentFiles, RECENT_FILES_KEY);
138+
saveList();
139139

140140
// remove linked module info
141141
final ModuleInfo info = recentModules.remove(path);
@@ -164,7 +164,7 @@ public List<String> getRecentFiles() {
164164

165165
@Override
166166
public void initialize() {
167-
recentFiles = prefService.getList(RECENT_FILES_KEY);
167+
loadList();
168168
recentModules = new HashMap<String, ModuleInfo>();
169169
for (final String path : recentFiles) {
170170
recentModules.put(path, createInfo(path));
@@ -183,6 +183,16 @@ protected void onEvent(final IOEvent event) {
183183

184184
// -- Helper methods --
185185

186+
/** Loads the list of recent files from persistent storage. */
187+
private void loadList() {
188+
recentFiles = prefService.getList(RECENT_FILES_KEY);
189+
}
190+
191+
/** Saves the list of recent files to persistent storage. */
192+
private void saveList() {
193+
prefService.putList(recentFiles, RECENT_FILES_KEY);
194+
}
195+
186196
/** Creates a {@link ModuleInfo} to reopen data at the given path. */
187197
private ModuleInfo createInfo(final String path) {
188198
// CTR FIXME: Avoid circular (and compile-time-unsafe) dependency between

0 commit comments

Comments
 (0)