Search code examples
eclipseeclipse-rcp

How do I programmatically set the length of Most Recent Used files in Eclipse


In Eclipse, I'm aware of the Preference setting for the number of recently opened files to offer:

Preference

For users of my RCP application I'd like to change the default length from 4 to 10.

I'm aware of the PreferenceManager, and can navigate to the correct node using this:

IPreferenceNode editorPrefs = preferenceManager.find
("/org.eclipse.ui.preferencePages.Workbench/org.eclipse.ui.preferencePages.Editors");

But, once I've found the node, I can't see how to access the specific property, in order to modify a value.

Anyone one done this before? Any tips?

Alternatively, I'm happy to do it via extension-point, but I couldn't get even this far via that mechanism.


Solution

  • This preference is set in the preferences for the org.eclipse.ui.workbench plugin. You can access this using ScopedPreferenceStore

    IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.ui.workbench");
    

    The key for recent files is RECENT_FILES so:

    store.setValue("RECENT_FILES", value);
    

    You may need to call the save() method to store the changes.