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 98707 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (-1 / +1 lines)
Lines 195-201 Link Here
195
         <action
195
         <action
196
               label="%CompareWithPatchAction.label"
196
               label="%CompareWithPatchAction.label"
197
               tooltip="%CompareWithPatchAction.tooltip"
197
               tooltip="%CompareWithPatchAction.tooltip"
198
               class="org.eclipse.compare.internal.patch.CompareWithPatchAction"
198
               class="org.eclipse.compare.CompareWithPatchAction"
199
               menubarPath="team.main/group1"
199
               menubarPath="team.main/group1"
200
               enablesFor="1"
200
               enablesFor="1"
201
               id="compareWithPatch">
201
               id="compareWithPatch">
(-)compare/org/eclipse/compare/internal/patch/CompareWithPatchAction.java (-154 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.compare.internal.patch;
12
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.Arrays;
15
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.SelectionAdapter;
18
import org.eclipse.swt.events.SelectionEvent;
19
import org.eclipse.swt.graphics.Image;
20
import org.eclipse.swt.widgets.Button;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
23
import org.eclipse.swt.widgets.Shell;
24
25
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
26
import org.eclipse.jface.operation.IRunnableWithProgress;
27
import org.eclipse.jface.util.Assert;
28
import org.eclipse.jface.viewers.*;
29
import org.eclipse.jface.window.Window;
30
import org.eclipse.jface.wizard.IWizard;
31
import org.eclipse.jface.wizard.WizardDialog;
32
33
import org.eclipse.core.resources.*;
34
import org.eclipse.core.runtime.*;
35
36
import org.eclipse.ui.IEditorPart;
37
38
import org.eclipse.compare.internal.*;
39
40
41
public class CompareWithPatchAction extends BaseCompareAction {
42
43
	static class PatchWizardDialog extends WizardDialog {
44
	
45
		PatchWizardDialog(Shell parent, IWizard wizard) {
46
			super(parent, wizard);
47
			
48
			setShellStyle(getShellStyle() | SWT.RESIZE);
49
			setMinimumPageSize(700, 500);
50
		}
51
	}
52
	
53
	protected boolean isEnabled(ISelection selection) {
54
		return Utilities.getResources(selection).length == 1;
55
	}
56
		
57
	/* (non-Javadoc)
58
	 * @see org.eclipse.compare.internal.BaseCompareAction#run(org.eclipse.jface.viewers.ISelection)
59
	 */
60
	protected void run(ISelection selection) {
61
		PatchWizard wizard= new PatchWizard(selection);
62
		
63
		if (areAllEditorsSaved()) {
64
			PatchWizardDialog dialog= new PatchWizardDialog(CompareUIPlugin.getShell(), wizard);
65
			dialog.open();
66
		}
67
	}
68
69
	private boolean areAllEditorsSaved(){
70
		if (CompareUIPlugin.getDirtyEditors().length == 0)
71
			return true;
72
		if (! saveAllDirtyEditors())
73
			return false;
74
		Shell shell= CompareUIPlugin.getShell();
75
		try {
76
			// Save isn't cancelable.
77
			IWorkspace workspace= ResourcesPlugin.getWorkspace();
78
			IWorkspaceDescription description= workspace.getDescription();
79
			boolean autoBuild= description.isAutoBuilding();
80
			description.setAutoBuilding(false);
81
			workspace.setDescription(description);
82
			try {
83
				new ProgressMonitorDialog(shell).run(false, false, createRunnable());
84
			} finally {
85
				description.setAutoBuilding(autoBuild);
86
				workspace.setDescription(description);
87
			}
88
			return true;
89
		} catch (InvocationTargetException e) {
90
			ExceptionHandler.handle(e, shell, PatchMessages.PatchAction_ExceptionTitle, PatchMessages.PatchAction_Exception);  
91
			return false;
92
		} catch (CoreException e) {
93
			ExceptionHandler.handle(e, shell, PatchMessages.PatchAction_ExceptionTitle, PatchMessages.PatchAction_Exception);  
94
			return false;			
95
		} catch (InterruptedException e) {
96
			Assert.isTrue(false); // Can't happen. Operation isn't cancelable.
97
			return false;
98
		}
99
	}
100
101
	private IRunnableWithProgress createRunnable() {
102
		return new IRunnableWithProgress() {
103
			public void run(IProgressMonitor pm) {
104
				IEditorPart[] editorsToSave= CompareUIPlugin.getDirtyEditors();
105
				pm.beginTask(PatchMessages.PatchAction_SavingDirtyEditorsTask, editorsToSave.length); 
106
				for (int i= 0; i < editorsToSave.length; i++) {
107
					editorsToSave[i].doSave(new SubProgressMonitor(pm, 1));
108
					pm.worked(1);
109
				}
110
				pm.done();
111
			}
112
		};
113
	}
114
115
	private boolean saveAllDirtyEditors() {
116
		if (ComparePreferencePage.getSaveAllEditors()) //must save everything
117
			return true;
118
		ListDialog dialog= new ListDialog(CompareUIPlugin.getShell()) {
119
			protected Control createDialogArea(Composite parent) {
120
				Composite result= (Composite) super.createDialogArea(parent);
121
				final Button check= new Button(result, SWT.CHECK);
122
				check.setText(PatchMessages.PatchAction_AlwaysSaveQuestion); 
123
				check.setSelection(ComparePreferencePage.getSaveAllEditors());
124
				check.addSelectionListener(
125
					new SelectionAdapter() {
126
						public void widgetSelected(SelectionEvent e) {
127
							ComparePreferencePage.setSaveAllEditors(check.getSelection());
128
						}
129
					}
130
				);
131
				applyDialogFont(result);
132
				return result;
133
			}
134
		};
135
		dialog.setTitle(PatchMessages.PatchAction_SaveAllQuestion); 
136
		dialog.setAddCancelButton(true);
137
		dialog.setLabelProvider(createDialogLabelProvider());
138
		dialog.setMessage(PatchMessages.PatchAction_SaveAllDescription); 
139
		dialog.setContentProvider(new ListContentProvider());
140
		dialog.setInput(Arrays.asList(CompareUIPlugin.getDirtyEditors()));
141
		return dialog.open() == Window.OK;
142
	}
143
144
	private ILabelProvider createDialogLabelProvider() {
145
		return new LabelProvider() {
146
			public Image getImage(Object element) {
147
				return ((IEditorPart) element).getTitleImage();
148
			}
149
			public String getText(Object element) {
150
				return ((IEditorPart) element).getTitle();
151
			}
152
		};
153
	}
154
}
(-)compare/org/eclipse/compare/internal/patch/InputPatchPage.java (-22 / +53 lines)
Lines 10-39 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.compare.internal.patch;
11
package org.eclipse.compare.internal.patch;
12
12
13
import java.io.*;
13
import java.io.BufferedReader;
14
import java.io.File;
15
import java.io.FileNotFoundException;
16
import java.io.FileReader;
17
import java.io.IOException;
18
import java.io.Reader;
19
import java.io.StringReader;
14
import java.text.MessageFormat;
20
import java.text.MessageFormat;
15
21
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.dnd.*;
18
import org.eclipse.swt.events.*;
19
import org.eclipse.swt.layout.*;
20
import org.eclipse.swt.widgets.*;
21
22
import org.eclipse.jface.dialogs.*;
23
import org.eclipse.jface.dialogs.Dialog;
24
import org.eclipse.jface.viewers.*;
25
import org.eclipse.jface.wizard.*;
26
27
import org.eclipse.ui.PlatformUI;
28
import org.eclipse.ui.model.*;
29
30
import org.eclipse.compare.internal.ICompareContextIds;
22
import org.eclipse.compare.internal.ICompareContextIds;
31
import org.eclipse.compare.internal.Utilities;
23
import org.eclipse.compare.internal.Utilities;
32
import org.eclipse.core.resources.*;
24
import org.eclipse.core.resources.IFile;
33
import org.eclipse.core.runtime.*;
25
import org.eclipse.core.resources.IResource;
26
import org.eclipse.core.resources.IWorkspace;
27
import org.eclipse.core.resources.IWorkspaceRoot;
28
import org.eclipse.core.runtime.IPath;
29
import org.eclipse.core.runtime.Path;
30
import org.eclipse.jface.dialogs.Dialog;
31
import org.eclipse.jface.dialogs.IDialogSettings;
32
import org.eclipse.jface.dialogs.MessageDialog;
33
import org.eclipse.jface.viewers.CheckboxTreeViewer;
34
import org.eclipse.jface.viewers.ISelection;
35
import org.eclipse.jface.viewers.ISelectionChangedListener;
36
import org.eclipse.jface.viewers.SelectionChangedEvent;
37
import org.eclipse.jface.viewers.StructuredSelection;
38
import org.eclipse.jface.wizard.IWizardPage;
39
import org.eclipse.jface.wizard.WizardPage;
40
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.dnd.Clipboard;
42
import org.eclipse.swt.dnd.TextTransfer;
43
import org.eclipse.swt.events.ModifyEvent;
44
import org.eclipse.swt.events.ModifyListener;
45
import org.eclipse.swt.events.SelectionAdapter;
46
import org.eclipse.swt.events.SelectionEvent;
47
import org.eclipse.swt.layout.GridData;
48
import org.eclipse.swt.layout.GridLayout;
49
import org.eclipse.swt.widgets.Button;
50
import org.eclipse.swt.widgets.Combo;
51
import org.eclipse.swt.widgets.Composite;
52
import org.eclipse.swt.widgets.Control;
53
import org.eclipse.swt.widgets.FileDialog;
54
import org.eclipse.swt.widgets.Group;
55
import org.eclipse.swt.widgets.Label;
56
import org.eclipse.swt.widgets.Text;
57
import org.eclipse.swt.widgets.Tree;
58
import org.eclipse.ui.PlatformUI;
59
import org.eclipse.ui.model.WorkbenchContentProvider;
60
import org.eclipse.ui.model.WorkbenchLabelProvider;
61
import org.eclipse.ui.model.WorkbenchViewerSorter;
34
62
35
63
36
/* package */ class InputPatchPage extends WizardPage {
64
/* package */public class InputPatchPage extends WizardPage {
37
65
38
	// constants
66
	// constants
39
	protected static final int SIZING_TEXT_FIELD_WIDTH= 250;
67
	protected static final int SIZING_TEXT_FIELD_WIDTH= 250;
Lines 41-48 Link Here
41
	
69
	
42
	// dialog store id constants
70
	// dialog store id constants
43
	private final static String PAGE_NAME= "PatchWizardPage1"; //$NON-NLS-1$
71
	private final static String PAGE_NAME= "PatchWizardPage1"; //$NON-NLS-1$
44
	private final static String STORE_PATCH_FILES_ID= PAGE_NAME + ".PATCH_FILES";	//$NON-NLS-1$
72
	public final static String STORE_PATCH_FILES_ID= PAGE_NAME + ".PATCH_FILES";	//$NON-NLS-1$
45
	private final static String STORE_USE_CLIPBOARD_ID= PAGE_NAME + ".USE_CLIPBOARD";	//$NON-NLS-1$
73
	public final static String STORE_USE_CLIPBOARD_ID= PAGE_NAME + ".USE_CLIPBOARD";	//$NON-NLS-1$
46
	
74
	
47
	static final char SEPARATOR = System.getProperty ("file.separator").charAt (0); //$NON-NLS-1$
75
	static final char SEPARATOR = System.getProperty ("file.separator").charAt (0); //$NON-NLS-1$
48
	
76
	
Lines 269-276 Link Here
269
		
297
		
270
		PatchWizard pw= (PatchWizard) getWizard();
298
		PatchWizard pw= (PatchWizard) getWizard();
271
		IResource target= pw.getTarget();
299
		IResource target= pw.getTarget();
272
		IWorkspace workspace= target.getWorkspace();
300
		IWorkspaceRoot root = null;
273
		IWorkspaceRoot root= workspace.getRoot();
301
		if (target != null) {
302
			IWorkspace workspace= target.getWorkspace();
303
			root= workspace.getRoot();
304
		}
274
		
305
		
275
		Tree tree= new Tree(parent, SWT.BORDER);
306
		Tree tree= new Tree(parent, SWT.BORDER);
276
		GridData gd= new GridData(GridData.FILL_BOTH);
307
		GridData gd= new GridData(GridData.FILL_BOTH);
(-)compare/org/eclipse/compare/internal/patch/PatchWizard.java (-3 / +3 lines)
Lines 25-34 Link Here
25
import org.eclipse.compare.internal.*;
25
import org.eclipse.compare.internal.*;
26
26
27
27
28
/* package */ class PatchWizard extends Wizard {
28
/* package */ public class PatchWizard extends Wizard {
29
	
29
	
30
	// dialog store id constants
30
	// dialog store id constants
31
	private final static String DIALOG_SETTINGS_KEY= "PatchWizard"; //$NON-NLS-1$
31
	public final static String DIALOG_SETTINGS_KEY= "PatchWizard"; //$NON-NLS-1$
32
32
33
	private boolean fHasNewDialogSettings;
33
	private boolean fHasNewDialogSettings;
34
	
34
	
Lines 41-47 Link Here
41
	/*
41
	/*
42
	 * Creates a wizard for applying a patch file to the workspace.
42
	 * Creates a wizard for applying a patch file to the workspace.
43
	 */
43
	 */
44
	/* package */ PatchWizard(ISelection selection) {
44
	/* package */ public PatchWizard(ISelection selection) {
45
		
45
		
46
		setDefaultPageImageDescriptor(CompareUIPlugin.getImageDescriptor("wizban/applypatch_wizban.gif"));	//$NON-NLS-1$
46
		setDefaultPageImageDescriptor(CompareUIPlugin.getImageDescriptor("wizban/applypatch_wizban.gif"));	//$NON-NLS-1$
47
		setWindowTitle(PatchMessages.PatchWizard_title); 
47
		setWindowTitle(PatchMessages.PatchWizard_title); 
(-)compare/org/eclipse/compare/CompareWithPatchAction.java (+162 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.compare;
12
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.Arrays;
15
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.SelectionAdapter;
18
import org.eclipse.swt.events.SelectionEvent;
19
import org.eclipse.swt.graphics.Image;
20
import org.eclipse.swt.widgets.Button;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
23
import org.eclipse.swt.widgets.Shell;
24
25
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
26
import org.eclipse.jface.operation.IRunnableWithProgress;
27
import org.eclipse.jface.util.Assert;
28
import org.eclipse.jface.viewers.*;
29
import org.eclipse.jface.window.Window;
30
import org.eclipse.jface.wizard.IWizard;
31
import org.eclipse.jface.wizard.WizardDialog;
32
33
import org.eclipse.core.resources.*;
34
import org.eclipse.core.runtime.*;
35
36
import org.eclipse.ui.IEditorPart;
37
38
import org.eclipse.compare.internal.*;
39
import org.eclipse.compare.internal.patch.PatchMessages;
40
import org.eclipse.compare.internal.patch.PatchWizard;
41
42
43
public class CompareWithPatchAction extends BaseCompareAction {
44
45
	private PatchDialogSettings dialogSettings; //$NON-NLS-1$
46
	
47
	static class PatchWizardDialog extends WizardDialog {
48
	
49
		PatchWizardDialog(Shell parent, IWizard wizard) {
50
			super(parent, wizard);
51
			
52
			setShellStyle(getShellStyle() | SWT.RESIZE);
53
			setMinimumPageSize(700, 500);
54
		}
55
	}
56
	
57
	protected boolean isEnabled(ISelection selection) {
58
		return Utilities.getResources(selection).length == 1;
59
	}
60
		
61
	/* (non-Javadoc)
62
	 * @see org.eclipse.compare.internal.BaseCompareAction#run(org.eclipse.jface.viewers.ISelection)
63
	 */
64
	protected void run(ISelection selection) {
65
		PatchWizard wizard= new PatchWizard(selection);
66
		wizard.setDialogSettings(dialogSettings);
67
		if (areAllEditorsSaved()) {
68
			PatchWizardDialog dialog= new PatchWizardDialog(CompareUIPlugin.getShell(), wizard);
69
			dialog.open();
70
		}
71
	}
72
73
	private boolean areAllEditorsSaved(){
74
		if (CompareUIPlugin.getDirtyEditors().length == 0)
75
			return true;
76
		if (! saveAllDirtyEditors())
77
			return false;
78
		Shell shell= CompareUIPlugin.getShell();
79
		try {
80
			// Save isn't cancelable.
81
			IWorkspace workspace= ResourcesPlugin.getWorkspace();
82
			IWorkspaceDescription description= workspace.getDescription();
83
			boolean autoBuild= description.isAutoBuilding();
84
			description.setAutoBuilding(false);
85
			workspace.setDescription(description);
86
			try {
87
				new ProgressMonitorDialog(shell).run(false, false, createRunnable());
88
			} finally {
89
				description.setAutoBuilding(autoBuild);
90
				workspace.setDescription(description);
91
			}
92
			return true;
93
		} catch (InvocationTargetException e) {
94
			ExceptionHandler.handle(e, shell, PatchMessages.PatchAction_ExceptionTitle, PatchMessages.PatchAction_Exception);  
95
			return false;
96
		} catch (CoreException e) {
97
			ExceptionHandler.handle(e, shell, PatchMessages.PatchAction_ExceptionTitle, PatchMessages.PatchAction_Exception);  
98
			return false;			
99
		} catch (InterruptedException e) {
100
			Assert.isTrue(false); // Can't happen. Operation isn't cancelable.
101
			return false;
102
		}
103
	}
104
105
	private IRunnableWithProgress createRunnable() {
106
		return new IRunnableWithProgress() {
107
			public void run(IProgressMonitor pm) {
108
				IEditorPart[] editorsToSave= CompareUIPlugin.getDirtyEditors();
109
				pm.beginTask(PatchMessages.PatchAction_SavingDirtyEditorsTask, editorsToSave.length); 
110
				for (int i= 0; i < editorsToSave.length; i++) {
111
					editorsToSave[i].doSave(new SubProgressMonitor(pm, 1));
112
					pm.worked(1);
113
				}
114
				pm.done();
115
			}
116
		};
117
	}
118
119
	private boolean saveAllDirtyEditors() {
120
		if (ComparePreferencePage.getSaveAllEditors()) //must save everything
121
			return true;
122
		ListDialog dialog= new ListDialog(CompareUIPlugin.getShell()) {
123
			protected Control createDialogArea(Composite parent) {
124
				Composite result= (Composite) super.createDialogArea(parent);
125
				final Button check= new Button(result, SWT.CHECK);
126
				check.setText(PatchMessages.PatchAction_AlwaysSaveQuestion); 
127
				check.setSelection(ComparePreferencePage.getSaveAllEditors());
128
				check.addSelectionListener(
129
					new SelectionAdapter() {
130
						public void widgetSelected(SelectionEvent e) {
131
							ComparePreferencePage.setSaveAllEditors(check.getSelection());
132
						}
133
					}
134
				);
135
				applyDialogFont(result);
136
				return result;
137
			}
138
		};
139
		dialog.setTitle(PatchMessages.PatchAction_SaveAllQuestion); 
140
		dialog.setAddCancelButton(true);
141
		dialog.setLabelProvider(createDialogLabelProvider());
142
		dialog.setMessage(PatchMessages.PatchAction_SaveAllDescription); 
143
		dialog.setContentProvider(new ListContentProvider());
144
		dialog.setInput(Arrays.asList(CompareUIPlugin.getDirtyEditors()));
145
		return dialog.open() == Window.OK;
146
	}
147
148
	private ILabelProvider createDialogLabelProvider() {
149
		return new LabelProvider() {
150
			public Image getImage(Object element) {
151
				return ((IEditorPart) element).getTitleImage();
152
			}
153
			public String getText(Object element) {
154
				return ((IEditorPart) element).getTitle();
155
			}
156
		};
157
	}
158
159
	public void setDialogSettings(PatchDialogSettings config) {
160
		this.dialogSettings = config;
161
	}
162
}
(-)compare/org/eclipse/compare/PatchDialogSettings.java (+46 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.compare;
12
13
import org.eclipse.compare.internal.patch.InputPatchPage;
14
import org.eclipse.compare.internal.patch.PatchWizard;
15
import org.eclipse.jface.dialogs.DialogSettings;
16
17
/**
18
 * <code>CompareWithPatchConfiguration</code> represents a UI configuration
19
 * for the <code>CompareWithPatchAction</code> wizard. 
20
 * 
21
 *
22
 */
23
public class PatchDialogSettings extends DialogSettings {
24
25
	public PatchDialogSettings(String sectionName) {
26
		super(sectionName);
27
	}
28
29
	public PatchDialogSettings() {
30
		super(PatchWizard.DIALOG_SETTINGS_KEY);
31
	}
32
33
	public String getPatchPath() {
34
		return this.get(InputPatchPage.STORE_PATCH_FILES_ID);
35
	}
36
	public void setPatchPath(String patchPath) {
37
		this.put(InputPatchPage.STORE_PATCH_FILES_ID, patchPath);
38
	}
39
40
	public boolean isUseClipboard() {
41
		return this.getBoolean(InputPatchPage.STORE_USE_CLIPBOARD_ID);
42
	}
43
	public void setUseClipboard(boolean useClipboard) {
44
		this.put(InputPatchPage.STORE_USE_CLIPBOARD_ID, useClipboard);
45
	}
46
}

Return to bug 98707