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

Collapse All | Expand All

(-)search/org/eclipse/search/internal/ui/SearchMessages.properties (-1 / +8 lines)
Lines 160-166 Link Here
160
ReplaceAction.label_selected= Replace Selected...
160
ReplaceAction.label_selected= Replace Selected...
161
ReplaceAction.error.only_on_text_search= Replace is only available on text search.
161
ReplaceAction.error.only_on_text_search= Replace is only available on text search.
162
ReplaceAction.error.unable_to_perform= Replace operation can\'t be performed.
162
ReplaceAction.error.unable_to_perform= Replace operation can\'t be performed.
163
ReplaceAction.error.changed_files= The content of the following file(s) has changed. Please redo the search to ensure that all matches are correct.
163
ReplaceAction.error.changed_file= The content of the following file has changed. Please redo the search to ensure that all matches are correct.
164
ReplaceAction.error.changed_files= The content of the following files have changed. Please redo the search to ensure that all matches are correct.
165
ReplaceAction.error.opened_file= The following file is already open in an editor, but the replace operation cannot handle this editor. Please close the editor.
166
ReplaceAction.error.opened_files= The following files are already open in editors, but the replace operation cannot handle these editors. Please close the editors.
167
ReplaceAction.error.not_file= The following resource is not a file and cannot be handled. Please exclude it from the replace operation.
168
ReplaceAction.error.not_files= The following resources are not files and cannot be handled. Please exclude them from the replace operation.
164
ReplaceAction.dialog.title= Replace
169
ReplaceAction.dialog.title= Replace
165
170
166
ReplaceDialog.replace_label= Replace:
171
ReplaceDialog.replace_label= Replace:
Lines 176-178 Link Here
176
ReplaceDialog.error.reenable_auto_build_failed=Couldn\'t reactivate auto building.
181
ReplaceDialog.error.reenable_auto_build_failed=Couldn\'t reactivate auto building.
177
ReplaceDialog.error.auto_building= Couldn\'t disable auto building.
182
ReplaceDialog.error.auto_building= Couldn\'t disable auto building.
178
ReplaceDialog.error.no_matches= Couldn\'t find first match.
183
ReplaceDialog.error.no_matches= Couldn\'t find first match.
184
ReplaceDialog.error.no_file_for_marker=Current match is not associated with a file. It is not possible to open an editor.
185
ReplaceDialog.error.unable_to_open_text_editor=It is not possible to open the built-in text editor for file ''{0}''.
(-)search/org/eclipse/search/internal/ui/text/ReplaceAction.java (-3 / +73 lines)
Lines 30-37 Link Here
30
import org.eclipse.core.resources.ResourcesPlugin;
30
import org.eclipse.core.resources.ResourcesPlugin;
31
import org.eclipse.core.runtime.IStatus;
31
import org.eclipse.core.runtime.IStatus;
32
32
33
import org.eclipse.ui.IEditorPart;
34
import org.eclipse.ui.IWorkbenchPage;
33
import org.eclipse.ui.IWorkbenchSite;
35
import org.eclipse.ui.IWorkbenchSite;
34
import org.eclipse.ui.model.WorkbenchLabelProvider;
36
import org.eclipse.ui.model.WorkbenchLabelProvider;
37
import org.eclipse.ui.part.FileEditorInput;
38
import org.eclipse.ui.texteditor.ITextEditor;
35
39
36
import org.eclipse.search.internal.ui.Search;
40
import org.eclipse.search.internal.ui.Search;
37
import org.eclipse.search.internal.ui.SearchManager;
41
import org.eclipse.search.internal.ui.SearchManager;
Lines 78-93 Link Here
78
	
82
	
