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 |
} |