Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 162102 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.properties (+1 lines)
Lines 219-224 Link Here
219
PreferenceKeywords.Restore = restore
219
PreferenceKeywords.Restore = restore
220
PreferenceKeywords.State = state
220
PreferenceKeywords.State = state
221
PreferenceKeywords.Encoding = encoding
221
PreferenceKeywords.Encoding = encoding
222
PreferenceKeywords.RecentWorkspaces = workspaces prompt recent startup
222
223
223
# TODO This stuff is just to help me work on the parsing of the menus extension
224
# TODO This stuff is just to help me work on the parsing of the menus extension
224
# point.  It is likely not in its final form yet.
225
# point.  It is likely not in its final form yet.
(-)plugin.xml (-1 / +4 lines)
Lines 411-416 Link Here
411
            id="org.eclipse.ui.ide.startupAndShutdown"
411
            id="org.eclipse.ui.ide.startupAndShutdown"
412
            label="%PreferenceKeywords.StartupAndShutdown"/>
412
            label="%PreferenceKeywords.StartupAndShutdown"/>
413
      <keyword
413
      <keyword
414
            id="org.eclipse.ui.ide.recentWorkspaces"
415
            label="%PreferenceKeywords.RecentWorkspaces"/>
416
      <keyword
414
            id="org.eclipse.ui.ide.workspace"
417
            id="org.eclipse.ui.ide.workspace"
415
            label="%PreferenceKeywords.Workspace"/>
418
            label="%PreferenceKeywords.Workspace"/>
416
      <keyword
419
      <keyword
Lines 2234-2240 Link Here
2234
            type="org.eclipse.core.resources.IMarker">
2237
            type="org.eclipse.core.resources.IMarker">
2235
      </propertyTester>
2238
      </propertyTester>
2236
   </extension>
2239
   </extension>
2237
      <extension
2240
   <extension
2238
         point="org.eclipse.ui.installationPages">
2241
         point="org.eclipse.ui.installationPages">
2239
          <page
2242
          <page
2240
            name="%installationPage.feature.name"
2243
            name="%installationPage.feature.name"
(-)src/org/eclipse/ui/internal/ide/ChooseWorkspaceData.java (-1 / +13 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 IBM Corporation and others.
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Eric Rizzo - added API to set the list of recent workspaces.
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.internal.ide;
12
package org.eclipse.ui.internal.ide;
12
13
Lines 192-197 Link Here
192
    }
193
    }
193
194
194
    /**
195
    /**
196
     * Sets the list of recent workspaces.
197
     */
198
    public void setRecentWorkspaces(String[] workspaces) {
199
    	if (workspaces == null) {
200
    		recentWorkspaces = new String[0];
201
    	} else {
202
			recentWorkspaces = workspaces;
203
		}
204
    }
205
206
    /**
195
	 * Update the persistent store. Call this function after the currently
207
	 * Update the persistent store. Call this function after the currently
196
	 * selected value has been found to be ok.
208
	 * selected value has been found to be ok.
197
	 */
209
	 */
