View | Details | Raw Unified | Return to bug 129132 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/internal/ide/dialogs/IDEWorkspacePreferencePage.java (-16 / +31 lines)
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
 *     ARM Ltd - ARM Ltd - prompt to save before manual build (bug 129132)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.internal.ide.dialogs;
12
package org.eclipse.ui.internal.ide.dialogs;
12
13
Lines 27-32 Link Here
27
import org.eclipse.jface.util.PropertyChangeEvent;
28
import org.eclipse.jface.util.PropertyChangeEvent;
28
import org.eclipse.osgi.util.NLS;
29
import org.eclipse.osgi.util.NLS;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.SWT;
31
import org.eclipse.swt.events.SelectionEvent;
32
import org.eclipse.swt.events.SelectionListener;
30
import org.eclipse.swt.layout.GridData;
33
import org.eclipse.swt.layout.GridData;
31
import org.eclipse.swt.layout.GridLayout;
34
import org.eclipse.swt.layout.GridLayout;
32
import org.eclipse.swt.widgets.Button;
35
import org.eclipse.swt.widgets.Button;
Lines 58-64 Link Here
58
61
59
	private Button autoBuildButton;
62
	private Button autoBuildButton;
60
63
61
    private Button autoSaveAllButton;
64
    private RadioGroupFieldEditor saveBeforeBuildEditor;
62
65
63
    private IntegerFieldEditor saveInterval;
66
    private IntegerFieldEditor saveInterval;
64
67
Lines 141-157 Link Here
141
	}
144
	}
142
145
143
	protected void createSaveAllBeforeBuildPref(Composite composite) {
146
	protected void createSaveAllBeforeBuildPref(Composite composite) {
144
        autoSaveAllButton = new Button(composite, SWT.CHECK);
147
        String[][] namesAndValues = {
145
        autoSaveAllButton.setText(IDEWorkbenchMessages.IDEWorkspacePreference_savePriorToBuilding);
148
                { IDEWorkbenchMessages.Always, IDEInternalPreferences.PSPM_ALWAYS },
146
        autoSaveAllButton.setToolTipText(IDEWorkbenchMessages.IDEWorkspacePreference_savePriorToBuildingToolTip);
149
                { IDEWorkbenchMessages.Never, IDEInternalPreferences.PSPM_NEVER },
147
        autoSaveAllButton.setSelection(getIDEPreferenceStore().getBoolean(
150
                { IDEWorkbenchMessages.Prompt, IDEInternalPreferences.PSPM_PROMPT } };
148
                IDEInternalPreferences.SAVE_ALL_BEFORE_BUILD));
151
		saveBeforeBuildEditor = new RadioGroupFieldEditor(IDEInternalPreferences.SAVE_ALL_BEFORE_BUILD,
149
    }
152
				                                          IDEWorkbenchMessages.IDEWorkspacePreference_savePriorToBuilding,
153
				                                          3, namesAndValues, composite, true);
154
		saveBeforeBuildEditor.setPreferenceStore(getIDEPreferenceStore());
155
		saveBeforeBuildEditor.setPage(this);
156
		composite.setToolTipText(IDEWorkbenchMessages.IDEWorkspacePreference_savePriorToBuildingToolTip);
157
		saveBeforeBuildEditor.load();
158
		saveBeforeBuildEditor.setEnabled(!autoBuildButton.getSelection(), composite);
159
	}
150
160
151
    protected void createAutoBuildPref(Composite composite) {
161
    protected void createAutoBuildPref(final Composite composite) {
152
        autoBuildButton = new Button(composite, SWT.CHECK);
162
        autoBuildButton = new Button(composite, SWT.CHECK);
153
        autoBuildButton.setText(IDEWorkbenchMessages.IDEWorkspacePreference_autobuild);
163
        autoBuildButton.setText(IDEWorkbenchMessages.IDEWorkspacePreference_autobuild);
154
        autoBuildButton.setToolTipText(IDEWorkbenchMessages.IDEWorkspacePreference_autobuildToolTip);
164
        autoBuildButton.setToolTipText(IDEWorkbenchMessages.IDEWorkspacePreference_autobuildToolTip);
165
        autoBuildButton.addSelectionListener(new SelectionListener() {
166
167
			public void widgetDefaultSelected(SelectionEvent e) {
168
				widgetSelected(e);
169
			}
170
171
			public void widgetSelected(SelectionEvent e) {
172
				saveBeforeBuildEditor.setEnabled(!autoBuildButton.getSelection(), composite);
173
			}
174
        	
175
    	});
155
        autoBuildButton.setSelection(ResourcesPlugin.getWorkspace()
176
        autoBuildButton.setSelection(ResourcesPlugin.getWorkspace()
156
                .isAutoBuilding());
177
                .isAutoBuilding());
157
    }
178
    }
Lines 326-335 Link Here
326
                .getDefaultBoolean(ResourcesPlugin.PREF_AUTO_BUILDING);
347
                .getDefaultBoolean(ResourcesPlugin.PREF_AUTO_BUILDING);
327
        autoBuildButton.setSelection(autoBuild);
348
        autoBuildButton.setSelection(autoBuild);
328
349
329
        IPreferenceStore store = getIDEPreferenceStore();
350
        saveBeforeBuildEditor.loadDefault();
330
        autoSaveAllButton
331
                .setSelection(store
332
                        .getDefaultBoolean(IDEInternalPreferences.SAVE_ALL_BEFORE_BUILD));
333
        saveInterval.loadDefault();
351
        saveInterval.loadDefault();
334
352
335
		
353
		
Lines 370-379 Link Here
370
388
371
        IPreferenceStore store = getIDEPreferenceStore();
389
        IPreferenceStore store = getIDEPreferenceStore();
372
390
373
        // store the save all prior to build setting
374
        store.setValue(IDEInternalPreferences.SAVE_ALL_BEFORE_BUILD,
375
                autoSaveAllButton.getSelection());
376
377
        // store the workspace save interval