79
	private boolean validateResources() {
83
	private boolean validateResources() {
80
		List modifiedFiles= new ArrayList();
84
		List modifiedFiles= new ArrayList();
85
		List openedFilesInNonTextEditor= new ArrayList();
86
		List notFiles= new ArrayList();
87
		IWorkbenchPage activePage =  fSite.getWorkbenchWindow().getActivePage();
88
81
		for (Iterator iter = fElements.iterator(); iter.hasNext();) {
89
		for (Iterator iter = fElements.iterator(); iter.hasNext();) {
82
			SearchResultViewEntry entry= (SearchResultViewEntry) iter.next();
90
			SearchResultViewEntry entry= (SearchResultViewEntry) iter.next();
83
			IResource resource= entry.getResource();
91
			IResource resource= entry.getResource();
84
			if (resource instanceof IFile && ((IFile)resource).getModificationStamp() != entry.getModificationStamp())
92
			if (resource instanceof IFile) {
85
				modifiedFiles.add(resource);
93
				IFile file= (IFile)resource;
94
				if (file.getModificationStamp() != entry.getModificationStamp() || !file.isSynchronized(IResource.DEPTH_ZERO)) {
95
					modifiedFiles.add(resource);
96
				} else if (activePage != null) {
97
					IEditorPart part= activePage.findEditor(new FileEditorInput(file));
98
					if (part != null && !(part instanceof ITextEditor))
99
						openedFilesInNonTextEditor.add(file);
100
				}
101
			} else {
102
				if (resource != null)
103
					notFiles.add(resource);
104
			}
86
		}
105
		}
87
		if (!modifiedFiles.isEmpty()) {
106
		if (!modifiedFiles.isEmpty()) {
88
			showModifiedFileDialog(modifiedFiles);
107
			showModifiedFileDialog(modifiedFiles);
89
			return false;
108
			return false;
90
		}
109
		}
110
		if (!openedFilesInNonTextEditor.isEmpty()) {
111
			showOpenedFileDialog(openedFilesInNonTextEditor);
112
			return false;
113
		}
114
		if (!notFiles.isEmpty()) {
115
			showNotFilesDialog(openedFilesInNonTextEditor);
116
			return false;
117
		}
91
		IFile[] readOnlyFiles= getReadOnlyFiles();
118
		IFile[] readOnlyFiles= getReadOnlyFiles();
92
		if (readOnlyFiles.length == 0)
119
		if (readOnlyFiles.length == 0)
93
			return true;
120
			return true;
Lines 113-120 Link Here
113
	}
140
	}
