fix trimming recent files list of excess files based on max setting
This commit is contained in:
parent
3f2ce3b810
commit
3ff5f782de
|
@ -120,6 +120,14 @@ enum MenuItem implements ActionListener {
|
||||||
listeners.add( ActionListener.class, listener );
|
listeners.add( ActionListener.class, listener );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void trimRecentFilesList(List<String> recentFiles) {
|
||||||
|
int numToTrim = recentFiles.size() - Settings.maxRecentFiles.get();
|
||||||
|
if (numToTrim > 0) {
|
||||||
|
for (int i = 0; i < numToTrim; ++i)
|
||||||
|
recentFiles.remove(recentFiles.size() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback to invoke whenever a file is opened. This method will sort the
|
* Callback to invoke whenever a file is opened. This method will sort the
|
||||||
* recent files menu to put the recently opened file at the top.
|
* recent files menu to put the recently opened file at the top.
|
||||||
|
@ -135,23 +143,21 @@ enum MenuItem implements ActionListener {
|
||||||
}
|
}
|
||||||
recentFiles.add( 0, path );
|
recentFiles.add( 0, path );
|
||||||
|
|
||||||
if ( recentFiles.size() > Settings.maxRecentFiles.get() ) {
|
trimRecentFilesList(recentFiles);
|
||||||
recentFiles.remove( (int)Settings.maxRecentFiles.get() );
|
|
||||||
}
|
|
||||||
Settings.recentFiles.set( recentFiles );
|
Settings.recentFiles.set( recentFiles );
|
||||||
populateRecentlyOpened();
|
populateRecentlyOpened();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills the {@code OPEN_RECENT} item with the list of recently opened
|
* Fills the {@code OPEN_RECENT} item with the list of recently opened
|
||||||
* files. If {@code MAX_FILES} is somehow lower than the recent files list
|
* files.
|
||||||
* length, the overflowing files are removed.
|
|
||||||
*/
|
*/
|
||||||
static void populateRecentlyOpened() {
|
static void populateRecentlyOpened() {
|
||||||
List<String> recentFiles = Settings.recentFiles.get();
|
List<String> recentFiles = Settings.recentFiles.get();
|
||||||
for ( int i = Settings.maxRecentFiles.get(); i < recentFiles.size(); i++ ) {
|
trimRecentFilesList(recentFiles);
|
||||||
recentFiles.remove( i - 1 );
|
Settings.recentFiles.set(recentFiles);
|
||||||
}
|
|
||||||
OPEN_RECENT.menuItem.removeAll();
|
OPEN_RECENT.menuItem.removeAll();
|
||||||
for ( String fileName : Settings.recentFiles.get() ) {
|
for ( String fileName : Settings.recentFiles.get() ) {
|
||||||
String text = fileName;
|
String text = fileName;
|
||||||
|
|
Reference in a new issue