391
        // store the workspace save interval
378
        // @issue we should drop our preference constant and let clients use
392
        // @issue we should drop our preference constant and let clients use
379
        // core's pref. ours is not up-to-date anyway if someone changes this
393
        // core's pref. ours is not up-to-date anyway if someone changes this
Lines 408-413 Link Here
408
        encodingEditor.store();
422
        encodingEditor.store();
409
		lineSeparatorEditor.store();
423
		lineSeparatorEditor.store();
410
		openReferencesEditor.store();
424
		openReferencesEditor.store();
425
		saveBeforeBuildEditor.store();
411
        return super.performOk();
426
        return super.performOk();
412
    }
427
    }
413
428
(-)src/org/eclipse/ui/internal/ide/dialogs/CleanDialog.java (-270 / +321 lines)
Lines 12-17 Link Here
12
 *******************************************************************************/
12
 *******************************************************************************/
13
package org.eclipse.ui.internal.ide.dialogs;
13
package org.eclipse.ui.internal.ide.dialogs;
14
14
15
import java.util.Arrays;
16
15
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.resources.IncrementalProjectBuilder;
18
import org.eclipse.core.resources.IncrementalProjectBuilder;
17
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.resources.ResourcesPlugin;
Lines 56-201 Link Here
56
 * @since 3.0
58
 * @since 3.0
57
 */
59
 */
58
public class CleanDialog extends MessageDialog {
60
public class CleanDialog extends MessageDialog {
59
    
61
60
    private static final String DIALOG_SETTINGS_SECTION = "CleanDialogSettings"; //$NON-NLS-1$
62
	private static final String DIALOG_SETTINGS_SECTION = "CleanDialogSettings"; //$NON-NLS-1$
61
    private static final String DIALOG_ORIGIN_X = "DIALOG_X_ORIGIN"; //$NON-NLS-1$
63
	private static final String DIALOG_ORIGIN_X = "DIALOG_X_ORIGIN"; //$NON-NLS-1$
62
    private static final String DIALOG_ORIGIN_Y = "DIALOG_Y_ORIGIN"; //$NON-NLS-1$
64
	private static final String DIALOG_ORIGIN_Y = "DIALOG_Y_ORIGIN"; //$NON-NLS-1$
63
    private static final String DIALOG_WIDTH = "DIALOG_WIDTH"; //$NON-NLS-1$
65
	private static final String DIALOG_WIDTH = "DIALOG_WIDTH"; //$NON-NLS-1$
64
    private static final String DIALOG_HEIGHT = "DIALOG_HEIGHT"; //$NON-NLS-1$
66
	private static final String DIALOG_HEIGHT = "DIALOG_HEIGHT"; //$NON-NLS-1$
65
    private static final String TOGGLE_SELECTED = "TOGGLE_SELECTED"; //$NON-NLS-1$
67
	private static final String TOGGLE_SELECTED = "TOGGLE_SELECTED"; //$NON-NLS-1$
66
    private static final String BUILD_NOW = "BUILD_NOW"; //$NON-NLS-1$
68
	private static final String BUILD_NOW = "BUILD_NOW"; //$NON-NLS-1$
67
    
69
68
    private Button allButton, selectedButton, buildNowButton;
70
	private Button allButton, selectedButton, buildNowButton;
69
71
70
    private CheckboxTableViewer projectNames;
72
	private CheckboxTableViewer projectNames;
71
73
72
    private Object[] selection;
74
	private Object[] selection;
73
75
74
    private IWorkbenchWindow window;
76
	private IWorkbenchWindow window;
75
77
76
    /**
78
	/**
77
     * Gets the text of the clean dialog, depending on whether the
79
	 * Gets the text of the clean dialog, depending on whether the workspace is
78
     * workspace is currently in autobuild mode.
80
	 * currently in autobuild mode.
79
     * @return String the question the user will be asked.
81
	 * 
80
     */
82
	 * @return String the question the user will be asked.
81
    private static String getQuestion() {
83
	 */
82
        boolean autoBuilding = ResourcesPlugin.getWorkspace().isAutoBuilding();
84
	private static String getQuestion() {
83
        if (autoBuilding) {
85
		boolean autoBuilding = ResourcesPlugin.getWorkspace().isAutoBuilding();
86
		if (autoBuilding) {
84
			return IDEWorkbenchMessages.CleanDialog_buildCleanAuto;
87
			return IDEWorkbenchMessages.CleanDialog_buildCleanAuto;
85
		}
88
		}
86
        return IDEWorkbenchMessages.CleanDialog_buildCleanManual;
89
		return IDEWorkbenchMessages.CleanDialog_buildCleanManual;
87
    }
90
	}
88
91
89
    /**
92
	/**
90
     * Creates a new clean dialog.
93
	 * Creates a new clean dialog.
91
     * 
94
	 * 
92
     * @param window the window to create it in
95
	 * @param window
93
     * @param selection the currently selected projects (may be empty)
96
	 *            the window to create it in
94
     */
97
	 * @param selection
95
    public CleanDialog(IWorkbenchWindow window, IProject[] selection) {
98
	 *            the currently selected projects (may be empty)
96
        super(
99
	 */
97
                window.getShell(),
100
	public CleanDialog(IWorkbenchWindow window, IProject[] selection) {
98
                IDEWorkbenchMessages.CleanDialog_title, null, getQuestion(), NONE, new String[] {
101
		super(window.getShell(), IDEWorkbenchMessages.CleanDialog_title, null,
99
                IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
102
				getQuestion(), NONE, new String[] { IDialogConstants.OK_LABEL,
100
        this.window = window;
103
						IDialogConstants.CANCEL_LABEL }, 0);
101
        this.selection = selection;
104
		this.window = window;
102
        if (this.selection == null) {
105
		this.selection = selection;
106
		if (this.selection == null) {
103
			this.selection = new Object[0];
107
			this.selection = new Object[0];
104
		}
108
		}
105
    }
109
	}
106
110
107
    /*
111
	/*
108
     * (non-Javadoc)
112
	 * (non-Javadoc)
109
     * 
113
	 * 
110
     * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
114
	 * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
111
     */
115
	 */
112
    protected void buttonPressed(int buttonId) {
116
	protected void buttonPressed(int buttonId) {
113
        final boolean cleanAll = allButton.getSelection();
117
		final boolean cleanAll = allButton.getSelection();
114
        final boolean buildAll = buildNowButton != null
118
		final boolean buildAll = buildNowButton != null
115
                && buildNowButton.getSelection();
119
				&& buildNowButton.getSelection();
116
        super.buttonPressed(buttonId);
120
		super.buttonPressed(buttonId);
117
        if (buttonId != IDialogConstants.OK_ID) {
121
		if (buttonId != IDialogConstants.OK_ID) {
118
			return;
122
			return;
119
		}
123
		}
120
        //save all dirty editors
124
		// save all dirty editors
121
        BuildUtilities.saveEditors(null);
125
		// save dirty editors in projects to be cleaned
122
        //batching changes ensures that autobuild runs after cleaning
126
		if (cleanAll) {
123
    	WorkspaceJob cleanJob = new WorkspaceJob(IDEWorkbenchMessages.CleanDialog_taskName) {
127
			if (!BuildUtilities.saveEditors(null)) {
124
    		public boolean belongsTo(Object family) {
128
				return;
125
    			return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family);
129
			}
126
    		}
130
		} else {
127
			public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
131
			if (!BuildUtilities.saveEditors(Arrays.asList(selection))) {
128
                doClean(cleanAll, monitor);
132
				return;
129
                //see if a build was requested
133
			}
130
                if (buildAll) {
134
		}
131
                    //start an immediate workspace build
135
132
                    GlobalBuildAction build = new GlobalBuildAction(window,
136
		// batching changes ensures that autobuild runs after cleaning
133
                            IncrementalProjectBuilder.INCREMENTAL_BUILD);
137
		// batching changes ensures that autobuild runs after cleaning
134
                    build.doBuild();
138
		WorkspaceJob cleanJob = new WorkspaceJob(
135
                }
139
				IDEWorkbenchMessages.CleanDialog_taskName) {
136
                return Status.OK_STATUS;
140
			public boolean belongsTo(Object family) {
137
    		}
141
				return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family);
138
    	};
142
			}
139
        cleanJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory()
143
140
                .buildRule());
144
			public IStatus runInWorkspace(IProgressMonitor monitor)
141
        cleanJob.setUser(true);
145
					throws CoreException {
142
        cleanJob.schedule();
146
				doClean(cleanAll, monitor);
143
    }
147
				// see if a build was requested
144
148
				if (buildAll) {
145
    /* (non-Javadoc)
149
					// start an immediate workspace build
146
     * @see org.eclipse.jface.dialogs.MessageDialog#createCustomArea(org.eclipse.swt.widgets.Composite)
150
					GlobalBuildAction build = new GlobalBuildAction(window,
147
     */
151
							IncrementalProjectBuilder.INCREMENTAL_BUILD);
148
    protected Control createCustomArea(Composite parent) {
152
					build.doBuild();
149
        Composite area = new Composite(parent, SWT.NONE);
153
				}
150
        GridLayout layout = new GridLayout();
154
				return Status.OK_STATUS;
151
        layout.marginWidth = layout.marginHeight = 0;
155
			}
152
        layout.numColumns = 2;
156
		};
153
        layout.makeColumnsEqualWidth = true;
157
		cleanJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory()
154
        area.setLayout(layout);
158
				.buildRule());
