Bug 128411 - [RCP] Allow size of recently opened files list to be changed
Summary: [RCP] Allow size of recently opened files list to be changed
Status: ASSIGNED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1.1   Edit
Hardware: PC Windows XP
: P3 enhancement with 10 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords: api, helpwanted
Depends on:
Blocks:
 
Reported: 2006-02-17 09:38 EST by Paul E. Keyser CLA
Modified: 2019-09-06 15:36 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul E. Keyser CLA 2006-02-17 09:38:46 EST
So one is stuck with the value "4" in all RCP apps. This seems like a pointless limitation. Probably there is some way to get the IDE preference-page to show up, but why should RCP-app writers have to use IDE (which is recommended against)?
Comment 1 Paul E. Keyser CLA 2006-02-17 09:58:14 EST
BTW, here is what I have tried: 

I have a working RCP app, composed of several features; it deploys correctly. I have not added any of the existing Eclipse preference pages, so all I have are my own, which is fine. (I haven't tried to reuse existing pages, because I do not want most of what's there, but also due to the bug:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=73587 )

However, I would like to allow users to set certain Eclipse-preferences; so I imagine I would create the appropriate UI in my preference-page, and then set the value of the given preference in the IPreferenceStore. In particular, the size of the recently-opened files list (as seen in the EditorHistory class) can be as large as 15, but defaults to 4. I'd like to set it, presumably something like this:

    prefs.setDefault("RECENT_FILES", 12); // or call setValue()?

But -- what is the id/name of that preference? By looking at ReopenEditorMenu#fill(), I see that the name is stored in
    WorkbenchPlugin.getDefault().getPreferenceStore().getInt(IPreferenceConstants.RECENT_FILES)

but, when I try to use the value of IPreferenceConstants.RECENT_FILES, i.e., "RECENT_FILES", to set the value from 4 to 12, as above, using either setDefault() or setValue(), on *my* preference store, there is no change in behavior, and the File menu's list stubbornly remains at length 4. Since the WorkbenchPlugin is in org.eclipse.ui.internal, there does not seem to be any way to do what I want. 
Comment 2 Nick Edgar CLA 2006-02-20 10:13:50 EST
Correct, this is only available via internals currently.

An app can override the default value programmatically using the preference customization mechansim described here:
http://wiki.eclipse.org/index.php/RCP_FAQ#customPrefs

and specifying the following line in the .ini file:
org.eclipse.ui.workbench/RECENT_FILES=12

The org.eclipse.ui.workbench preference store is also exposed via the deprecated IWorkbench.getPreferenceStore() method, so you can use that to change the value.

Either way, you would still be referring to an internal preference though, since org.eclipse.ui.workbench's preference store is not intended to be exposed as API.  

The fix would be to move this to the org.eclipse.ui preference store, and provide the constant as API in IWorkbenchPreferenceConstants.
Comment 3 Paul E. Keyser CLA 2006-02-20 17:53:14 EST
Thanks for the advice; glad to see some prospect of a fix. 

Meanwhile, I tried using the deprecated IWorkbench.getPreferenceStore() method, to change the default value (works) and to allow the user to specify their desired value (fails). 

On my preference page I have an IntegerFieldEditor, with tag equal to IPreferenceConstants.RECENT_FILES, on which I make sure to call field.setPreferenceStore(PlatformUI.getWorkbench().getPreferenceStore()) -- and the field indeed displays whatever value I programmatically set for the default (e.g. 12) -- but if the user changes the value, the ReopenEditorMenu does not seem to update (still shows 12 items), unlike the ReopenEditorMenu in Eclipse, which updates immediately. 

So I must be missing something -- any idea what? 
Comment 4 Nick Edgar CLA 2006-02-21 12:55:34 EST
If you open a new window, does it then get the new value?

Not sure why it's not working.  The value should be obtained each time the menu is populated.  Try setting a breakpoint in ReopenEditorMenu.fill and tracing through it.

Also, if you're using a FieldEditorPreferencePage, it's possible the field's preference store is getting overridden by FieldEditorPreferencePage.initialize.
Comment 5 Paul E. Keyser CLA 2006-02-27 17:30:37 EST
(In reply to comment #4)
> If you open a new window, does it then get the new value?
> 
Nope, still the old value. 

> Also, if you're using a FieldEditorPreferencePage, it's possible the field's
> preference store is getting overridden by FieldEditorPreferencePage.initialize.
> 
That was the problem! I should have read the code more thoroughly. Here is what I have now done to get the workaround to work: 

1) As above, in https://bugs.eclipse.org/bugs/show_bug.cgi?id=128411#c3

2) Then, in the createFieldEditors() method of my pref-page: 

PlatformUI.getPreferenceStore().addPropertyChangeListener(

new IPropertyChangeListener() {
    public void propertyChange(PropertyChangeEvent e) {
        if (e.getProperty().equals(RECENT_FILES)) { 
            if (!e.getOldValue().equals(e.getNewValue())) {
                final int ourValue = 
                    PlatformUI.getPreferenceStore().getInt(RECENT_FILES); 
                final IPreferenceStore theirs = 
                    PlatformUI.getWorkbench().getPreferenceStore();
                theirs.setValue(RECENT_FILES, ourValue);
            }
        }
    }
}
); 

and that works. 
Thanks
Comment 6 Nick Edgar CLA 2006-03-02 12:27:13 EST
Rather than copying the value between preference stores, you could override the field editor's preference store after the page sets it:

protected void initialize() {
  super.initialize();
  numFilesFieldEditor.setPreferenceStore(PlatformUI.getWorkbench().getPreferenceStore());
  numFilesFieldEditor.load();

}
Comment 7 Nick Edgar CLA 2006-03-15 11:24:37 EST
Reassigning bugs in component areas that are changing ownership.
Comment 8 Boris Bokowski CLA 2009-11-26 16:15:06 EST
Prakash is now responsible for watching bugs in the [RCP] component area.
Comment 9 Eclipse Webmaster CLA 2019-09-06 15:33:01 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
Comment 10 Eclipse Webmaster CLA 2019-09-06 15:36:13 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.