114
141
115
	private void showModifiedFileDialog(List modifiedFiles) {
142
	private void showModifiedFileDialog(List modifiedFiles) {
143
		String message= (modifiedFiles.size() == 1
144
			? SearchMessages.getString("ReplaceAction.error.changed_file")  //$NON-NLS-1$
145
			: SearchMessages.getString("ReplaceAction.error.changed_files"));  //$NON-NLS-1$
116
		ListDialog dialog= new ListDialog(fSite.getShell(), modifiedFiles, getDialogTitle(), 
146
		ListDialog dialog= new ListDialog(fSite.getShell(), modifiedFiles, getDialogTitle(), 
117
			SearchMessages.getString("ReplaceAction.error.changed_files"),  //$NON-NLS-1$
147
			message,
118
			new IStructuredContentProvider() {
148
			new IStructuredContentProvider() {
119
				public Object[] getElements(Object inputElement) {
149
				public Object[] getElements(Object inputElement) {
120
					return ((List)inputElement).toArray();
150
					return ((List)inputElement).toArray();
Lines 151-154 Link Here
151
	private String getDialogTitle() {
181
	private String getDialogTitle() {
152
		return SearchMessages.getString("ReplaceAction.dialog.title"); //$NON-NLS-1$
182
		return SearchMessages.getString("ReplaceAction.dialog.title"); //$NON-NLS-1$
153
	}
183
	}
184
	
185
	private void showOpenedFileDialog(List openedFilesInNonTextEditor) {
186
		String message= (openedFilesInNonTextEditor.size() == 1
187
			? SearchMessages.getString("ReplaceAction.error.opened_file")  //$NON-NLS-1$
188
			: SearchMessages.getString("ReplaceAction.error.opened_files"));  //$NON-NLS-1$
189
		ListDialog dialog= new ListDialog(fSite.getShell(), openedFilesInNonTextEditor, getDialogTitle(), 
190
			message,
191
			new IStructuredContentProvider() {
192
				public Object[] getElements(Object inputElement) {
193
					return ((List)inputElement).toArray();
194
				}
195
				public void dispose() {
196
				}
197
				public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
198
				}
199
			}, 
200
			new WorkbenchLabelProvider());
201
		dialog.setCreateCancelButton(false);
202
		dialog.open();
203
	}
204
	
205
	private void showNotFilesDialog(List notFiles) {
206
		String message= (notFiles.size() == 1
207
			? SearchMessages.getString("ReplaceAction.error.not_file")  //$NON-NLS-1$
208
			: SearchMessages.getString("ReplaceAction.error.not_files"));  //$NON-NLS-1$
209
		ListDialog dialog= new ListDialog(fSite.getShell(), notFiles, getDialogTitle(), 
210
			message,
211
			new IStructuredContentProvider() {
212
				public Object[] getElements(Object inputElement) {
213
					return ((List)inputElement).toArray();
214
				}
215
				public void dispose() {
216
				}
217
				public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
218
				}
219
			}, 
220
			new WorkbenchLabelProvider());
221
		dialog.setCreateCancelButton(false);
222
		dialog.open();
223
	}		
154
}
224
}
(-)search/org/eclipse/search/internal/ui/text/ReplaceDialog.java (-5 / +63 lines)
Lines 10-18 Link Here
10
 ******************************************************************************/
10
 ******************************************************************************/
11
package org.eclipse.search.internal.ui.text;
11
package org.eclipse.search.internal.ui.text;
12
12
13
import java.text.MessageFormat;
13
import java.util.ArrayList;
14
import java.util.ArrayList;
14
import java.util.List;
15
import java.util.List;
15
16
17
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IMarker;
18
import org.eclipse.core.resources.IMarker;
17
import org.eclipse.core.resources.IWorkspace;
19
import org.eclipse.core.resources.IWorkspace;
18
import org.eclipse.core.resources.IWorkspaceDescription;
20
import org.eclipse.core.resources.IWorkspaceDescription;
Lines 41-49 Link Here
41
import org.eclipse.jface.text.Position;
43
import org.eclipse.jface.text.Position;
42
import org.eclipse.jface.util.Assert;
44
import org.eclipse.jface.util.Assert;
43
45
46
import org.eclipse.ui.IEditorDescriptor;
44
import org.eclipse.ui.IEditorInput;
47
import org.eclipse.ui.IEditorInput;
48
import org.eclipse.ui.IEditorPart;
49
import org.eclipse.ui.IEditorRegistry;
45
import org.eclipse.ui.IWorkbenchPage;
50
import org.eclipse.ui.IWorkbenchPage;
46
import org.eclipse.ui.IWorkbenchWindow;
51
import org.eclipse.ui.IWorkbenchWindow;
52
import org.eclipse.ui.PartInitException;
47
import org.eclipse.ui.actions.GlobalBuildAction;
53
import org.eclipse.ui.actions.GlobalBuildAction;
48
import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
54
import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
49
import org.eclipse.ui.texteditor.IDocumentProvider;
55
import org.eclipse.ui.texteditor.IDocumentProvider;
Lines 91-96 Link Here
91
	private int fMarkerIndex;
97
	private int fMarkerIndex;
92
	private IMarker fCurrentMatch;
98
	private IMarker fCurrentMatch;
93
	
99
	
100
	private static class MarkerNotPresentableException extends Exception {
101
		private IFile fFile;
102
		MarkerNotPresentableException(IFile file) {
103
			fFile= file;
104
		}
105
		public IFile getFile() {
106
			return fFile;
107
		}
108
	}
109
	
94
	protected ReplaceDialog(Shell parentShell, List elements, IWorkbenchWindow window, String searchPattern) {
110
	protected ReplaceDialog(Shell parentShell, List elements, IWorkbenchWindow window, String searchPattern) {
95
		super(parentShell);
111
		super(parentShell);
96
		Assert.isNotNull(elements);
112
		Assert.isNotNull(elements);
Lines 126-131 Link Here
126
		} catch (CoreException e) {
142
		} catch (CoreException e) {
127
			ExceptionHandler.handle(e, getShell(), getDialogTitle(), SearchMessages.getString("ReplaceDialog.error.no_matches")); //$NON-NLS-1$
143
			ExceptionHandler.handle(e, getShell(), getDialogTitle(), SearchMessages.getString("ReplaceDialog.error.no_matches")); //$NON-NLS-1$
128
			fFatalError= true;
144
			fFatalError= true;
145
		} catch (MarkerNotPresentableException e) {
146
			handleMarkerNotPresentableException(e);
147
			fFatalError= true;
129
		}
148
		}
130
		return super.open();
149
		return super.open();
131
	}
150
	}
Lines 217-222 Link Here
217
		} catch (BadLocationException e) {
236
		} catch (BadLocationException e) {
218
			MessageDialog.openError(getShell(), getDialogTitle(), SearchMessages.getString("ReplaceDialog.error.different_content")); //$NON-NLS-1$
237
			MessageDialog.openError(getShell(), getDialogTitle(), SearchMessages.getString("ReplaceDialog.error.different_content")); //$NON-NLS-1$
219
			fFatalError= true;
238
			fFatalError= true;
239
		} catch (MarkerNotPresentableException e) {
240
			handleMarkerNotPresentableException(e);
241
			fFatalError= true;
220
		}
242
		}
221
		updateButtons();
243
		updateButtons();
222
		super.buttonPressed(buttonId);
244
		super.buttonPressed(buttonId);
Lines 238-244 Link Here
238
		return fElementIndex < fElements.size();
260
		return fElementIndex < fElements.size();
239
	}
261
	}