(-)src/org/eclipse/ui/internal/ide/application/dialogs/IDEStartupPreferencePage.java (-29 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 IBM Corporation and others.
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Eric Rizzo - removed "prompt for workspace on startup" checkbox
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.internal.ide.application.dialogs;
12
package org.eclipse.ui.internal.ide.application.dialogs;
12
13
Lines 21-27 Link Here
21
import org.eclipse.ui.PlatformUI;
22
import org.eclipse.ui.PlatformUI;
22
import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
23
import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
23
import org.eclipse.ui.internal.dialogs.StartupPreferencePage;
24
import org.eclipse.ui.internal.dialogs.StartupPreferencePage;
24
import org.eclipse.ui.internal.ide.ChooseWorkspaceData;
25
import org.eclipse.ui.internal.ide.IDEInternalPreferences;
25
import org.eclipse.ui.internal.ide.IDEInternalPreferences;
26
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
26
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
27
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
27
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
Lines 38-45 Link Here
38
38
39
    private Button refreshButton;
39
    private Button refreshButton;
40
40
41
    private Button launchPromptButton;
42
43
    private Button exitPromptButton;
41
    private Button exitPromptButton;
44
42
45
    /*
43
    /*
Lines 54-60 Link Here
54
52
55
        Composite composite = createComposite(parent);
53
        Composite composite = createComposite(parent);
56
54
57
        createLaunchPromptPref(composite);
58
        createRefreshWorkspaceOnStartupPref(composite);
55
        createRefreshWorkspaceOnStartupPref(composite);
59
        createExitPromptPref(composite);
56
        createExitPromptPref(composite);
60
57
Lines 72-79 Link Here
72
    protected void performDefaults() {
69
    protected void performDefaults() {
73
        IPreferenceStore store = getIDEPreferenceStore();
70
        IPreferenceStore store = getIDEPreferenceStore();
74
71
75
        launchPromptButton.setSelection(true);
76
77
        refreshButton
72
        refreshButton
78
                .setSelection(store
73
                .setSelection(store
79
                        .getDefaultBoolean(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP));
74
                        .getDefaultBoolean(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP));
Lines 94-107 Link Here
94
        store.setValue(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP,
89
        store.setValue(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP,
95
                refreshButton.getSelection());
90
                refreshButton.getSelection());
96
91
97
        // TODO: This should get the value from the configuration preference
98
        //       area, but dj said we shouldn't use it yet; some final details are
99
        //       being worked out. Hopefully it will be available soon, at which time
100
        //       the entire recentWorkspaces.xml file can be removed. But until then,
101
        //       this preference reads/writes the file each time.
102
        ChooseWorkspaceData.setShowDialogValue(launchPromptButton
103
                .getSelection());
104
105
        // store the exit prompt on last window close setting
92
        // store the exit prompt on last window close setting
106
        store.setValue(IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW,
93
        store.setValue(IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW,
107
                exitPromptButton.getSelection());
94
                exitPromptButton.getSelection());
Lines 119-138 Link Here
119
                IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP));
106
                IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP));
120
    }
107
    }
121
108
122
    protected void createLaunchPromptPref(Composite composite) {
123
        launchPromptButton = new Button(composite, SWT.CHECK);
124
        launchPromptButton.setText(IDEWorkbenchMessages.StartupPreferencePage_launchPromptButton);
125
        launchPromptButton.setFont(composite.getFont());
126
127
        // TODO: This should get the value from the configuration preference
128
        //       area, but dj said we shouldn't use it yet; some final details are
129
        //       being worked out. Hopefully it will be available soon, at which time
130
        //       the entire recentWorkspaces.xml file can be removed. But until then,
131
        //       this preference reads/writes the file each time.
132
        launchPromptButton.setSelection(ChooseWorkspaceData
133
                .getShowDialogValue());
134
    }
135
136
    protected void createExitPromptPref(Composite composite) {
109
    protected void createExitPromptPref(Composite composite) {
137
        exitPromptButton = new Button(composite, SWT.CHECK);
110
        exitPromptButton = new Button(composite, SWT.CHECK);
138
        exitPromptButton.setText(IDEWorkbenchMessages.StartupPreferencePage_exitPromptButton);
111
        exitPromptButton.setText(IDEWorkbenchMessages.StartupPreferencePage_exitPromptButton);
(-)plugin.xml (+7 lines)
Lines 19-24 Link Here
19
            id="org.eclipse.ui.preferencePages.Startup">
19
            id="org.eclipse.ui.preferencePages.Startup">
20
         <keywordReference id="org.eclipse.ui.ide.startupAndShutdown"/>
20
         <keywordReference id="org.eclipse.ui.ide.startupAndShutdown"/>
21
      </page>
21
      </page>
22
     <page
23
            name="%PreferencePages.Startup.Workspaces"
24
            category="org.eclipse.ui.preferencePages.Startup"
25
            class="org.eclipse.ui.internal.ide.application.dialogs.RecentWorkspacesPreferencePage"
26
            id="org.eclipse.ui.preferencePages.Startup.Workspaces">
27
         <keywordReference id="org.eclipse.ui.ide.recentWorkspaces"/>
28
      </page>
22
    </extension>
29
    </extension>
23
     <extension
30
     <extension
24
         point="org.eclipse.ui.perspectives">
31
         point="org.eclipse.ui.perspectives">
(-)plugin.properties (+1 lines)
Lines 12-17 Link Here
12
Plugin.providerName = Eclipse.org
12
Plugin.providerName = Eclipse.org
13
13
14
PreferencePages.Startup = Startup and Shutdown
14
PreferencePages.Startup = Startup and Shutdown
15
PreferencePages.Startup.Workspaces = Workspaces
15
16
16
Perspective.resourcePerspective = Resource
17
Perspective.resourcePerspective = Resource
17
Perspective.resourceDescription = This perspective is designed to provide general resource viewing and navigation. 
18
Perspective.resourceDescription = This perspective is designed to provide general resource viewing and navigation. 
(-)src/org/eclipse/ui/internal/ide/application/dialogs/RecentWorkspacesPreferencePage.java (+182 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Eric Rizzo and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Eric Rizzo - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.ide.application.dialogs;
12
13
import java.util.ArrayList;
14
import java.util.Arrays;
15
16
import org.eclipse.core.runtime.Platform;
17
import org.eclipse.jface.preference.PreferencePage;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.events.SelectionAdapter;
20
import org.eclipse.swt.events.SelectionEvent;
21
import org.eclipse.swt.layout.GridData;
22
import org.eclipse.swt.layout.GridLayout;
23
import org.eclipse.swt.widgets.Button;
24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Group;
27
import org.eclipse.swt.widgets.Label;
28
import org.eclipse.swt.widgets.List;
29
import org.eclipse.swt.widgets.Spinner;
30
import org.eclipse.ui.IWorkbench;
31
import org.eclipse.ui.IWorkbenchPreferencePage;
32
import org.eclipse.ui.internal.ide.ChooseWorkspaceData;
33
34
35
/**
36
 * Preference page for editing the list of recent workspaces and whether or not
37
 * the user is prompted at startup.
38
 * 
39
 * @since 3.5
40
 */
41
public class RecentWorkspacesPreferencePage extends PreferencePage
42
	implements IWorkbenchPreferencePage {
43
44
	private static final int MIN_WORKSPACS = 5;
45
	private static final int MAX_WORKSPACES = 99;
46
	private static final int MAX_WORKSPACES_DIGIT_COUNT = 2;
47
48
	private ChooseWorkspaceData workspacesData;
49
50
	private Button promptOption;
51
	private Spinner maxWorkspacesField;
52
	private List workspacesList;
53
	private Button removeButton;
54
55
56
	public void init(IWorkbench workbench) {
57
		workspacesData = new ChooseWorkspaceData(Platform.getInstanceLocation().getURL());
58
	}
59
60
	public Control createContents(Composite parent) {
61
		Composite container = new Composite(parent, SWT.NULL);
62
		final GridLayout gridLayout = new GridLayout();
63
		gridLayout.numColumns = 2;
64
		gridLayout.marginHeight = 0;
65
		gridLayout.marginWidth = 0;
66
		container.setLayout(gridLayout);
67
68
		createPromptOption(container);
69
		createMaxWorkspacesField(container);
70
		createWorkspacesList(container);
71
72
		return container;
73
	}
74
75
76
	protected void createPromptOption(Composite parent) {
77
		promptOption = new Button(parent, SWT.CHECK);
78
		promptOption.setText("Prompt for &workspace on startup"); //$NON-NLS-1$
79
		promptOption.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
80
81
		promptOption.setSelection(workspacesData.getShowDialog());
82
		promptOption.addSelectionListener(new SelectionAdapter(){
83
				public void widgetSelected(SelectionEvent event) {
84
					workspacesData.toggleShowDialog();
85
				}
86
			});
87
	}
88
89
90
	protected void createMaxWorkspacesField(Composite parent) {
91
		final Label maxWorkspacesLabel = new Label(parent, SWT.NONE);
92
		maxWorkspacesLabel.setText("&Number of recent workspaces to remember:"); //$NON-NLS-1$
93
		maxWorkspacesField = new Spinner(parent, SWT.BORDER);
94
		maxWorkspacesField.setTextLimit(MAX_WORKSPACES_DIGIT_COUNT);
95
		maxWorkspacesField.setMinimum(MIN_WORKSPACS);
96
		maxWorkspacesField.setMaximum(MAX_WORKSPACES);
97
98
		maxWorkspacesField.setSelection(workspacesData.getRecentWorkspaces().length);
99
	}
100
101
102
	protected void createWorkspacesList(Composite parent) {
103
		final Group recentWorkspacesGroup = new Group(parent, SWT.NONE);
104
		recentWorkspacesGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
105
		recentWorkspacesGroup.setText("Recent workspaces"); //$NON-NLS-1$
106
		final GridLayout gridLayout_1 = new GridLayout();
107
		gridLayout_1.numColumns = 2;
108
		recentWorkspacesGroup.setLayout(gridLayout_1);
109
		
110
		workspacesList = new List(recentWorkspacesGroup, SWT.BORDER | SWT.MULTI);
111
		final GridData gd_workspacesList = new GridData(SWT.FILL, SWT.FILL, true, true);
112
		workspacesList.setLayoutData(gd_workspacesList);
113
		
114
		removeButton = new Button(recentWorkspacesGroup, SWT.NONE);
115
		final GridData gd_removeButton = new GridData(SWT.CENTER, SWT.TOP, false, false);
116
		removeButton.setLayoutData(gd_removeButton);
117
		removeButton.setText("&Remove"); //$NON-NLS-1$
118
		removeButton.setEnabled(false);
119
120
		removeButton.addSelectionListener(new SelectionAdapter(){
121
				public void widgetSelected(SelectionEvent event) {
122
					removeSelectedWorkspaces();
123
				}
124
			});
125
126
		workspacesList.addSelectionListener(new SelectionAdapter() {
127
				public void widgetSelected(SelectionEvent event) {
128
					removeButton.setEnabled(workspacesList.getSelectionCount() > 0);
129
				}
130
			});
131
132
		String[] recentWorkspaces = workspacesData.getRecentWorkspaces();
133
		for (int i = 0; i < recentWorkspaces.length; i++) {
134
			String aWorkspace = recentWorkspaces[i];
135
			if (aWorkspace != null) {
136
				workspacesList.add(aWorkspace);
137
			}
138
		}
139
	}
140
141
142
	protected void removeSelectedWorkspaces() {
143
		// This would be a lot less code if we could use Jakarta CollectionUtils and/or ArrayUtils
144
145
		int[] selected = workspacesList.getSelectionIndices();
146
		java.util.List workspaces = new ArrayList(Arrays.asList(workspacesList.getItems()));
147
148
		// Iterate bottom-up because removal changes indices in the list
149
		for (int i = selected.length-1; i >= 0; i--) {
150
			workspaces.remove(selected[i]);
151
		}
152
153
		String[] newItems = new String[workspaces.size()];
154
		workspaces.toArray(newItems);
155
		workspacesList.setItems(newItems);
156
	}
157
158
159
	protected void performDefaults() {
160
		promptOption.setSelection(true);
161
		super.performDefaults();
162
	}
163
164
165
	public boolean performOk() {
166
		int maxWorkspaces = maxWorkspacesField.getSelection();
167
		String[] workspaces = new String[maxWorkspaces];
168
		String[] listItems = workspacesList.getItems();
169
170
		if (maxWorkspaces < listItems.length) {
171
			// TODO: maybe alert the user that the list will be truncated?
172
			System.arraycopy(listItems, 0, workspaces, 0, maxWorkspaces);
173
		} else  {
174
			System.arraycopy(listItems, 0, workspaces, 0, listItems.length);
175
		}
176
177
		workspacesData.setRecentWorkspaces(workspaces);
178
		workspacesData.writePersistedData();
179
		return true;
180
	}
181
182
}

Return to bug 162102