155
        area.setLayoutData(new GridData(GridData.FILL_BOTH));
159
		cleanJob.setUser(true);
156
        SelectionListener updateEnablement = new SelectionAdapter() {
160
		cleanJob.schedule();
157
            public void widgetSelected(SelectionEvent e) {
161
	}
158
                updateEnablement();
162
159
            }
163
	/*
160
        };
164
	 * (non-Javadoc)
161
165
	 * 
162
        IDialogSettings settings = getDialogSettings(DIALOG_SETTINGS_SECTION);
166
	 * @see org.eclipse.jface.dialogs.MessageDialog#createCustomArea(org.eclipse.swt.widgets.Composite)
163
        boolean selectSelectedButton= settings.getBoolean(TOGGLE_SELECTED);
167
	 */
164
        //first row
168
	protected Control createCustomArea(Composite parent) {
165
        allButton = new Button(area, SWT.RADIO);
169
		Composite area = new Composite(parent, SWT.NONE);
166
        allButton.setText(IDEWorkbenchMessages.CleanDialog_cleanAllButton);
170
		GridLayout layout = new GridLayout();
167
        allButton.setSelection(!selectSelectedButton);
171
		layout.marginWidth = layout.marginHeight = 0;
168
        allButton.addSelectionListener(updateEnablement);
172
		layout.numColumns = 2;
169
        selectedButton = new Button(area, SWT.RADIO);
173
		layout.makeColumnsEqualWidth = true;
170
        selectedButton.setText(IDEWorkbenchMessages.CleanDialog_cleanSelectedButton);
174
		area.setLayout(layout);
171
        selectedButton.setSelection(selectSelectedButton);
175
		area.setLayoutData(new GridData(GridData.FILL_BOTH));
172
        selectedButton.addSelectionListener(updateEnablement);
176
		SelectionListener updateEnablement = new SelectionAdapter() {
173
177
			public void widgetSelected(SelectionEvent e) {
174
        //second row
178
				updateEnablement();
175
        createProjectSelectionTable(area);
179
			}
176
        
180
		};
177
        //third row
181
178
        //only prompt for immediate build if autobuild is off
182
		IDialogSettings settings = getDialogSettings(DIALOG_SETTINGS_SECTION);
179
        if (!ResourcesPlugin.getWorkspace().isAutoBuilding()) {
183
		boolean selectSelectedButton = settings.getBoolean(TOGGLE_SELECTED);
180
            buildNowButton = new Button(parent, SWT.CHECK);
184
		// first row
181
            buildNowButton.setText(IDEWorkbenchMessages.CleanDialog_buildNowButton);
185
		allButton = new Button(area, SWT.RADIO);
182
            String buildNow = settings.get(BUILD_NOW);
186
		allButton.setText(IDEWorkbenchMessages.CleanDialog_cleanAllButton);
183
            buildNowButton.setSelection(buildNow == null || Boolean.valueOf(buildNow).booleanValue());
187
		allButton.setSelection(!selectSelectedButton);
184
            buildNowButton.setLayoutData(new GridData(
188
		allButton.addSelectionListener(updateEnablement);
185
                    GridData.HORIZONTAL_ALIGN_BEGINNING));
189
		selectedButton = new Button(area, SWT.RADIO);
186
        }
190
		selectedButton
187
        projectNames.getTable().setEnabled(selectSelectedButton);
191
				.setText(IDEWorkbenchMessages.CleanDialog_cleanSelectedButton);
188
        return area;
192
		selectedButton.setSelection(selectSelectedButton);
189
    }