240
	
262
	
241
	private IMarker getNextMatch(boolean save) throws CoreException {
263
	private IMarker getNextMatch(boolean save) throws CoreException, MarkerNotPresentableException {
242
		if (fCurrentMarkers == null) {
264
		if (fCurrentMarkers == null) {
243
			if (fElementIndex >= fElements.size())
265
			if (fElementIndex >= fElements.size())
244
				return null;
266
				return null;
Lines 251-257 Link Here
251
		if (fEditor == null) {
273
		if (fEditor == null) {
252
			IWorkbenchPage activePage = fWindow.getActivePage();
274
			IWorkbenchPage activePage = fWindow.getActivePage();
253
			int openEditors= activePage.getEditorReferences().length;
275
			int openEditors= activePage.getEditorReferences().length;
254
			fEditor= (ITextEditor)activePage.openEditor(result, false);
276
			
277
			fEditor= openFile(result, activePage);
278
			fEditor.gotoMarker(result);
255
			IDocumentProvider provider= fEditor.getDocumentProvider();
279
			IDocumentProvider provider= fEditor.getDocumentProvider();
256
			IEditorInput input = fEditor.getEditorInput();
280
			IEditorInput input = fEditor.getEditorInput();
257
			fDocument= provider.getDocument(input);
281
			fDocument= provider.getDocument(input);
Lines 268-276 Link Here
268
		return result;
292
		return result;
269
	}
293
	}
270
294
295
	private ITextEditor openFile(IMarker marker, IWorkbenchPage activePage) throws MarkerNotPresentableException, PartInitException {
296
		IFile markerFile= marker.getResource() instanceof IFile ? (IFile)marker.getResource() : null;
297
		if (markerFile == null)
298
			throw new MarkerNotPresentableException(null);
299
			
300
		String currentEditorId= null;
301
		IEditorRegistry editorRegistry= SearchPlugin.getDefault().getWorkbench().getEditorRegistry();
302
		IEditorDescriptor desc= editorRegistry.getDefaultEditor(markerFile);
303
		if (desc != null)
304
			currentEditorId= desc.getId();
305
		try {
306
			IEditorPart result= activePage.openEditor(markerFile, "org.eclipse.ui.DefaultTextEditor", false); //$NON-NLS-1$
307
			if (!(result instanceof ITextEditor))
308
				throw new MarkerNotPresentableException(markerFile);
309
			return (ITextEditor)result;
310
		} finally {
311
			if (currentEditorId != null)
312
				editorRegistry.setDefaultEditor(markerFile, currentEditorId);
313
		}
314
	}
315
271
	private void saveEditor(boolean save) throws CoreException {
316
	private void saveEditor(boolean save) throws CoreException {
272
		if (fEditor != null)
317
		if (fEditor == null)
273
			save= save && fEditor.isDirty();
318
			return;
319
			
320
		save= save && fEditor.isDirty();
274
		if (save) {
321
		if (save) {
275
			IDocumentProvider provider= fEditor.getDocumentProvider();
322
			IDocumentProvider provider= fEditor.getDocumentProvider();
276
			IEditorInput input = fEditor.getEditorInput();
323
			IEditorInput input = fEditor.getEditorInput();
Lines 282-288 Link Here
282
				provider.changed(input);
329
				provider.changed(input);
283
			}
330
			}
284
		}
331
		}
285
		if (fEditor != null && fCloseEditor && save)
332
		if (fCloseEditor && !fEditor.isDirty())
286
			fEditor.close(false);
333
			fEditor.close(false);
287
		fEditor= null;
334
		fEditor= null;
288
		fDocument= null;
335
		fDocument= null;
Lines 321-325 Link Here
321
	
368
	
322
	private String getDialogTitle() {
369
	private String getDialogTitle() {
323
		return SearchMessages.getString("ReplaceDialog.dialog.title"); //$NON-NLS-1$
370
		return SearchMessages.getString("ReplaceDialog.dialog.title"); //$NON-NLS-1$
371
	}
372
	
373
	private void handleMarkerNotPresentableException(MarkerNotPresentableException e) {
374
		IFile file= e.getFile();
375
		String message;
376
		if (file == null) {
377
			message= SearchMessages.getString("ReplaceDialog.error.no_file_for_marker"); //$NON-NLS-1$
378
		} else {
379
			message= SearchMessages.getFormattedString("ReplaceDialog.error.unable_to_open_text_editor", file.getName()); //$NON-NLS-1$
380
		}
381
		MessageDialog.openError(getParentShell(), getDialogTitle(), message);
324
	}
382
	}
325
}
383
}

Return to bug 20706