Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Maeder2004-06-22 15:28:22 +0000
committerThomas Maeder2004-06-22 15:28:22 +0000
commit1116b2aec468c146904dfb1f53193cd02c43b408 (patch)
tree850c71ea693d178d5115edfeab375b3735c22283
parentc7366d9c3f92a59ed9df6ee9ad4a76f813c0583e (diff)
downloadeclipse.platform.text-1116b2aec468c146904dfb1f53193cd02c43b408.tar.gz
eclipse.platform.text-1116b2aec468c146904dfb1f53193cd02c43b408.tar.xz
eclipse.platform.text-1116b2aec468c146904dfb1f53193cd02c43b408.zip
fix for bug 68039
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.properties2
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction2.java69
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceDialog2.java26
3 files changed, 53 insertions, 44 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 e961a91b7..9d4ca2661 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
@@ -195,6 +195,8 @@ SearchPreferencePage.ignorePotentialMatches= &Ignore potential matches
ReplaceAction.label_all= Re&place...
ReplaceAction.label_selected= Rep&lace Selected...
ReplaceAction.error.only_on_text_search= Replace is only available on text search.
+ReplaceAction2.error_validate.title=Replace
+ReplaceAction2.error_validate.message=An error occurred while ensuring that files are writeable
ReplaceAction.dialog.title= Replace
ReplaceDialog.replace_label= Replace:
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction2.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction2.java
index 8a09397cd..829c10443 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction2.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction2.java
@@ -18,22 +18,24 @@ import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceProxy;
import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-
-import org.eclipse.swt.widgets.Item;
-
-import org.eclipse.core.filebuffers.FileBuffers;
-import org.eclipse.core.filebuffers.ITextFileBuffer;
-import org.eclipse.core.filebuffers.ITextFileBufferManager;
-
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.util.Assert;
@@ -42,16 +44,14 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewer;
-
-import org.eclipse.ui.IWorkbenchSite;
-import org.eclipse.ui.actions.WorkspaceModifyOperation;
-
-import org.eclipse.search.ui.text.AbstractTextSearchResult;
-import org.eclipse.search.ui.text.Match;
-
import org.eclipse.search.internal.ui.SearchMessages;
import org.eclipse.search.internal.ui.SearchPlugin;
import org.eclipse.search.internal.ui.util.ExceptionHandler;
+import org.eclipse.search.ui.text.AbstractTextSearchResult;
+import org.eclipse.search.ui.text.Match;
+import org.eclipse.swt.widgets.Item;
+import org.eclipse.ui.IWorkbenchSite;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
/* package */ class ReplaceAction2 extends Action {
@@ -124,13 +124,19 @@ import org.eclipse.search.internal.ui.util.ExceptionHandler;
private IFile[] collectFiles(Iterator resources) {
final Set files= new HashSet();
+ final AbstractTextSearchResult result= fPage.getInput();
+ if (result == null)
+ return new IFile[0];
while (resources.hasNext()) {
IResource resource= (IResource) resources.next();
try {
resource.accept(new IResourceProxyVisitor() {
public boolean visit(IResourceProxy proxy) throws CoreException {
if (proxy.getType() == IResource.FILE) {
- files.add(proxy.requestResource());
+ IResource file= proxy.requestResource();
+ if (result.getMatchCount(file) > 0) {
+ files.add(file);
+ }
return false;
}
return true;
@@ -147,13 +153,30 @@ import org.eclipse.search.internal.ui.util.ExceptionHandler;
public void run() {
- if (validateResources((FileSearchQuery) fPage.getInput().getQuery())) {
- ReplaceDialog2 dialog= new ReplaceDialog2(fSite.getShell(), fElements, fPage);
- dialog.open();
+ IWorkspace workspace= ResourcesPlugin.getWorkspace();
+ ISchedulingRule rule= workspace.getRuleFactory().modifyRule(workspace.getRoot());
+ try {
+ Platform.getJobManager().beginRule(rule, null);
+ if (validateResources((FileSearchQuery) fPage.getInput().getQuery())) {
+ ReplaceDialog2 dialog= new ReplaceDialog2(fSite.getShell(), fElements, fPage);
+ dialog.open();
+ }
+ } catch (OperationCanceledException e) {
+ } finally {
+ Platform.getJobManager().endRule(rule);
}
}
private boolean validateResources(final FileSearchQuery operation) {
+ IFile[] readOnlyFiles= getReadOnlyFiles();
+ IStatus status= ResourcesPlugin.getWorkspace().validateEdit(readOnlyFiles, fSite.getShell());
+ if (!status.isOK()) {
+ if (status.getSeverity() != IStatus.CANCEL) {
+ ErrorDialog.openError(fSite.getShell(), SearchMessages.getString("ReplaceAction2.error_validate.title"), SearchMessages.getString("ReplaceAction2.error_validate.message"), status); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return false;
+ }
+
final List outOfDateEntries= new ArrayList();
for (int j= 0; j < fElements.length; j++) {
IFile entry = fElements[j];
@@ -195,6 +218,16 @@ import org.eclipse.search.internal.ui.util.ExceptionHandler;
return true;
}
+ private IFile[] getReadOnlyFiles() {
+ Set readOnly= new HashSet();
+ for (int i = 0; i < fElements.length; i++) {
+ if (fElements[i].isReadOnly())
+ readOnly.add(fElements[i]);
+ }
+ IFile[] readOnlyArray= new IFile[readOnly.size()];
+ return (IFile[]) readOnly.toArray(readOnlyArray);
+ }
+
private void research(IProgressMonitor monitor, List outOfDateEntries, FileSearchQuery operation) throws CoreException {
IStatus status= null;
for (Iterator elements = outOfDateEntries.iterator(); elements.hasNext();) {
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceDialog2.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceDialog2.java
index deca0dba0..24b1e47f5 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceDialog2.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceDialog2.java
@@ -14,10 +14,8 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Set;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
@@ -33,11 +31,9 @@ import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
-import org.eclipse.core.runtime.jobs.MultiRule;
import org.eclipse.jface.contentassist.SubjectControlContentAssistant;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -361,8 +357,6 @@ class ReplaceDialog2 extends ExtendedDialogWindow {
private void run(ReplaceOperation operation, IResource resource) throws InvocationTargetException, InterruptedException {
IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
ISchedulingRule rule= ruleFactory.modifyRule(resource);
- ISchedulingRule validateRule= ruleFactory.validateEditRule(new IResource[] { resource });
- rule= MultiRule.combine(rule, validateRule);
PlatformUI.getWorkbench().getProgressService().runInUI(this, operation, rule);
}
@@ -386,10 +380,6 @@ class ReplaceDialog2 extends ExtendedDialogWindow {
private void replaceAll(IProgressMonitor pm, String replacementText) throws BadLocationException, CoreException {
int resourceCount= countResources();
- IStatus status= ResourcesPlugin.getWorkspace().validateEdit(getAllFiles(), getShell());
- if (!status.isOK()) {
- throw new CoreException(status);
- }
pm.beginTask(SearchMessages.getString("ReplaceDialog.task.replace.replaceAll"), resourceCount); //$NON-NLS-1$
while (fMarkers.size() > 0) {
replaceInFile(new SubProgressMonitor(pm, 1, 0), replacementText);
@@ -397,16 +387,6 @@ class ReplaceDialog2 extends ExtendedDialogWindow {
pm.done();
}
- private IFile[] getAllFiles() {
- Set files= new HashSet();
- for (int i= 0; i < fMarkers.size(); i++) {
- Match marker= (Match)fMarkers.get(i);
- files.add(marker.getElement());
- }
- IFile[] fileArray= new IFile[files.size()];
- return (IFile[])files.toArray(fileArray);
- }
-
private void replaceInFile(final IProgressMonitor pm, final IFile file, final String replacementText, final Match[] markers) throws BadLocationException, CoreException {
if (pm.isCanceled())
throw new OperationCanceledException();
@@ -420,12 +400,6 @@ class ReplaceDialog2 extends ExtendedDialogWindow {
}
try {
if (file.isReadOnly()) {
- IStatus status= file.getWorkspace().validateEdit(new IFile[]{file}, getShell());
- if (!status.isOK()) {
- throw new CoreException(status);
- }
- }
- if (file.isReadOnly()) {
if (fSkipReadonly) {
skipFile();
return;

Back to the top