193
		selectedButton.addSelectionListener(updateEnablement);
190
194
191
    private void createProjectSelectionTable(Composite radioGroup) {
195
		// second row
192
    	projectNames = CheckboxTableViewer.newCheckList(radioGroup, SWT.BORDER);
196
		createProjectSelectionTable(area);
193
    	projectNames.setContentProvider(new WorkbenchContentProvider());
197
194
    	projectNames.setLabelProvider(new WorkbenchLabelProvider());
198
		// third row
195
    	projectNames.setComparator(new ResourceComparator(ResourceComparator.NAME));
199
		// only prompt for immediate build if autobuild is off
196
    	projectNames.addFilter(new ViewerFilter() {
200
		if (!ResourcesPlugin.getWorkspace().isAutoBuilding()) {
197
    		private final IProject[] projectHolder = new IProject[1];
201
			buildNowButton = new Button(parent, SWT.CHECK);
198
			public boolean select(Viewer viewer, Object parentElement, Object element) {
202
			buildNowButton
203
					.setText(IDEWorkbenchMessages.CleanDialog_buildNowButton);
204
			String buildNow = settings.get(BUILD_NOW);
205
			buildNowButton.setSelection(buildNow == null
206
					|| Boolean.valueOf(buildNow).booleanValue());
207
			buildNowButton.setLayoutData(new GridData(
208
					GridData.HORIZONTAL_ALIGN_BEGINNING));
209
		}
210
		projectNames.getTable().setEnabled(selectSelectedButton);
211
		return area;
212
	}
213
214
	private void createProjectSelectionTable(Composite radioGroup) {
215
		projectNames = CheckboxTableViewer.newCheckList(radioGroup, SWT.BORDER);
216
		projectNames.setContentProvider(new WorkbenchContentProvider());
217
		projectNames.setLabelProvider(new WorkbenchLabelProvider());
218
		projectNames.setComparator(new ResourceComparator(
219
				ResourceComparator.NAME));
220
		projectNames.addFilter(new ViewerFilter() {
221
			private final IProject[] projectHolder = new IProject[1];
222
223
			public boolean select(Viewer viewer, Object parentElement,
224
					Object element) {
199
				if (!(element instanceof IProject)) {
225
				if (!(element instanceof IProject)) {
200
					return false;
226
					return false;
201
				}
227
				}
Lines 204-222 Link Here
204
					return false;
230
					return false;
205
				}
231
				}
206
				projectHolder[0] = project;
232
				projectHolder[0] = project;
207
				return BuildUtilities.isEnabled(projectHolder, IncrementalProjectBuilder.CLEAN_BUILD);
233
				return BuildUtilities.isEnabled(projectHolder,
234
						IncrementalProjectBuilder.CLEAN_BUILD);
208
			}
235
			}
209
		});
236
		});
210
    	projectNames.setInput(ResourcesPlugin.getWorkspace().getRoot());
237
		projectNames.setInput(ResourcesPlugin.getWorkspace().getRoot());
211
    	GridData data = new GridData(GridData.FILL_BOTH);
238
		GridData data = new GridData(GridData.FILL_BOTH);
212
    	data.horizontalSpan = 2;
239
		data.horizontalSpan = 2;
213
    	data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
240
		data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
214
    	data.heightHint = IDialogConstants.ENTRY_FIELD_WIDTH;
241
		data.heightHint = IDialogConstants.ENTRY_FIELD_WIDTH;
215
    	projectNames.getTable().setLayoutData(data);
242
		projectNames.getTable().setLayoutData(data);
216
    	projectNames.setCheckedElements(selection);
243
		projectNames.setCheckedElements(selection);
217
    	//table is disabled to start because all button is selected
244
		// table is disabled to start because all button is selected
218
    	projectNames.getTable().setEnabled(selectedButton.getSelection());
245
		projectNames.getTable().setEnabled(selectedButton.getSelection());
