Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDani Megert2002-06-21 10:08:12 +0000
committerDani Megert2002-06-21 10:08:12 +0000
commitab9220f8a94aed35d5dab363785360ce27dbb294 (patch)
tree5d9e196c2dd37af9b7d246c7dfa0e798ebe82783 /org.eclipse.search
parent647a27d35c34fda06db84e7fe59d8a4b149d73d6 (diff)
downloadeclipse.platform.text-ab9220f8a94aed35d5dab363785360ce27dbb294.tar.gz
eclipse.platform.text-ab9220f8a94aed35d5dab363785360ce27dbb294.tar.xz
eclipse.platform.text-ab9220f8a94aed35d5dab363785360ce27dbb294.zip
[20706] released patch provided by Dirk Baeumerv20020621
Diffstat (limited to 'org.eclipse.search')
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.properties9
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction.java76
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceDialog.java68
3 files changed, 144 insertions, 9 deletions
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.properties b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.properties
index 38883bce22b..adf5380166e 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.properties
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.properties
@@ -160,7 +160,12 @@ ReplaceAction.label_all= Replace...
ReplaceAction.label_selected= Replace Selected...
ReplaceAction.error.only_on_text_search= Replace is only available on text search.
ReplaceAction.error.unable_to_perform= Replace operation can\'t be performed.
-ReplaceAction.error.changed_files= The content of the following file(s) has changed. Please redo the search to ensure that all matches are correct.
+ReplaceAction.error.changed_file= The content of the following file has changed. Please redo the search to ensure that all matches are correct.
+ReplaceAction.error.changed_files= The content of the following files have changed. Please redo the search to ensure that all matches are correct.
+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.
+ReplaceAction.error.opened_files= The following files are already open in editors, but the replace operation cannot handle these editors. Please close the editors.
+ReplaceAction.error.not_file= The following resource is not a file and cannot be handled. Please exclude it from the replace operation.
+ReplaceAction.error.not_files= The following resources are not files and cannot be handled. Please exclude them from the replace operation.
ReplaceAction.dialog.title= Replace
ReplaceDialog.replace_label= Replace:
@@ -176,3 +181,5 @@ ReplaceDialog.error.different_content= File content differs from search result.
ReplaceDialog.error.reenable_auto_build_failed=Couldn\'t reactivate auto building.
ReplaceDialog.error.auto_building= Couldn\'t disable auto building.
ReplaceDialog.error.no_matches= Couldn\'t find first match.
+ReplaceDialog.error.no_file_for_marker=Current match is not associated with a file. It is not possible to open an editor.
+ReplaceDialog.error.unable_to_open_text_editor=It is not possible to open the built-in text editor for file ''{0}''. \ No newline at end of file
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction.java
index 30965abc61b..022fa74f2ae 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction.java
@@ -30,8 +30,12 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.search.internal.ui.Search;
import org.eclipse.search.internal.ui.SearchManager;
@@ -78,16 +82,39 @@ import org.eclipse.search.internal.ui.util.ListDialog;
private boolean validateResources() {
List modifiedFiles= new ArrayList();
+ List openedFilesInNonTextEditor= new ArrayList();
+ List notFiles= new ArrayList();
+ IWorkbenchPage activePage = fSite.getWorkbenchWindow().getActivePage();
+
for (Iterator iter = fElements.iterator(); iter.hasNext();) {
SearchResultViewEntry entry= (SearchResultViewEntry) iter.next();
IResource resource= entry.getResource();
- if (resource instanceof IFile && ((IFile)resource).getModificationStamp() != entry.getModificationStamp())
- modifiedFiles.add(resource);
+ if (resource instanceof IFile) {
+ IFile file= (IFile)resource;
+ if (file.getModificationStamp() != entry.getModificationStamp() || !file.isSynchronized(IResource.DEPTH_ZERO)) {
+ modifiedFiles.add(resource);
+ } else if (activePage != null) {
+ IEditorPart part= activePage.findEditor(new FileEditorInput(file));
+ if (part != null && !(part instanceof ITextEditor))
+ openedFilesInNonTextEditor.add(file);
+ }
+ } else {
+ if (resource != null)
+ notFiles.add(resource);
+ }
}
if (!modifiedFiles.isEmpty()) {
showModifiedFileDialog(modifiedFiles);
return false;
}
+ if (!openedFilesInNonTextEditor.isEmpty()) {
+ showOpenedFileDialog(openedFilesInNonTextEditor);
+ return false;
+ }
+ if (!notFiles.isEmpty()) {
+ showNotFilesDialog(openedFilesInNonTextEditor);
+ return false;
+ }
IFile[] readOnlyFiles= getReadOnlyFiles();
if (readOnlyFiles.length == 0)
return true;
@@ -113,8 +140,11 @@ import org.eclipse.search.internal.ui.util.ListDialog;
}
private void showModifiedFileDialog(List modifiedFiles) {
+ String message= (modifiedFiles.size() == 1
+ ? SearchMessages.getString("ReplaceAction.error.changed_file") //$NON-NLS-1$
+ : SearchMessages.getString("ReplaceAction.error.changed_files")); //$NON-NLS-1$
ListDialog dialog= new ListDialog(fSite.getShell(), modifiedFiles, getDialogTitle(),
- SearchMessages.getString("ReplaceAction.error.changed_files"), //$NON-NLS-1$
+ message,
new IStructuredContentProvider() {
public Object[] getElements(Object inputElement) {
return ((List)inputElement).toArray();
@@ -151,4 +181,44 @@ import org.eclipse.search.internal.ui.util.ListDialog;
private String getDialogTitle() {
return SearchMessages.getString("ReplaceAction.dialog.title"); //$NON-NLS-1$
}
+
+ private void showOpenedFileDialog(List openedFilesInNonTextEditor) {
+ String message= (openedFilesInNonTextEditor.size() == 1
+ ? SearchMessages.getString("ReplaceAction.error.opened_file") //$NON-NLS-1$
+ : SearchMessages.getString("ReplaceAction.error.opened_files")); //$NON-NLS-1$
+ ListDialog dialog= new ListDialog(fSite.getShell(), openedFilesInNonTextEditor, getDialogTitle(),
+ message,
+ new IStructuredContentProvider() {
+ public Object[] getElements(Object inputElement) {
+ return ((List)inputElement).toArray();
+ }
+ public void dispose() {
+ }
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ },
+ new WorkbenchLabelProvider());
+ dialog.setCreateCancelButton(false);
+ dialog.open();
+ }
+
+ private void showNotFilesDialog(List notFiles) {
+ String message= (notFiles.size() == 1
+ ? SearchMessages.getString("ReplaceAction.error.not_file") //$NON-NLS-1$
+ : SearchMessages.getString("ReplaceAction.error.not_files")); //$NON-NLS-1$
+ ListDialog dialog= new ListDialog(fSite.getShell(), notFiles, getDialogTitle(),
+ message,
+ new IStructuredContentProvider() {
+ public Object[] getElements(Object inputElement) {
+ return ((List)inputElement).toArray();
+ }
+ public void dispose() {
+ }
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ },
+ new WorkbenchLabelProvider());
+ dialog.setCreateCancelButton(false);
+ dialog.open();
+ }
}
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceDialog.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceDialog.java
index 6dcc113d02b..99c892d8a7c 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceDialog.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceDialog.java
@@ -10,9 +10,11 @@
******************************************************************************/
package org.eclipse.search.internal.ui.text;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceDescription;
@@ -41,9 +43,13 @@ import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.util.Assert;
+import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorRegistry;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.actions.GlobalBuildAction;
import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
import org.eclipse.ui.texteditor.IDocumentProvider;
@@ -91,6 +97,16 @@ public class ReplaceDialog extends Dialog {
private int fMarkerIndex;
private IMarker fCurrentMatch;
+ private static class MarkerNotPresentableException extends Exception {
+ private IFile fFile;
+ MarkerNotPresentableException(IFile file) {
+ fFile= file;
+ }
+ public IFile getFile() {
+ return fFile;
+ }
+ }
+
protected ReplaceDialog(Shell parentShell, List elements, IWorkbenchWindow window, String searchPattern) {
super(parentShell);
Assert.isNotNull(elements);
@@ -126,6 +142,9 @@ public class ReplaceDialog extends Dialog {
} catch (CoreException e) {
ExceptionHandler.handle(e, getShell(), getDialogTitle(), SearchMessages.getString("ReplaceDialog.error.no_matches")); //$NON-NLS-1$
fFatalError= true;
+ } catch (MarkerNotPresentableException e) {
+ handleMarkerNotPresentableException(e);
+ fFatalError= true;
}
return super.open();
}
@@ -217,6 +236,9 @@ public class ReplaceDialog extends Dialog {
} catch (BadLocationException e) {
MessageDialog.openError(getShell(), getDialogTitle(), SearchMessages.getString("ReplaceDialog.error.different_content")); //$NON-NLS-1$
fFatalError= true;
+ } catch (MarkerNotPresentableException e) {
+ handleMarkerNotPresentableException(e);
+ fFatalError= true;
}
updateButtons();
super.buttonPressed(buttonId);
@@ -238,7 +260,7 @@ public class ReplaceDialog extends Dialog {
return fElementIndex < fElements.size();
}
- private IMarker getNextMatch(boolean save) throws CoreException {
+ private IMarker getNextMatch(boolean save) throws CoreException, MarkerNotPresentableException {
if (fCurrentMarkers == null) {
if (fElementIndex >= fElements.size())
return null;
@@ -251,7 +273,9 @@ public class ReplaceDialog extends Dialog {
if (fEditor == null) {
IWorkbenchPage activePage = fWindow.getActivePage();
int openEditors= activePage.getEditorReferences().length;
- fEditor= (ITextEditor)activePage.openEditor(result, false);
+
+ fEditor= openFile(result, activePage);
+ fEditor.gotoMarker(result);
IDocumentProvider provider= fEditor.getDocumentProvider();
IEditorInput input = fEditor.getEditorInput();
fDocument= provider.getDocument(input);
@@ -268,9 +292,32 @@ public class ReplaceDialog extends Dialog {
return result;
}
+ private ITextEditor openFile(IMarker marker, IWorkbenchPage activePage) throws MarkerNotPresentableException, PartInitException {
+ IFile markerFile= marker.getResource() instanceof IFile ? (IFile)marker.getResource() : null;
+ if (markerFile == null)
+ throw new MarkerNotPresentableException(null);
+
+ String currentEditorId= null;
+ IEditorRegistry editorRegistry= SearchPlugin.getDefault().getWorkbench().getEditorRegistry();
+ IEditorDescriptor desc= editorRegistry.getDefaultEditor(markerFile);
+ if (desc != null)
+ currentEditorId= desc.getId();
+ try {
+ IEditorPart result= activePage.openEditor(markerFile, "org.eclipse.ui.DefaultTextEditor", false); //$NON-NLS-1$
+ if (!(result instanceof ITextEditor))
+ throw new MarkerNotPresentableException(markerFile);
+ return (ITextEditor)result;
+ } finally {
+ if (currentEditorId != null)
+ editorRegistry.setDefaultEditor(markerFile, currentEditorId);
+ }
+ }
+
private void saveEditor(boolean save) throws CoreException {
- if (fEditor != null)
- save= save && fEditor.isDirty();
+ if (fEditor == null)
+ return;
+
+ save= save && fEditor.isDirty();
if (save) {
IDocumentProvider provider= fEditor.getDocumentProvider();
IEditorInput input = fEditor.getEditorInput();
@@ -282,7 +329,7 @@ public class ReplaceDialog extends Dialog {
provider.changed(input);
}
}
- if (fEditor != null && fCloseEditor && save)
+ if (fCloseEditor && !fEditor.isDirty())
fEditor.close(false);
fEditor= null;
fDocument= null;
@@ -322,4 +369,15 @@ public class ReplaceDialog extends Dialog {
private String getDialogTitle() {
return SearchMessages.getString("ReplaceDialog.dialog.title"); //$NON-NLS-1$
}
+
+ private void handleMarkerNotPresentableException(MarkerNotPresentableException e) {
+ IFile file= e.getFile();
+ String message;
+ if (file == null) {
+ message= SearchMessages.getString("ReplaceDialog.error.no_file_for_marker"); //$NON-NLS-1$
+ } else {
+ message= SearchMessages.getFormattedString("ReplaceDialog.error.unable_to_open_text_editor", file.getName()); //$NON-NLS-1$
+ }
+ MessageDialog.openError(getParentShell(), getDialogTitle(), message);
+ }
}

Back to the top