219
    	projectNames.addCheckStateListener(new ICheckStateListener() {
246
		projectNames.addCheckStateListener(new ICheckStateListener() {
220
			public void checkStateChanged(CheckStateChangedEvent event) {
247
			public void checkStateChanged(CheckStateChangedEvent event) {
221
				selection = projectNames.getCheckedElements();
248
				selection = projectNames.getCheckedElements();
222
				updateEnablement();
249
				updateEnablement();
Lines 226-365 Link Here
226
253
227
	/**
254
	/**
228
	 * Performs the actual clean operation.
255
	 * Performs the actual clean operation.
229
	 * @param cleanAll if <code>true</true> clean all projects
256
	 * 
257
	 * @param cleanAll
258
	 *            if <code>true</true> clean all projects
230
	 * @param monitor The monitor that the build will report to
259
	 * @param monitor The monitor that the build will report to
231
	 * @throws CoreException thrown if there is a problem from the
260
	 * @throws CoreException thrown if there is a problem from the
232
	 * core builder.
261
	 * core builder.
233
	 */
262
	 */
234
	protected void doClean(boolean cleanAll, IProgressMonitor monitor)
263
	protected void doClean(boolean cleanAll, IProgressMonitor monitor)
235
	        throws CoreException {
264
			throws CoreException {
236
	    if (cleanAll) {
265
		if (cleanAll) {
237
			ResourcesPlugin.getWorkspace().build(
266
			ResourcesPlugin.getWorkspace().build(
238
	                IncrementalProjectBuilder.CLEAN_BUILD, monitor);
267
					IncrementalProjectBuilder.CLEAN_BUILD, monitor);
239
		} else {
268
		} else {
240
	        try {
269
			try {
241
	            monitor.beginTask(IDEWorkbenchMessages.CleanDialog_taskName, selection.length);
270
				monitor.beginTask(IDEWorkbenchMessages.CleanDialog_taskName,
242
	            for (int i = 0; i < selection.length; i++) {
271
						selection.length);
272
				for (int i = 0; i < selection.length; i++) {
243
					((IProject) selection[i]).build(
273
					((IProject) selection[i]).build(
244
	                        IncrementalProjectBuilder.CLEAN_BUILD,
274
							IncrementalProjectBuilder.CLEAN_BUILD,
245
	                        new SubProgressMonitor(monitor, 1));
275
							new SubProgressMonitor(monitor, 1));
246
				}
276
				}
247
	        } finally {
277
			} finally {
248
	            monitor.done();
278
				monitor.done();
249
	        }
279
			}
250
	    }
280
		}
251
	}
281
	}
252
282
253
    /**
283
	/**
254
     * Updates the enablement of the dialog's ok button based
284
	 * Updates the enablement of the dialog's ok button based on the current
255
     * on the current choices in the dialog.
285
	 * choices in the dialog.
256
     */
286
	 */
257
    protected void updateEnablement() {
287
	protected void updateEnablement() {
258
    	projectNames.getTable().setEnabled(selectedButton.getSelection());
288
		projectNames.getTable().setEnabled(selectedButton.getSelection());
259
        boolean enabled = allButton.getSelection() || selection.length > 0;
289
		boolean enabled = allButton.getSelection() || selection.length > 0;
260
        getButton(OK).setEnabled(enabled);
290
		getButton(OK).setEnabled(enabled);
261
    }
291
	}
262
    
292
263
    /* (non-Javadoc)
293
	/*
264
     * @see org.eclipse.jface.window.Window#close()
294
	 * (non-Javadoc)
265
     */
295
	 * 
266
    public boolean close() {
296
	 * @see org.eclipse.jface.window.Window#close()
267
        persistDialogSettings(getShell(), DIALOG_SETTINGS_SECTION);
297
	 */
268
        return super.close();
298
	public boolean close() {
269
    }
299
		persistDialogSettings(getShell(), DIALOG_SETTINGS_SECTION);
270
    
300
		return super.close();
271
    /* (non-Javadoc)
301
	}
272
     * @see org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point)
302
273
     */
303
	/*
274
    protected Point getInitialLocation(Point initialSize) {
304
	 * (non-Javadoc)
275
        Point p = getInitialLocation(DIALOG_SETTINGS_SECTION);
305
	 * 
276
        return p != null ? p : super.getInitialLocation(initialSize);
306
	 * @see org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point)
277
    }
307
	 */
278
    
308
	protected Point getInitialLocation(Point initialSize) {
279
    /* (non-Javadoc)
309
		Point p = getInitialLocation(DIALOG_SETTINGS_SECTION);
280
     * @see org.eclipse.jface.window.Window#getInitialSize()
310
		return p != null ? p : super.getInitialLocation(initialSize);
281
     */
311
	}
282
    protected Point getInitialSize() {
312
283
        Point p = super.getInitialSize();
313
	/*
284
        return getInitialSize(DIALOG_SETTINGS_SECTION, p);
314
	 * (non-Javadoc)
285
    }
315
	 * 
286
    
316
	 * @see org.eclipse.jface.window.Window#getInitialSize()
287
    /**
317
	 */
288
     * Returns the initial location which is persisted in the Ant UI Plugin dialog settings
318
	protected Point getInitialSize() {
289
     * under the provided dialog setttings section name.
319
		Point p = super.getInitialSize();
290
     * If location is not persisted in the settings, the <code>null</code> is returned. 
320
		return getInitialSize(DIALOG_SETTINGS_SECTION, p);
291
     * 
321
	}
292
     * @param dialogSettingsSectionName The name of the dialog settings section
322
293
     * @return The initial location or <code>null</code>
323
	/**
294
     */
324
	 * Returns the initial location which is persisted in the Ant UI Plugin
295
    public Point getInitialLocation(String dialogSettingsSectionName) {
325
	 * dialog settings under the provided dialog setttings section name. If
296
        IDialogSettings settings = getDialogSettings(dialogSettingsSectionName);
326
	 * location is not persisted in the settings, the <code>null</code> is
297
        try {
327
	 * returned.
298
            int x= settings.getInt(DIALOG_ORIGIN_X);
328
	 * 
299
            int y= settings.getInt(DIALOG_ORIGIN_Y);
329
	 * @param dialogSettingsSectionName
300
            return new Point(x,y);
330
	 *            The name of the dialog settings section
301
        } catch (NumberFormatException e) {
331
	 * @return The initial location or <code>null</code>
302
        }
332
	 */
303
        return null;
333
	public Point getInitialLocation(String dialogSettingsSectionName) {
304
    }
334
		IDialogSettings settings = getDialogSettings(dialogSettingsSectionName);
305
    
335
		try {
306
    private IDialogSettings getDialogSettings(String dialogSettingsSectionName) {
336
			int x = settings.getInt(DIALOG_ORIGIN_X);
307
        IDialogSettings settings = IDEWorkbenchPlugin.getDefault().getDialogSettings();
337
			int y = settings.getInt(DIALOG_ORIGIN_Y);
308
        IDialogSettings section = settings.getSection(dialogSettingsSectionName);
338
			return new Point(x, y);
309
        if (section == null) {
339
		} catch (NumberFormatException e) {
310
            section = settings.addNewSection(dialogSettingsSectionName);
340
		}
311
        } 
341
		return null;
312
        return section;
342
	}
313
    }
343
314
    
344
	private IDialogSettings getDialogSettings(String dialogSettingsSectionName) {
315
    /**
345
		IDialogSettings settings = IDEWorkbenchPlugin.getDefault()
316
     * Persists the location and dimensions of the shell and other user settings in the
346
				.getDialogSettings();
317
     * plugin's dialog settings under the provided dialog settings section name
347
		IDialogSettings section = settings
318
     * 
348
				.getSection(dialogSettingsSectionName);
319
     * @param shell The shell whose geometry is to be stored
349
		if (section == null) {
320
     * @param dialogSettingsSectionName The name of the dialog settings section
350
			section = settings.addNewSection(dialogSettingsSectionName);
321
     */
351
		}
322
    private void persistDialogSettings(Shell shell, String dialogSettingsSectionName) {
352
		return section;
323
        Point shellLocation = shell.getLocation();
353
	}
324
        Point shellSize = shell.getSize();
354
325
        IDialogSettings settings = getDialogSettings(dialogSettingsSectionName);
355
	/**
326
        settings.put(DIALOG_ORIGIN_X, shellLocation.x);
356
	 * Persists the location and dimensions of the shell and other user settings
327
        settings.put(DIALOG_ORIGIN_Y, shellLocation.y);
357
	 * in the plugin's dialog settings under the provided dialog settings
328
        settings.put(DIALOG_WIDTH, shellSize.x);
358
	 * section name
329
        settings.put(DIALOG_HEIGHT, shellSize.y);
359
	 * 
330
        
360
	 * @param shell
331
        if (buildNowButton != null) {
361
	 *            The shell whose geometry is to be stored
332
            settings.put(BUILD_NOW, buildNowButton.getSelection());
362
	 * @param dialogSettingsSectionName
333
        }
363
	 *            The name of the dialog settings section
334
        settings.put(TOGGLE_SELECTED, selectedButton.getSelection());
364
	 */
335
    }
365
	private void persistDialogSettings(Shell shell,
336
    
366
			String dialogSettingsSectionName) {
337
    /**
367
		Point shellLocation = shell.getLocation();
338
     * Returns the initial size which is the larger of the <code>initialSize</code> or
368
		Point shellSize = shell.getSize();
339
     * the size persisted in the Ant UI Plugin dialog settings under the provided dialog setttings section name.
369
		IDialogSettings settings = getDialogSettings(dialogSettingsSectionName);
340
     * If no size is persisted in the settings, the <code>initialSize</code> is returned. 
370
		settings.put(DIALOG_ORIGIN_X, shellLocation.x);
341
     * 
371
		settings.put(DIALOG_ORIGIN_Y, shellLocation.y);
342
     * @param initialSize The initialSize to compare against
372
		settings.put(DIALOG_WIDTH, shellSize.x);
343
     * @param dialogSettingsSectionName The name of the dialog settings section
373
		settings.put(DIALOG_HEIGHT, shellSize.y);
344
     * @return the initial size
374
345
     */
375
		if (buildNowButton != null) {
346
    private Point getInitialSize(String dialogSettingsSectionName, Point initialSize) {
376
			settings.put(BUILD_NOW, buildNowButton.getSelection());
347
        IDialogSettings settings = getDialogSettings(dialogSettingsSectionName);
377
		}
348
        try {
378
		settings.put(TOGGLE_SELECTED, selectedButton.getSelection());
349
            int x, y;
379
	}
350
            x = settings.getInt(DIALOG_WIDTH);
380
351
            y = settings.getInt(DIALOG_HEIGHT);
381
	/**
352
            return new Point(Math.max(x, initialSize.x), Math.max(y, initialSize.y));
382
	 * Returns the initial size which is the larger of the
353
        } catch (NumberFormatException e) {
383
	 * <code>initialSize</code> or the size persisted in the Ant UI Plugin
354
        }
384
	 * dialog settings under the provided dialog setttings section name. If no
355
        return initialSize;
385
	 * size is persisted in the settings, the <code>initialSize</code> is
356
    }
386
	 * returned.
357
    
387
	 * 
358
    /*
388
	 * @param initialSize
359
     * (non-Javadoc)
389
	 *            The initialSize to compare against
360
     * @see org.eclipse.jface.dialogs.Dialog#isResizable()
390
	 * @param dialogSettingsSectionName
361
     */
391
	 *            The name of the dialog settings section
362
    protected boolean isResizable() {
392
	 * @return the initial size
363
    	return true;
393
	 */
364
    }
394
	private Point getInitialSize(String dialogSettingsSectionName,
395
			Point initialSize) {
396
		IDialogSettings settings = getDialogSettings(dialogSettingsSectionName);
397
		try {
398
			int x, y;
399
			x = settings.getInt(DIALOG_WIDTH);
400
			y = settings.getInt(DIALOG_HEIGHT);
401
			return new Point(Math.max(x, initialSize.x), Math.max(y,
402
					initialSize.y));
403
		} catch (NumberFormatException e) {
404
		}
405
		return initialSize;
406
	}
407
408
	/*
409
	 * (non-Javadoc)
410
	 * 
411
	 * @see org.eclipse.jface.dialogs.Dialog#isResizable()
412
	 */
413
	protected boolean isResizable() {
414
		return true;
415
	}
365
}
416
}
(-)extensions/org/eclipse/ui/actions/BuildAction.java (-17 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 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
 *     ARM Ltd - ARM Ltd - prompt to save before manual build (bug 129132)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.actions;
12
package org.eclipse.ui.actions;
12
13
Lines 25-39 Link Here
25
import org.eclipse.core.resources.ResourcesPlugin;
26
import org.eclipse.core.resources.ResourcesPlugin;
26
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.IProgressMonitor;
28
import org.eclipse.core.runtime.IProgressMonitor;
28
import org.eclipse.jface.preference.IPreferenceStore;
29
import org.eclipse.jface.viewers.IStructuredSelection;
29
import org.eclipse.jface.viewers.IStructuredSelection;
30
import org.eclipse.jface.viewers.StructuredSelection;
30
import org.eclipse.jface.viewers.StructuredSelection;
31
import org.eclipse.swt.widgets.Shell;
31
import org.eclipse.swt.widgets.Shell;
32
import org.eclipse.ui.IWorkbenchWindow;
32
import org.eclipse.ui.IWorkbenchWindow;
33
import org.eclipse.ui.PlatformUI;
33
import org.eclipse.ui.PlatformUI;
34
import org.eclipse.ui.internal.ide.IDEInternalPreferences;
35
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
34
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
36
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
37
import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
35
import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
38
import org.eclipse.ui.internal.ide.actions.BuildUtilities;
36
import org.eclipse.ui.internal.ide.actions.BuildUtilities;
39
37
Lines 206-223 Link Here
206
		return super.isEnabled();
204
		return super.isEnabled();
207
	}
205
	}
208
    
206
    
209
    /**
210
     * Returns whether the user's preference is set to automatically save modified
211
     * resources before a manual build is done.
212
     *
213
     * @return <code>true</code> if Save All Before Build is enabled
214
     */
215
    public static boolean isSaveAllSet() {
216
        IPreferenceStore store = IDEWorkbenchPlugin.getDefault()
217
                .getPreferenceStore();
218
        return store.getBoolean(IDEInternalPreferences.SAVE_ALL_BEFORE_BUILD);
219
    }
220
221
    /* (non-Javadoc)
207
    /* (non-Javadoc)
222
     * Method declared on WorkspaceAction.
208
     * Method declared on WorkspaceAction.
223
     *
209
     *
Lines 278-284 Link Here
278
		}
264
		}
279
265
280
	    // Save all resources prior to doing build
266
	    // Save all resources prior to doing build
281
        BuildUtilities.saveEditors(projects);
267
        if (!BuildUtilities.saveEditors(projects)) {
268
        	return;
269
        }
282
        runInBackground(ResourcesPlugin.getWorkspace().getRuleFactory()
270
        runInBackground(ResourcesPlugin.getWorkspace().getRuleFactory()
283
                .buildRule(), ResourcesPlugin.FAMILY_MANUAL_BUILD);
271
                .buildRule(), ResourcesPlugin.FAMILY_MANUAL_BUILD);
284
    }
272
    }
(-)extensions/org/eclipse/ui/actions/GlobalBuildAction.java (-2 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 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
 *     ARM Ltd - prompt to save before manual build (bug 129132)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.actions;
12
package org.eclipse.ui.actions;
12
13
Lines 237-243 Link Here
237
			return;
238
			return;
238
		}
239
		}
239
        // Save all resources prior to doing build
240
        // Save all resources prior to doing build
240
        BuildUtilities.saveEditors(null);
241
        if (!BuildUtilities.saveEditors(null)) {
242
        	return;
243
        }
241
        // Perform the build on all the projects
244
        // Perform the build on all the projects
242
        doBuildOperation();
245
        doBuildOperation();
243
    }
246
    }
(-)src/org/eclipse/ui/internal/ide/IDEInternalPreferences.java (-2 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 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
 *     ARM Ltd - prompt to save before manual build (bug 129132)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
12
12
package org.eclipse.ui.internal.ide;
13
package org.eclipse.ui.internal.ide;
Lines 17-23 Link Here
17
 * The IDEInternalPreferences are the internal constants used by the Workbench.
18
 * The IDEInternalPreferences are the internal constants used by the Workbench.
18
 */
19
 */
19
public interface IDEInternalPreferences {
20
public interface IDEInternalPreferences {
20
    // (boolean) Save all dirty editors before running a full or incremental build 
21
    // (String) Save all dirty editors before running a full or incremental build 
21
    public static final String SAVE_ALL_BEFORE_BUILD = "SAVE_ALL_BEFORE_BUILD"; //$NON-NLS-1$
22
    public static final String SAVE_ALL_BEFORE_BUILD = "SAVE_ALL_BEFORE_BUILD"; //$NON-NLS-1$
22
23
23
    // (boolean) Refresh workspace on startup 
24
    // (boolean) Refresh workspace on startup 
(-)src/org/eclipse/ui/internal/ide/IDEPreferenceInitializer.java (-2 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
2
 * Copyright (c) 2004, 2007 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
 *     ARM Ltd - prompt to save before manual build (bug 129132)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.internal.ide;
12
package org.eclipse.ui.internal.ide;
12
13
Lines 45-51 Link Here
45
46
46
		// Internal preferences
47
		// Internal preferences
47
48
48
		node.putBoolean(IDEInternalPreferences.SAVE_ALL_BEFORE_BUILD, false);
49
		node.put(IDEInternalPreferences.SAVE_ALL_BEFORE_BUILD, 
50
				IDEInternalPreferences.PSPM_PROMPT);
49
		node.putInt(IDEInternalPreferences.SAVE_INTERVAL, 5); // 5 minutes
51
		node.putInt(IDEInternalPreferences.SAVE_INTERVAL, 5); // 5 minutes
50
		node.putBoolean(IDEInternalPreferences.WELCOME_DIALOG, true);
52
		node.putBoolean(IDEInternalPreferences.WELCOME_DIALOG, true);
51
		node.putBoolean(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP,
53
		node.putBoolean(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP,
(-)src/org/eclipse/ui/internal/ide/actions/BuildUtilities.java (-15 / +50 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
2
 * Copyright (c) 2004, 2007 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-17 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 * IBM - Initial API and implementation
9
 * IBM - Initial API and implementation
10
 * ARM Ltd - prompt to save before manual build (bug 129132)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.internal.ide.actions;
12
package org.eclipse.ui.internal.ide.actions;
12
13
14
import java.util.ArrayList;
13
import java.util.Collection;
15
import java.util.Collection;
14
import java.util.HashSet;
16
import java.util.HashSet;
17
import java.util.List;
15
18
16
import org.eclipse.core.resources.ICommand;
19
import org.eclipse.core.resources.ICommand;
17
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IFile;
Lines 22-36 Link Here
22
import org.eclipse.core.resources.ResourcesPlugin;
25
import org.eclipse.core.resources.ResourcesPlugin;
23
import org.eclipse.core.resources.mapping.ResourceMapping;
26
import org.eclipse.core.resources.mapping.ResourceMapping;
24
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
29
import org.eclipse.jface.operation.IRunnableContext;
25
import org.eclipse.jface.viewers.ISelection;
30
import org.eclipse.jface.viewers.ISelection;
26
import org.eclipse.jface.viewers.IStructuredSelection;
31
import org.eclipse.jface.viewers.IStructuredSelection;
32
import org.eclipse.jface.window.IShellProvider;
33
import org.eclipse.swt.widgets.Shell;
27
import org.eclipse.ui.IEditorPart;
34
import org.eclipse.ui.IEditorPart;
28
import org.eclipse.ui.IWorkbenchPage;
35
import org.eclipse.ui.IWorkbenchPage;
29
import org.eclipse.ui.IWorkbenchPart;
36
import org.eclipse.ui.IWorkbenchPart;
30
import org.eclipse.ui.IWorkbenchWindow;
37
import org.eclipse.ui.IWorkbenchWindow;
31
import org.eclipse.ui.PlatformUI;
38
import org.eclipse.ui.PlatformUI;
32
import org.eclipse.ui.actions.BuildAction;
33
import org.eclipse.ui.ide.ResourceUtil;
39
import org.eclipse.ui.ide.ResourceUtil;
40
import org.eclipse.ui.internal.EditorManager;
41
import org.eclipse.ui.internal.ide.IDEInternalPreferences;
42
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
34
43
35
/**
44
/**
36
 * This class contains convenience methods used by the various build commands
45
 * This class contains convenience methods used by the various build commands
Lines 150-181 Link Here
150
	 * of projects depending on the user's preference.
159
	 * of projects depending on the user's preference.
151
	 * @param projects The projects in which to save editors, or <code>null</code>
160
	 * @param projects The projects in which to save editors, or <code>null</code>
152
	 * to save editors in all projects.
161
	 * to save editors in all projects.
162
	 * @return <code>true</code> if it is OK to continue with the build, or <code>false</code>
163
	 * otherwise (i.e. if the user has canceled).
153
	 */
164
	 */
154
	public static void saveEditors(Collection projects) {
165
	public static boolean saveEditors(Collection projects) {
155
		if (!BuildAction.isSaveAllSet()) {
166
		String saveBeforeBuildSetting = IDEWorkbenchPlugin.getDefault().getPreferenceStore().getString(IDEInternalPreferences.SAVE_ALL_BEFORE_BUILD);
156
			return;
167
		if (saveBeforeBuildSetting.equals(IDEInternalPreferences.PSPM_NEVER)) {
168
			return true;
157
		}
169
		}
170
		final boolean confirmRequired = saveBeforeBuildSetting.equals(IDEInternalPreferences.PSPM_PROMPT);
171
		List dirtyEditors = new ArrayList();
172
158
		IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
173
		IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
159
		for (int i = 0; i < windows.length; i++) {
174
		for (int i = 0; i < windows.length; i++) {
160
			IWorkbenchPage[] pages = windows[i].getPages();
175
			IWorkbenchPage[] pages = windows[i].getPages();
161
			for (int j = 0; j < pages.length; j++) {
176
			for (int j = 0; j < pages.length; j++) {
162
				IWorkbenchPage page = pages[j];
177
				IWorkbenchPage page = pages[j];
163
				if (projects == null) {
178
				IEditorPart[] editors = page.getDirtyEditors();
164
					page.saveAllEditors(false);
179
				for (int k = 0; k < editors.length; k++) {
165
				} else {
180
					IEditorPart editor = editors[k];
166
					IEditorPart[] editors = page.getDirtyEditors();
181
					if (projects == null) {
167
					for (int k = 0; k < editors.length; k++) {
182
						dirtyEditors.add(editor);
168
						IEditorPart editor = editors[k];
183
					}
184
					else {
169
						IFile inputFile = ResourceUtil.getFile(editor.getEditorInput());
185
						IFile inputFile = ResourceUtil.getFile(editor.getEditorInput());
170
						if (inputFile != null) {
186
						if (inputFile != null && projects.contains(inputFile.getProject())) {
171
							if (projects.contains(inputFile.getProject())) {
187
							dirtyEditors.add(editor);
172
								page.saveEditor(editor, false);
173
							}
174
						}
188
						}
175
					}
189
					}
176
				}
190
				}
177
			}
191
			}
178
		}
192
		}
193
194
		/* Taken from org.eclipse.ui.internal.Workbench.saveAllEditors */
195
		IShellProvider shellProvider;
196
		IRunnableContext runnableContext;
197
		IWorkbenchWindow w = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
198
		if (w == null && windows.length > 0) {
199
			w = windows[0];
200
		}
201
		if (w != null) {
202
			shellProvider = w;
203
			runnableContext = w;
204
		} else {
205
			shellProvider = new IShellProvider() {
206
				public Shell getShell() {
207
					return null;
208
				}
209
			};
210
			runnableContext = new ProgressMonitorDialog(null);
211
		}
212
		
213
		return EditorManager.saveAll(dirtyEditors, confirmRequired, false, true, runnableContext, shellProvider);
179
	}
214
	}
180
215
181
	/**
216
	/**

Return to bug 129132