Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Maeder2004-02-16 11:53:01 -0500
committerThomas Maeder2004-02-16 11:53:01 -0500
commit3f0cc5405f4918774647ebe19fa19a429790ee3c (patch)
treef252389ccf82d15447b71f7f2dc196867238fedd /org.eclipse.search
parentfab6232477c426f08241faaf758d62a057ed945b (diff)
downloadeclipse.platform.text-3f0cc5405f4918774647ebe19fa19a429790ee3c.tar.gz
eclipse.platform.text-3f0cc5405f4918774647ebe19fa19a429790ee3c.tar.xz
eclipse.platform.text-3f0cc5405f4918774647ebe19fa19a429790ee3c.zip
Added "Replace selected" action for text search (first cut).
Various little UI fixes
Diffstat (limited to 'org.eclipse.search')
-rw-r--r--org.eclipse.search/icons/full/clcl16/flatLayout.gifbin0 -> 100 bytes
-rw-r--r--org.eclipse.search/icons/full/clcl16/hierarchicalLayout.gifbin0 -> 106 bytes
-rw-r--r--org.eclipse.search/icons/full/dlcl16/flatLayout.gifbin0 -> 71 bytes
-rw-r--r--org.eclipse.search/icons/full/dlcl16/hierarchicalLayout.gifbin0 -> 75 bytes
-rw-r--r--org.eclipse.search/icons/full/elcl16/flatLayout.gifbin0 -> 82 bytes
-rw-r--r--org.eclipse.search/icons/full/elcl16/hierarchicalLayout.gifbin0 -> 103 bytes
-rw-r--r--org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchViewPage.java49
-rw-r--r--org.eclipse.search/new search/org/eclipse/search2/internal/ui/InternalSearchUI.java17
-rw-r--r--org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchDropDownAction.java6
-rw-r--r--org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchMessages.properties7
-rw-r--r--org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchView.java3
-rw-r--r--org.eclipse.search/new search/org/eclipse/search2/internal/ui/basic/views/SetLayoutAction.java (renamed from org.eclipse.search/new search/org/eclipse/search2/internal/ui/basic/views/ToggleModeAction.java)20
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/core/text/FileMatchCollector.java38
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/core/text/IMatchCollector.java21
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/core/text/MatchLocator.java8
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java7
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPluginImages.java2
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileMatch.java32
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java41
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java46
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction.java11
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction2.java165
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceDialog2.java590
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/SearchAgainConfirmationDialog.java16
24 files changed, 1023 insertions, 56 deletions
diff --git a/org.eclipse.search/icons/full/clcl16/flatLayout.gif b/org.eclipse.search/icons/full/clcl16/flatLayout.gif
new file mode 100644
index 000000000..b84df084f
--- /dev/null
+++ b/org.eclipse.search/icons/full/clcl16/flatLayout.gif
Binary files differ
diff --git a/org.eclipse.search/icons/full/clcl16/hierarchicalLayout.gif b/org.eclipse.search/icons/full/clcl16/hierarchicalLayout.gif
new file mode 100644
index 000000000..e597c3d16
--- /dev/null
+++ b/org.eclipse.search/icons/full/clcl16/hierarchicalLayout.gif
Binary files differ
diff --git a/org.eclipse.search/icons/full/dlcl16/flatLayout.gif b/org.eclipse.search/icons/full/dlcl16/flatLayout.gif
new file mode 100644
index 000000000..aa0160d1c
--- /dev/null
+++ b/org.eclipse.search/icons/full/dlcl16/flatLayout.gif
Binary files differ
diff --git a/org.eclipse.search/icons/full/dlcl16/hierarchicalLayout.gif b/org.eclipse.search/icons/full/dlcl16/hierarchicalLayout.gif
new file mode 100644
index 000000000..76f336003
--- /dev/null
+++ b/org.eclipse.search/icons/full/dlcl16/hierarchicalLayout.gif
Binary files differ
diff --git a/org.eclipse.search/icons/full/elcl16/flatLayout.gif b/org.eclipse.search/icons/full/elcl16/flatLayout.gif
new file mode 100644
index 000000000..9f9ca4876
--- /dev/null
+++ b/org.eclipse.search/icons/full/elcl16/flatLayout.gif
Binary files differ
diff --git a/org.eclipse.search/icons/full/elcl16/hierarchicalLayout.gif b/org.eclipse.search/icons/full/elcl16/hierarchicalLayout.gif
new file mode 100644
index 000000000..b50b2c38a
--- /dev/null
+++ b/org.eclipse.search/icons/full/elcl16/hierarchicalLayout.gif
Binary files differ
diff --git a/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchViewPage.java b/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchViewPage.java
index a74e1fc84..7c8cd10a6 100644
--- a/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchViewPage.java
+++ b/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchViewPage.java
@@ -47,6 +47,7 @@ import org.eclipse.search.ui.ISearchResultViewPart;
import org.eclipse.search.ui.SearchResultEvent;
import org.eclipse.search.internal.ui.CopyToClipboardAction;
+import org.eclipse.search.internal.ui.SearchPluginImages;
import org.eclipse.search2.internal.ui.InternalSearchUI;
import org.eclipse.search2.internal.ui.SearchMessages;
@@ -55,12 +56,13 @@ import org.eclipse.search2.internal.ui.basic.views.RemoveAllResultsAction;
import org.eclipse.search2.internal.ui.basic.views.RemoveMatchAction;
import org.eclipse.search2.internal.ui.basic.views.SearchResultsTableViewer;
import org.eclipse.search2.internal.ui.basic.views.SearchResultsTreeViewer;
+import org.eclipse.search2.internal.ui.basic.views.SetLayoutAction;
import org.eclipse.search2.internal.ui.basic.views.ShowNextResultAction;
import org.eclipse.search2.internal.ui.basic.views.ShowPreviousResultAction;
-import org.eclipse.search2.internal.ui.basic.views.ToggleModeAction;
import org.eclipse.search2.internal.ui.text.AnnotationManager;
public abstract class AbstractTextSearchViewPage extends Page implements ISearchResultPage {
+ private static final boolean INITIALLY_FLAT= false;
private StructuredViewer fViewer;
private Composite fViewerContainer;
private ISearchResultViewPart fViewPart;
@@ -75,7 +77,8 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch
private Action fRemoveAllResultsAction;
private Action fShowNextAction;
private Action fShowPreviousAction;
- private ToggleModeAction fToggleModeAction;
+ private Action fFlatAction;
+ private Action fHierarchicalAction;
private int fCurrentMatchIndex= 0;
@@ -84,7 +87,17 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch
fRemoveResultsAction= new RemoveMatchAction(this);
fShowNextAction= new ShowNextResultAction(this);
fShowPreviousAction= new ShowPreviousResultAction(this);
- fToggleModeAction= new ToggleModeAction(this);
+
+
+ fFlatAction= new SetLayoutAction(this, SearchMessages.getString("AbstractTextSearchViewPage.flat_layout.label"), SearchMessages.getString("AbstractTextSearchViewPage.flat_layout.tooltip"), true); //$NON-NLS-1$ //$NON-NLS-2$
+ fHierarchicalAction= new SetLayoutAction(this, SearchMessages.getString("AbstractTextSearchViewPage.hierarchical_layout.label"), SearchMessages.getString("AbstractTextSearchViewPage.hierarchical_layout.tooltip"), false); //$NON-NLS-1$ //$NON-NLS-2$
+
+ SearchPluginImages.setImageDescriptors(fFlatAction, SearchPluginImages.T_LCL, SearchPluginImages.IMG_LCL_SEARCH_FLAT_LAYOUT);
+ SearchPluginImages.setImageDescriptors(fHierarchicalAction, SearchPluginImages.T_LCL, SearchPluginImages.IMG_LCL_SEARCH_HIERARCHICAL_LAYOUT);
+
+ fFlatAction.setChecked(INITIALLY_FLAT);
+ fHierarchicalAction.setChecked(!INITIALLY_FLAT);
+
fBatchedUpdates= new HashSet();
fListener= new ISearchResultListener() {
public void searchResultChanged(SearchResultEvent e) {
@@ -150,9 +163,9 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch
mgr.appendToGroup(IContextMenuConstants.GROUP_ADDITIONS, fCopyToClipboardAction);
mgr.appendToGroup(IContextMenuConstants.GROUP_SHOW, fShowNextAction);
mgr.appendToGroup(IContextMenuConstants.GROUP_SHOW, fShowPreviousAction);
- mgr.appendToGroup(IContextMenuConstants.GROUP_REMOVE_MATCHES, fRemoveResultsAction);
+ if (getCurrentMatch() != null)
+ mgr.appendToGroup(IContextMenuConstants.GROUP_REMOVE_MATCHES, fRemoveResultsAction);
mgr.appendToGroup(IContextMenuConstants.GROUP_REMOVE_MATCHES, fRemoveAllResultsAction);
- mgr.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, fToggleModeAction);
}
/**
@@ -176,22 +189,25 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch
fViewerContainer.setSize(100, 100);
fViewerContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
fViewerContainer.setLayout(new FillLayout());
- createViewer(fViewerContainer, false);
+ createViewer(fViewerContainer, INITIALLY_FLAT);
}
/**
- * Toggles the page between tree mode and flat (table) mode.
+ * Toggles the page between tree mode and flat (table) layout.
*/
- public void toggleMode() {
+ public void setFlatLayout(boolean on) {
+ if (on == isFlatLayout())
+ return;
ISelection selection= fViewer.getSelection();
- boolean newMode= !isFlatMode();
ISearchResult result= disconnectViewer();
fViewer.getControl().dispose();
fViewer= null;
- createViewer(fViewerContainer, newMode);
+ createViewer(fViewerContainer, on);
fViewerContainer.layout(true);
connectViewer(result);
fViewer.setSelection(selection, true);
+ fFlatAction.setChecked(isFlatLayout());
+ fHierarchicalAction.setChecked(!isFlatLayout());
}
/**
@@ -199,7 +215,7 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch
* table.
* @return Whether the page shows a tree or a table.
*/
- public boolean isFlatMode() {
+ public boolean isFlatLayout() {
return fViewer instanceof TableViewer;
}
@@ -299,7 +315,7 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch
}
}
- public void run() throws PartInitException {
+ public void run() throws Exception {
Position currentPosition= InternalSearchUI.getInstance().getPositionTracker().getCurrentPosition(match);
if (currentPosition != null) {
showMatch(match.getElement(), currentPosition.getOffset(), currentPosition.getLength());
@@ -414,6 +430,15 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch
actionBars.setGlobalActionHandler(ActionFactory.NEXT.getId(), fShowNextAction);
actionBars.setGlobalActionHandler(ActionFactory.PREVIOUS.getId(), fShowPreviousAction);
}
+
+ addLayoutMenu(menuManager);
+ }
+
+ private void addLayoutMenu(IMenuManager menuManager) {
+ MenuManager subMenu= new MenuManager(SearchMessages.getString("AbstractTextSearchViewPage.layout.label")); //$NON-NLS-1$
+ subMenu.add(fFlatAction);
+ subMenu.add(fHierarchicalAction);
+ menuManager.add(subMenu);
}
/**
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/InternalSearchUI.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/InternalSearchUI.java
index a80891d53..a29a6d8c0 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/InternalSearchUI.java
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/InternalSearchUI.java
@@ -15,11 +15,15 @@ import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.util.Assert;
import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.WorkbenchException;
import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.ISearchResult;
import org.eclipse.search.ui.ISearchResultManager;
+import org.eclipse.search.ui.SearchUI;
import org.eclipse.search.internal.ui.SearchPlugin;
@@ -211,8 +215,19 @@ public class InternalSearchUI {
}
public void activateSearchView() {
+ IWorkbenchWindow window= SearchPlugin.getActiveWorkbenchWindow();
+ String defaultPerspectiveId= SearchUI.getDefaultPerspectiveId();
+ if (defaultPerspectiveId != null) {
+ if (window != null && window.getShell() != null && !window.getShell().isDisposed()) {
+ try {
+ PlatformUI.getWorkbench().showPerspective(defaultPerspectiveId, window);
+ } catch (WorkbenchException ex) {
+ // show view in current perspective
+ }
+ }
+ }
try {
- SearchPlugin.getActiveWorkbenchWindow().getActivePage().showView(SEARCH_VIEW_ID);
+ window.getActivePage().showView(SEARCH_VIEW_ID);
} catch (PartInitException ex) {
// TODO Auto-generated catch block
}
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchDropDownAction.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchDropDownAction.java
index feccee002..707b654d6 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchDropDownAction.java
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchDropDownAction.java
@@ -69,8 +69,10 @@ class SearchDropDownAction extends Action implements IMenuCreator {
action.setChecked(true);
addActionToMenu(fMenu, action);
}
- new MenuItem(fMenu, SWT.SEPARATOR);
- addActionToMenu(fMenu, new RemoveAllSearchesAction());
+ if (searches.length > 0) {
+ new MenuItem(fMenu, SWT.SEPARATOR);
+ addActionToMenu(fMenu, new RemoveAllSearchesAction());
+ }
return fMenu;
}
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchMessages.properties b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchMessages.properties
index 87ca7979f..11cca0a02 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchMessages.properties
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchMessages.properties
@@ -16,8 +16,6 @@ RemoveAllResultsAction.label=Remove All Matches
RemoveAllResultsAction.tooltip=Removes all matches in the current search result
ShowNextResultAction.label=Show Next Match
ShowNextResultAction.tooltip=Shows the next match
-ToggleModeAction.label=Show as Tree
-ToggleModeAction.tooltip=Show search results as a tree
SortDropDownActon.label=Sort By
SortDropDownActon.tooltip=Selects the sort order
SortDropDownActon.ascending.label=Sort ascending
@@ -29,3 +27,8 @@ RemoveMatchAction.label=Remove Match
RemoveMatchAction.tooltip=Remove the currently shown match
DefaultSearchViewPage.show_match=Show Match
DefaultSearchViewPage.error.no_editor=Could not find an editor for the current match
+AbstractTextSearchViewPage.flat_layout.label=Flat
+AbstractTextSearchViewPage.flat_layout.tooltip=Set Flat Layout
+AbstractTextSearchViewPage.hierarchical_layout.label=Hierarchical
+AbstractTextSearchViewPage.hierarchical_layout.tooltip=Set Hierarchical Layout
+AbstractTextSearchViewPage.layout.label=Layout
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchView.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchView.java
index ca1d33b62..87ba4c1ca 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchView.java
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchView.java
@@ -250,6 +250,7 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I
private void createActions() {
fSearchesDropDownAction= new SearchDropDownAction(this);
+ fSearchesDropDownAction.setEnabled(NewSearchUI.getSearchManager().getSearchResults().length != 0);
fSearchAgainAction= new SearchAgainAction(this);
}
@@ -263,6 +264,7 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I
public void searchResultAdded(ISearchResult search) {
showSearchResult(search);
+ fSearchesDropDownAction.setEnabled(NewSearchUI.getSearchManager().getSearchResults().length != 0);
}
public void searchResultRemoved(ISearchResult search) {
@@ -272,6 +274,7 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I
partActivated(fDefaultPart);
}
fSearchViewStates.remove(search);
+ fSearchesDropDownAction.setEnabled(NewSearchUI.getSearchManager().getSearchResults().length != 0);
}
public void searchResultChanged(SearchResultEvent e) {
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/basic/views/ToggleModeAction.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/basic/views/SetLayoutAction.java
index b20e2c033..3c02daffc 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/basic/views/ToggleModeAction.java
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/basic/views/SetLayoutAction.java
@@ -11,25 +11,23 @@
package org.eclipse.search2.internal.ui.basic.views;
import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
-import org.eclipse.search.ui.text.*;
+import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
-import org.eclipse.search2.internal.ui.SearchMessages;
-
-public class ToggleModeAction extends Action {
+public class SetLayoutAction extends Action {
private AbstractTextSearchViewPage fPage;
+ private boolean fIsFlatMode;
- public ToggleModeAction(AbstractTextSearchViewPage page) {
+ public SetLayoutAction(AbstractTextSearchViewPage page, String label, String tooltip, boolean flatMode) {
+ super(label, IAction.AS_CHECK_BOX);
fPage= page;
- setText(SearchMessages.getString("ToggleModeAction.label")); //$NON-NLS-1$
- setToolTipText(SearchMessages.getString("ToggleModeAction.tooltip")); //$NON-NLS-1$
- setChecked(!page.isFlatMode());
+ setToolTipText(tooltip); //$NON-NLS-1$
+ fIsFlatMode= flatMode;
}
public void run() {
- fPage.toggleMode();
- setChecked(!fPage.isFlatMode());
+ fPage.setFlatLayout(fIsFlatMode);
}
-
}
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/text/FileMatchCollector.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/FileMatchCollector.java
new file mode 100644
index 000000000..2b85f80ac
--- /dev/null
+++ b/org.eclipse.search/search/org/eclipse/search/internal/core/text/FileMatchCollector.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.search.internal.core.text;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * @author Thomas Mäder
+ *
+ */
+public class FileMatchCollector implements IMatchCollector {
+ private ITextSearchResultCollector fCollector;
+ private IResourceProxy fProxy;
+
+ public FileMatchCollector(ITextSearchResultCollector collector, IResourceProxy proxy) {
+ fCollector= collector;
+ fProxy= proxy;
+ }
+
+ public void accept(String line, int start, int length, int lineNumber) throws InvocationTargetException {
+ try {
+ fCollector.accept(fProxy, line, start, length, lineNumber);
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+}
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/text/IMatchCollector.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/IMatchCollector.java
new file mode 100644
index 000000000..936305fd3
--- /dev/null
+++ b/org.eclipse.search/search/org/eclipse/search/internal/core/text/IMatchCollector.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.search.internal.core.text;
+
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * @author Thomas Mäder
+ *
+ */
+public interface IMatchCollector {
+ void accept(String line, int start, int length, int lineNumber) throws InvocationTargetException;
+}
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/text/MatchLocator.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/MatchLocator.java
index 9d77f53f6..e87a84373 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/core/text/MatchLocator.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/core/text/MatchLocator.java
@@ -12,13 +12,13 @@ package org.eclipse.search.internal.core.text;
import java.io.IOException;
import java.io.Reader;
+import java.lang.reflect.InvocationTargetException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.eclipse.core.resources.IResourceProxy;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
+
import org.eclipse.search.internal.ui.SearchMessages;
/**
@@ -61,7 +61,7 @@ public class MatchLocator {
return fPattern;
}
- public void locateMatches(IProgressMonitor monitor, IResourceProxy proxy, Reader reader, ITextSearchResultCollector collector) throws CoreException, IOException {
+ public void locateMatches(IProgressMonitor monitor, Reader reader, IMatchCollector collector) throws IOException, InvocationTargetException {
int lineCounter= 1;
int charCounter=0;
boolean eof= false;
@@ -78,7 +78,7 @@ public class MatchLocator {
if (fMatcher.find(start)) {
start= charCounter + fMatcher.start();
int length= fMatcher.end() - fMatcher.start();
- collector.accept(proxy, line.trim(), start, length, lineCounter);
+ collector.accept(line.trim(), start, length, lineCounter);
start= fMatcher.end();
}
else // no match in this line
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java
index a5f9ceff6..65a006bce 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java
@@ -15,6 +15,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -147,7 +148,11 @@ public class TextSearchVisitor extends TypedResourceVisitor {
InputStream stream= file.getContents(false);
reader= new BufferedReader(new InputStreamReader(stream, ResourcesPlugin.getEncoding()));
}
- fLocator.locateMatches(fProgressMonitor, proxy, reader, fCollector);
+ try {
+ fLocator.locateMatches(fProgressMonitor, reader, new FileMatchCollector(fCollector, proxy));
+ } catch (InvocationTargetException e1) {
+ throw ((CoreException)e1.getCause());
+ }
} catch (IOException e) {
String message= SearchMessages.getFormattedString("TextSearchVisitor.error", file.getFullPath()); //$NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, SearchUI.PLUGIN_ID, Platform.PLUGIN_ERROR, message, e));
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPluginImages.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPluginImages.java
index 54331cc6b..f0f9c2b09 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPluginImages.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPluginImages.java
@@ -60,6 +60,8 @@ public class SearchPluginImages {
public static final String IMG_LCL_SEARCH_GOTO= NAME_PREFIX + "search_goto.gif"; //$NON-NLS-1$
public static final String IMG_LCL_SEARCH_SORT= NAME_PREFIX + "search_sortmatch.gif"; //$NON-NLS-1$
public static final String IMG_LCL_SEARCH_HISTORY= NAME_PREFIX + "search_history.gif"; //$NON-NLS-1$
+ public static final String IMG_LCL_SEARCH_FLAT_LAYOUT= NAME_PREFIX + "flatLayout.gif"; //$NON-NLS-1$
+ public static final String IMG_LCL_SEARCH_HIERARCHICAL_LAYOUT= NAME_PREFIX + "hierarchicalLayout.gif"; //$NON-NLS-1$
public static final String IMG_VIEW_SEARCHRES= NAME_PREFIX + "searchres.gif"; //$NON-NLS-1$
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileMatch.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileMatch.java
new file mode 100644
index 000000000..d1f28e18a
--- /dev/null
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileMatch.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.search.internal.ui.text;
+
+import org.eclipse.core.resources.IFile;
+
+import org.eclipse.search.ui.text.Match;
+
+public class FileMatch extends Match {
+ private long fCreationTimeStamp;
+
+ public FileMatch(IFile element, int offset, int length) {
+ super(element, offset, length);
+ fCreationTimeStamp= element.getModificationStamp();
+ }
+
+ public IFile getFile() {
+ return (IFile) getElement();
+ }
+
+ public long getCreationTimeStamp() {
+ return fCreationTimeStamp;
+ }
+}
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java
index b0544c99d..bc00a7009 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java
@@ -10,10 +10,16 @@
*******************************************************************************/
package org.eclipse.search.internal.ui.text;
+import java.util.HashMap;
+import java.util.List;
+
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewer;
@@ -28,6 +34,7 @@ import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.search.ui.IContextMenuConstants;
import org.eclipse.search.ui.ISearchResultViewPart;
+import org.eclipse.search.ui.SearchUI;
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
import org.eclipse.search.internal.ui.SearchPlugin;
@@ -43,12 +50,17 @@ public class FileSearchPage extends AbstractTextSearchViewPage {
private SortAction fCurrentSortAction;
private SortAction fSortByNameAction;
private SortAction fSortByPathAction;
+ private ReplaceAction2 fReplaceAction;
public FileSearchPage() {
fSortByNameAction= new SortAction("Name", this, FileLabelProvider.SHOW_LABEL_PATH);
fSortByPathAction= new SortAction("Path", this, FileLabelProvider.SHOW_PATH_LABEL);
fCurrentSortAction= fSortByNameAction;
}
+
+ StructuredViewer internalGetViewer() {
+ return getViewer();
+ }
protected void configureViewer(StructuredViewer viewer) {
viewer.setLabelProvider(new DelegatingLabelProvider(this, new FileLabelProvider(FileLabelProvider.SHOW_LABEL)));
@@ -65,20 +77,39 @@ public class FileSearchPage extends AbstractTextSearchViewPage {
IFile file= (IFile) element;
IWorkbenchPage page= SearchPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor= IDE.openEditor(page, file, false);
- if (!(editor instanceof ITextEditor))
- return;
- ITextEditor textEditor= (ITextEditor) editor;
- textEditor.selectAndReveal(offset, length);
+ if (!(editor instanceof ITextEditor)) {
+ showWithMarker(editor, file, offset, length);
+ } else {
+ ITextEditor textEditor= (ITextEditor) editor;
+ textEditor.selectAndReveal(offset, length);
+ }
+ }
+ private void showWithMarker(IEditorPart editor, IFile file, int offset, int length) {
+ try {
+ IMarker marker= file.createMarker(SearchUI.SEARCH_MARKER);
+ HashMap attributes= new HashMap(4);
+ attributes.put(IMarker.CHAR_START, new Integer(offset));
+ attributes.put(IMarker.CHAR_END, new Integer(offset + length));
+ marker.setAttributes(attributes);
+ IDE.gotoMarker(editor, marker);
+ marker.delete();
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
+
protected void fillContextMenu(IMenuManager mgr) {
super.fillContextMenu(mgr);
addSortActions(mgr);
fActionGroup.setContext(new ActionContext(getSite().getSelectionProvider().getSelection()));
fActionGroup.fillContextMenu(mgr);
+ fReplaceAction= new ReplaceAction2(this, (IStructuredSelection) getViewer().getSelection());
+ mgr.add(fReplaceAction);
}
private void addSortActions(IMenuManager mgr) {
- if (!isFlatMode())
+ if (!isFlatLayout())
return;
MenuManager sortMenu= new MenuManager("Sort By");
sortMenu.add(fSortByNameAction);
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java
index 2fd6f74d6..782a7b5d3 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java
@@ -12,6 +12,7 @@ package org.eclipse.search.internal.ui.text;
import java.text.MessageFormat;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceProxy;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -21,8 +22,8 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.ISearchResult;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
-import org.eclipse.search.ui.text.Match;
+import org.eclipse.search.internal.core.SearchScope;
import org.eclipse.search.internal.core.text.ITextSearchResultCollector;
import org.eclipse.search.internal.core.text.MatchLocator;
import org.eclipse.search.internal.core.text.TextSearchEngine;
@@ -66,7 +67,7 @@ public class FileSearchQuery implements ISearchQuery {
start= 0;
if (length < 0)
length= 0;
- textResult.addMatch(new Match(resource, start, length));
+ textResult.addMatch(new FileMatch((IFile) resource, start, length));
}
public void done() {
@@ -80,16 +81,51 @@ public class FileSearchQuery implements ISearchQuery {
public String getName() {
return fName;
}
+
+ public String getSearchString() {
+ return fSearchString;
+ }
String getSingularLabel() {
String[] args= new String[] { fSearchString, fScope.getDescription() };
- String format= "{0} - 1 match in {1}";
+ String format= "{0} - 1 match in {1}"; //$NON-NLS-1$
return MessageFormat.format(format, args);
}
String getPluralPattern() {
- String[] args= new String[] { fSearchString, "{0}", fScope.getDescription() };
- String format= "{0} - {1} match in {2}";
+ String[] args= new String[] { fSearchString, "{0}", fScope.getDescription() }; //$NON-NLS-1$
+ String format= "{0} - {1} match in {2}"; //$NON-NLS-1$
return MessageFormat.format(format, args);
}
+
+ /**
+ * @return
+ */
+ public IStatus searchInFile(final AbstractTextSearchResult result, final IProgressMonitor monitor, IFile file) {
+ ITextSearchResultCollector collector= new ITextSearchResultCollector() {
+ public IProgressMonitor getProgressMonitor() {
+ return monitor;
+ }
+
+ public void aboutToStart() {
+ // do nothing
+ }
+
+ public void accept(IResourceProxy proxy, String line, int start, int length, int lineNumber) {
+ IResource resource= proxy.requestResource();
+ if (start < 0)
+ start= 0;
+ if (length < 0)
+ length= 0;
+ result.addMatch(new FileMatch((IFile) resource, start, length));
+ }
+
+ public void done() {
+ // do nothing
+ }
+ };
+ SearchScope scope= new SearchScope("", new IResource[] { file }); //$NON-NLS-1$
+ new TextSearchEngine().search(SearchPlugin.getWorkspace(), scope, collector, new MatchLocator(fSearchString, fSearchOptions));
+ return new Status(IStatus.OK, SearchPlugin.getDefault().getDescriptor().getUniqueIdentifier(), 0, "", null); //$NON-NLS-1$
+ }
}
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 484368c57..e51e28768 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
@@ -34,6 +34,7 @@ import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchSite;
@@ -45,6 +46,8 @@ import org.eclipse.search.internal.core.text.ITextSearchResultCollector;
import org.eclipse.search.internal.ui.Search;
import org.eclipse.search.internal.ui.SearchManager;
import org.eclipse.search.internal.ui.SearchMessages;
+import org.eclipse.search.internal.ui.SearchPlugin;
+import org.eclipse.search.internal.ui.SearchResultView;
import org.eclipse.search.internal.ui.SearchResultViewEntry;
import org.eclipse.search.internal.ui.util.ExceptionHandler;
@@ -135,7 +138,11 @@ import org.eclipse.search.internal.ui.util.ExceptionHandler;
}
private boolean askForResearch(List outOfDateEntries, List outOfSyncEntries) {
- SearchAgainConfirmationDialog dialog= new SearchAgainConfirmationDialog(fSite.getShell(), outOfSyncEntries, outOfDateEntries);
+ SearchResultView view= (SearchResultView) SearchPlugin.getSearchResultView();
+ ILabelProvider labelProvider= null;
+ if (view != null)
+ labelProvider= view.getLabelProvider();
+ SearchAgainConfirmationDialog dialog= new SearchAgainConfirmationDialog(fSite.getShell(), labelProvider, outOfSyncEntries, outOfDateEntries);
return dialog.open() == IDialogConstants.OK_ID;
}
@@ -167,6 +174,7 @@ import org.eclipse.search.internal.ui.util.ExceptionHandler;
}
public void aboutToStart() {
+ // nothing to do
}
public void accept(IResourceProxy proxy, String line, int start, int length, int lineNumber) throws CoreException {
@@ -183,6 +191,7 @@ import org.eclipse.search.internal.ui.util.ExceptionHandler;
}
public void done(){
+ // nothing to do
}
});
IStatus status = operation.getStatus();
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
new file mode 100644
index 000000000..4381dfa0c
--- /dev/null
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction2.java
@@ -0,0 +1,165 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.search.internal.ui.text;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+
+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.util.ExceptionHandler;
+
+/* package */ class ReplaceAction2 extends Action {
+
+ private IWorkbenchSite fSite;
+ private List fElements;
+ private FileSearchPage fPage;
+
+ public ReplaceAction2(FileSearchPage page, List elements) {
+ Assert.isNotNull(page);
+ fSite= page.getSite();
+ if (elements != null)
+ fElements= elements;
+ else
+ fElements= new ArrayList(0);
+ fPage= page;
+ setText(SearchMessages.getString("ReplaceAction.label_all")); //$NON-NLS-1$
+ setEnabled(!fElements.isEmpty());
+ }
+
+ public ReplaceAction2(FileSearchPage page, IStructuredSelection selection) {
+ fSite= page.getSite();
+ fPage= page;
+ setText(SearchMessages.getString("ReplaceAction.label_selected")); //$NON-NLS-1$
+ fElements= selection.toList();
+ setEnabled(!fElements.isEmpty());
+ }
+
+ private AbstractTextSearchResult getResult() {
+ return fPage.getInput();
+ }
+
+ public void run() {
+ if (validateResources((FileSearchQuery) getResult().getQuery())) {
+ ReplaceDialog2 dialog= new ReplaceDialog2(fSite.getShell(), fElements, fPage.internalGetViewer(), getResult());
+ dialog.open();
+ }
+ }
+
+ private boolean validateResources(final FileSearchQuery operation) {
+ final List outOfDateEntries= new ArrayList();
+ for (Iterator elements = fElements.iterator(); elements.hasNext();) {
+ IFile entry = (IFile) elements.next();
+ Match[] markers= getResult().getMatches(entry);
+ for (int i= 0; i < markers.length; i++) {
+ if (isOutOfDate((FileMatch)markers[i])) {
+ outOfDateEntries.add(entry);
+ break;
+ }
+ }
+ }
+
+ final List outOfSyncEntries= new ArrayList();
+ for (Iterator elements = fElements.iterator(); elements.hasNext();) {
+ IFile entry = (IFile) elements.next();
+ if (isOutOfSync(entry)) {
+ outOfSyncEntries.add(entry);
+ }
+ }
+
+ if (outOfDateEntries.size() > 0 || outOfSyncEntries.size() > 0) {
+ if (askForResearch(outOfDateEntries, outOfSyncEntries)) {
+ ProgressMonitorDialog pmd= new ProgressMonitorDialog(fSite.getShell());
+ try {
+ pmd.run(true, true, new WorkspaceModifyOperation(null) {
+ protected void execute(IProgressMonitor monitor) throws CoreException {
+ research(monitor, outOfDateEntries, operation);
+ }
+ });
+ return true;
+ } catch (InvocationTargetException e) {
+ ExceptionHandler.handle(e, fSite.getShell(), SearchMessages.getString("ReplaceAction.label"), SearchMessages.getString("ReplaceAction.research.error")); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (InterruptedException e) {
+ // canceled
+ }
+ }
+ return false;
+ }
+ return true;
+ }
+
+ private void research(IProgressMonitor monitor, List outOfDateEntries, FileSearchQuery operation) throws CoreException {
+ IStatus status= null;
+ for (Iterator elements = outOfDateEntries.iterator(); elements.hasNext();) {
+ IFile entry = (IFile) elements.next();
+ status = research(operation, monitor, entry);
+ if (status != null && !status.isOK()) {
+ throw new CoreException(status);
+ }
+ }
+ }
+
+ private boolean askForResearch(List outOfDateEntries, List outOfSyncEntries) {
+ SearchAgainConfirmationDialog dialog= new SearchAgainConfirmationDialog(fSite.getShell(), (ILabelProvider) fPage.internalGetViewer().getLabelProvider(), outOfSyncEntries, outOfDateEntries);
+ return dialog.open() == IDialogConstants.OK_ID;
+ }
+
+ private boolean isOutOfDate(FileMatch match) {
+
+ if (match.getCreationTimeStamp() != match.getFile().getModificationStamp())
+ return true;
+ ITextFileBufferManager bm= FileBuffers.getTextFileBufferManager();
+ ITextFileBuffer fb= bm.getTextFileBuffer(match.getFile().getFullPath());
+ if (fb != null && fb.isDirty())
+ return true;
+ return false;
+ }
+
+ private boolean isOutOfSync(IFile entry) {
+ return !entry.isSynchronized(IResource.DEPTH_ZERO);
+ }
+
+ private IStatus research(FileSearchQuery operation, final IProgressMonitor monitor, IFile entry) {
+ Match[] matches= getResult().getMatches(entry);
+ IStatus status= operation.searchInFile(getResult(), monitor, entry);
+ if (status == null || status.isOK()) {
+ for (int i= 0; i < matches.length; i++) {
+ getResult().removeMatch(matches[i]);
+ }
+ }
+ return status;
+ }
+
+}
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
new file mode 100644
index 000000000..1e2aef7d4
--- /dev/null
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceDialog2.java
@@ -0,0 +1,590 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.search.internal.ui.text;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.SubProgressMonitor;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.StructuredViewer;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
+
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IReusableEditor;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+import org.eclipse.search.ui.SearchUI;
+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.ExtendedDialogWindow;
+
+import org.eclipse.search2.internal.ui.InternalSearchUI;
+import org.eclipse.search2.internal.ui.text.PositionTracker;
+
+class ReplaceDialog2 extends ExtendedDialogWindow {
+
+ private abstract static class ReplaceOperation extends WorkspaceModifyOperation {
+ ReplaceOperation(IResource lock) {
+ super(lock);
+ }
+ ReplaceOperation() {
+ super();
+ }
+ public void execute(IProgressMonitor monitor) throws InvocationTargetException {
+ try {
+ doReplace(monitor);
+ } catch (BadLocationException e) {
+ throw new InvocationTargetException(e);
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ } catch (IOException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+
+ protected abstract void doReplace(IProgressMonitor pm) throws BadLocationException, CoreException, IOException;
+ }
+
+ // various widget related constants
+ private static final int REPLACE= IDialogConstants.CLIENT_ID + 1;
+ private static final int REPLACE_ALL_IN_FILE= IDialogConstants.CLIENT_ID + 2;
+ private static final int REPLACE_ALL= IDialogConstants.CLIENT_ID + 3;
+ private static final int SKIP= IDialogConstants.CLIENT_ID + 4;
+ private static final int SKIP_FILE= IDialogConstants.CLIENT_ID + 5;
+ private static final int SKIP_ALL= IDialogConstants.CLIENT_ID + 6;
+
+ // Widgets
+ private Text fTextField;
+ private Button fReplaceButton;
+ private Button fReplaceAllInFileButton;
+ private Button fReplaceAllButton;
+ private Button fSkipButton;
+ private Button fSkipFileButton;
+
+ private List fMarkers;
+ private boolean fSkipReadonly= false;
+
+ // reuse editors stuff
+ private IReusableEditor fEditor;
+ private AbstractTextSearchResult fSearchResult;
+ private StructuredViewer fViewer;
+
+ protected ReplaceDialog2(Shell parentShell, List entries, StructuredViewer viewer, AbstractTextSearchResult result) {
+ super(parentShell);
+ Assert.isNotNull(entries);
+ Assert.isNotNull(result);
+ fSearchResult= result;
+ fMarkers= new ArrayList();
+ fViewer= viewer;
+ initializeMarkers(entries);
+ }
+
+ private void initializeMarkers(List entries) {
+ for (Iterator elements= entries.iterator(); elements.hasNext(); ) {
+ Match[] matches= fSearchResult.getMatches(elements.next());
+ for (int i= 0; i < matches.length; i++) {
+ fMarkers.add(matches[i]);
+ }
+ }
+ }
+
+ // widget related stuff -----------------------------------------------------------
+ public void create() {
+ super.create();
+ Shell shell= getShell();
+ shell.setText(getDialogTitle());
+ gotoCurrentMarker();
+ enableButtons();
+ }
+
+ protected Control createPageArea(Composite parent) {
+ Composite result= new Composite(parent, SWT.NULL);
+ GridLayout layout= new GridLayout();
+ result.setLayout(layout);
+ layout.numColumns= 2;
+
+ layout.marginHeight =
+ convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+ layout.marginWidth =
+ convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+ layout.verticalSpacing =
+ convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
+ layout.horizontalSpacing =
+ convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+
+ initializeDialogUnits(result);
+
+ Label label= new Label(result, SWT.NONE);
+ label.setText(SearchMessages.getString("ReplaceDialog.replace_label")); //$NON-NLS-1$
+ Text clabel= new Text(result, SWT.BORDER);
+ clabel.setEnabled(false);
+ clabel.setText(((FileSearchQuery)fSearchResult.getQuery()).getSearchString());
+ GridData gd= new GridData(GridData.FILL_HORIZONTAL);
+ gd.widthHint= convertWidthInCharsToPixels(50);
+ clabel.setLayoutData(gd);
+
+
+ label= new Label(result, SWT.NONE);
+ label.setText(SearchMessages.getString("ReplaceDialog.with_label")); //$NON-NLS-1$
+ fTextField= new Text(result, SWT.BORDER);
+ gd= new GridData(GridData.FILL_HORIZONTAL);
+ gd.widthHint= convertWidthInCharsToPixels(50);
+ fTextField.setLayoutData(gd);
+ fTextField.setFocus();
+
+
+ new Label(result, SWT.NONE);
+ Button replaceWithRegex= new Button(result, SWT.CHECK);
+ replaceWithRegex.setText(SearchMessages.getString("ReplaceDialog.isRegex.label")); //$NON-NLS-1$
+ replaceWithRegex.setEnabled(false);
+ replaceWithRegex.setSelection(false);
+
+ applyDialogFont(result);
+ return result;
+ }
+
+ protected void createButtonsForButtonBar(Composite parent) {
+ fReplaceButton= createButton(parent, REPLACE, SearchMessages.getString("ReplaceDialog.replace"), true); //$NON-NLS-1$
+ fReplaceAllInFileButton= createButton(parent, REPLACE_ALL_IN_FILE, SearchMessages.getString("ReplaceDialog.replaceAllInFile"), false); //$NON-NLS-1$
+
+ Label filler= new Label(parent, SWT.NONE);
+ filler.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
+
+ fReplaceAllButton= createButton(parent, REPLACE_ALL, SearchMessages.getString("ReplaceDialog.replaceAll"), false); //$NON-NLS-1$
+ fSkipButton= createButton(parent, SKIP, SearchMessages.getString("ReplaceDialog.skip"), false); //$NON-NLS-1$
+ fSkipFileButton= createButton(parent, SKIP_FILE, SearchMessages.getString("ReplaceDialog.skipFile"), false); //$NON-NLS-1$
+
+ filler= new Label(parent, SWT.NONE);
+ filler.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
+ super.createButtonsForButtonBar(parent);
+ ((GridLayout)parent.getLayout()).numColumns= 4;
+ }
+
+ private void enableButtons() {
+ fSkipButton.setEnabled(hasNextMarker());
+ fSkipFileButton.setEnabled(hasNextFile());
+ fReplaceButton.setEnabled(canReplace());
+ fReplaceAllInFileButton.setEnabled(canReplace());
+ fReplaceAllButton.setEnabled(canReplace());
+ }
+
+ protected void buttonPressed(int buttonId) {
+ final String replaceText= fTextField.getText();
+ try {
+ switch (buttonId) {
+ case SKIP :
+ skip();
+ break;
+ case SKIP_FILE :
+ skipFile();
+ break;
+ case REPLACE :
+ run(false, true, new ReplaceOperation((IResource) getCurrentMarker().getElement()) {
+ protected void doReplace(IProgressMonitor pm) throws BadLocationException, CoreException {
+ replace(pm, replaceText);
+ }
+ });
+ if (hasNextMarker())
+ gotoCurrentMarker();
+ break;
+ case REPLACE_ALL_IN_FILE :
+ run(false, true, new ReplaceOperation((IResource) getCurrentMarker().getElement()) {
+ protected void doReplace(IProgressMonitor pm) throws BadLocationException, CoreException {
+ replaceInFile(pm, replaceText);
+
+ }
+ });
+ if (hasNextFile())
+ gotoCurrentMarker();
+ break;
+ case REPLACE_ALL :
+ run(false, true, new ReplaceOperation() {
+ protected void doReplace(IProgressMonitor pm) throws BadLocationException, CoreException {
+ replaceAll(pm, replaceText);
+ }
+ });
+ if (hasNextFile())
+ gotoCurrentMarker();
+ break;
+ default :
+ {
+ super.buttonPressed(buttonId);
+ return;
+ }
+ }
+ } catch (InvocationTargetException e) {
+ SearchPlugin.log(e);
+ String message= SearchMessages.getFormattedString("ReplaceDialog.error.unable_to_replace", ((IFile)getCurrentMarker().getElement()).getName()); //$NON-NLS-1$
+ MessageDialog.openError(getParentShell(), getDialogTitle(), message);
+ } catch (InterruptedException e) {
+ // means operation canceled
+ }
+ if (!hasNextMarker() && !hasNextFile() && !canReplace())
+ close();
+ else {
+ enableButtons();
+ }
+ }
+
+ private Match getCurrentMarker() {
+ return (Match)fMarkers.get(0);
+ }
+
+ private void replace(IProgressMonitor pm, String replacementText) throws BadLocationException, CoreException {
+ Match marker= getCurrentMarker();
+ pm.beginTask(SearchMessages.getString("ReplaceDialog.task.replace"), 10); //$NON-NLS-1$
+ replaceInFile(pm, (IFile) marker.getElement(), replacementText, new Match[]{marker});
+ }
+
+ private void replaceInFile(IProgressMonitor pm, String replacementText) throws BadLocationException, CoreException {
+ Match firstMarker= getCurrentMarker();
+ Match[] markers= collectMarkers((IFile)firstMarker.getElement());
+ pm.beginTask(SearchMessages.getFormattedString("ReplaceDialog.task.replaceInFile", ((IFile)firstMarker.getElement()).getFullPath().toOSString()), 4); //$NON-NLS-1$
+ replaceInFile(pm, (IFile) firstMarker.getElement(), replacementText, markers);
+ }
+
+ private void replaceAll(IProgressMonitor pm, String replacementText) throws BadLocationException, CoreException {
+ int resourceCount= countResources();
+ pm.beginTask(SearchMessages.getString("ReplaceDialog.task.replace.replaceAll"), resourceCount); //$NON-NLS-1$
+ while (fMarkers.size() > 0) {
+ replaceInFile(new SubProgressMonitor(pm, 1, 0), replacementText);
+ }
+ pm.done();
+ }
+
+ private void replaceInFile(final IProgressMonitor pm, final IFile file, final String replacementText, final Match[] markers) throws BadLocationException, CoreException {
+ if (pm.isCanceled())
+ throw new OperationCanceledException();
+ doReplaceInFile(pm, file, replacementText, markers);
+ }
+
+ private void doReplaceInFile(IProgressMonitor pm, IFile file, String replacementText, final Match[] markers) throws BadLocationException, CoreException {
+ try {
+ if (file.isReadOnly()) {
+ file.getWorkspace().validateEdit(new IFile[]{file}, null);
+ }
+ if (file.isReadOnly()) {
+ if (fSkipReadonly) {
+ skipFile();
+ return;
+ }
+ int rc= askForSkip(file);
+ switch (rc) {
+ case CANCEL :
+ throw new OperationCanceledException();
+ case SKIP_FILE :
+ skipFile();
+ return;
+ case SKIP_ALL :
+ fSkipReadonly= true;
+ skipFile();
+ return;
+ }
+ }
+ ITextFileBufferManager bm= FileBuffers.getTextFileBufferManager();
+ try {
+ bm.connect(file.getFullPath(), new SubProgressMonitor(pm, 1));
+ ITextFileBuffer fb= bm.getTextFileBuffer(file.getFullPath());
+ boolean wasDirty= fb.isDirty();
+ IDocument doc= fb.getDocument();
+ for (int i= 0; i < markers.length; i++) {
+ PositionTracker tracker= InternalSearchUI.getInstance().getPositionTracker();
+ int offset= markers[i].getOffset();
+ int length= markers[i].getLength();
+ Position currentPosition= tracker.getCurrentPosition(markers[i]);
+ if (currentPosition != null) {
+ offset= currentPosition.offset;
+ length= currentPosition.length;
+ }
+ doc.replace(offset, length, replacementText);
+ fMarkers.remove(0);
+ fSearchResult.removeMatch(markers[i]);
+ }
+ if (!wasDirty)
+ fb.commit(new SubProgressMonitor(pm, 1), true);
+ } finally {
+ bm.disconnect(file.getFullPath(), new SubProgressMonitor(pm, 1));
+ }
+ } finally {
+ pm.done();
+ }
+ }
+
+ private int askForSkip(final IFile file) {
+
+ String message= SearchMessages.getFormattedString("ReadOnlyDialog.message", file.getFullPath().toOSString()); //$NON-NLS-1$
+ String[] buttonLabels= null;
+ boolean showSkip= countResources() > 1;
+ if (showSkip) {
+ String skipLabel= SearchMessages.getString("ReadOnlyDialog.skipFile"); //$NON-NLS-1$
+ String skipAllLabel= SearchMessages.getString("ReadOnlyDialog.skipAll"); //$NON-NLS-1$
+ buttonLabels= new String[]{skipLabel, skipAllLabel, IDialogConstants.CANCEL_LABEL};
+ } else {
+ buttonLabels= new String[]{IDialogConstants.CANCEL_LABEL};
+
+ }
+
+ MessageDialog msd= new MessageDialog(getShell(), getShell().getText(), null, message, MessageDialog.ERROR, buttonLabels, 0);
+ int rc= msd.open();
+ switch (rc) {
+ case 0 :
+ return showSkip ? SKIP_FILE : CANCEL;
+ case 1 :
+ return SKIP_ALL;
+ default :
+ return CANCEL;
+ }
+ }
+
+ private String getDialogTitle() {
+ return SearchMessages.getString("ReplaceDialog.dialog.title"); //$NON-NLS-1$
+ }
+
+ private void skip() {
+ fMarkers.remove(0);
+ Assert.isTrue(fMarkers.size() > 0);
+ gotoCurrentMarker();
+ }
+
+ private void skipFile() {
+ Match currentMarker= getCurrentMarker();
+ if (currentMarker == null)
+ return;
+ IResource currentFile= (IResource) currentMarker.getElement();
+ while (fMarkers.size() > 0 && getCurrentMarker().getElement().equals(currentFile))
+ fMarkers.remove(0);
+ if (fMarkers.size() > 0)
+ gotoCurrentMarker();
+ }
+
+ private void gotoCurrentMarker() {
+ if (fMarkers.size() > 0) {
+ Match marker= getCurrentMarker();
+ Control focusControl= getShell().getDisplay().getFocusControl();
+ try {
+ selectEntry(marker);
+ ITextEditor editor= null;
+ if (SearchUI.reuseEditor())
+ editor= openEditorReuse(marker);
+ else
+ editor= openEditorNoReuse(marker);
+ editor.selectAndReveal(marker.getOffset(), marker.getLength());
+ if (focusControl != null && !focusControl.isDisposed())
+ focusControl.setFocus();
+ } catch (PartInitException e) {
+ String message= SearchMessages.getFormattedString("ReplaceDialog.error.unable_to_open_text_editor", ((IFile)marker.getElement()).getName()); //$NON-NLS-1$
+ MessageDialog.openError(getParentShell(), getDialogTitle(), message);
+ }
+ }
+ }
+
+ private void selectEntry(Match marker) {
+ ISelection sel= fViewer.getSelection();
+ if (!(sel instanceof IStructuredSelection))
+ return;
+ IStructuredSelection ss= (IStructuredSelection) sel;
+ IFile file= (IFile) marker.getElement();
+ if (ss.size() == 1 && file.equals(ss.getFirstElement()))
+ return;
+ fViewer.setSelection(new StructuredSelection(marker.getElement()));
+ }
+
+ // opening editors ------------------------------------------
+ private ITextEditor openEditorNoReuse(Match marker) throws PartInitException {
+ IFile file= (IFile) marker.getElement();
+ IWorkbenchPage activePage= SearchPlugin.getActivePage();
+ if (activePage == null)
+ return null;
+ ITextEditor textEditor= showOpenTextEditor(activePage, file);
+ if (textEditor != null)
+ return textEditor;
+ return openNewTextEditor(file, activePage);
+ }
+
+ private ITextEditor openNewTextEditor(IFile file, IWorkbenchPage activePage) throws PartInitException {
+ IEditorDescriptor desc= IDE.getDefaultEditor(file);
+ if (desc != null) {
+ String editorID= desc.getId();
+ IEditorPart editor;
+ if (desc.isInternal()) {
+ editor= activePage.openEditor(new FileEditorInput(file), editorID);
+ if (editor instanceof ITextEditor) {
+ if (editor instanceof IReusableEditor)
+ fEditor= (IReusableEditor) editor;
+ return (ITextEditor)editor;
+ } else
+ activePage.closeEditor(editor, false);
+ }
+ }
+ IEditorPart editor= activePage.openEditor(new FileEditorInput(file), "org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$
+ return (ITextEditor)editor;
+ }
+
+ private ITextEditor openEditorReuse(Match marker) throws PartInitException {
+ IWorkbenchPage page= SearchPlugin.getActivePage();
+ IFile file= (IFile) marker.getElement();
+ if (page == null)
+ return null;
+
+ ITextEditor textEditor= showOpenTextEditor(page, file);
+ if (textEditor != null)
+ return textEditor;
+
+ String editorId= null;
+ IEditorDescriptor desc= IDE.getDefaultEditor(file);
+ if (desc != null && desc.isInternal())
+ editorId= desc.getId();
+
+ boolean isOpen= isEditorOpen(page, fEditor);
+
+ boolean canBeReused= isOpen && !fEditor.isDirty() && !isPinned(fEditor);
+ boolean showsSameInputType= fEditor != null && (editorId == null || fEditor.getSite().getId().equals(editorId));
+
+ if (canBeReused) {
+ if (showsSameInputType) {
+ fEditor.setInput(new FileEditorInput(file));
+ page.bringToTop(fEditor);
+ return (ITextEditor) fEditor;
+ } else {
+ page.closeEditor(fEditor, false);
+ fEditor= null;
+ }
+ }
+ return openNewTextEditor(file, page);
+ }
+
+ private boolean isEditorOpen(IWorkbenchPage page, IEditorPart editor) {
+ if (editor != null) {
+ IEditorReference[] parts= page.getEditorReferences();
+ int i= 0;
+ for (int j = 0; j < parts.length; j++) {
+ if (editor == parts[i++].getEditor(false))
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private ITextEditor showOpenTextEditor(IWorkbenchPage page, IFile file) {
+ IEditorPart editor= page.findEditor(new FileEditorInput(file));
+ if (editor instanceof ITextEditor) {
+ page.bringToTop(editor);
+ return (ITextEditor) editor;
+ }
+ return null;
+ }
+
+ private boolean isPinned(IEditorPart editor) {
+ if (editor == null)
+ return false;
+
+ IEditorReference[] editorRefs= editor.getEditorSite().getPage().getEditorReferences();
+ int i= 0;
+ while (i < editorRefs.length) {
+ if (editor.equals(editorRefs[i].getEditor(false)))
+ return editorRefs[i].isPinned();
+ i++;
+ }
+ return false;
+ }
+
+ // resource related -------------------------------------------------------------
+ /**
+ * @return the number of resources referred to in fMarkers
+ */
+ private int countResources() {
+ IResource r= null;
+ int count= 0;
+ for (Iterator elements= fMarkers.iterator(); elements.hasNext(); ) {
+ Match element= (Match)elements.next();
+ if (!element.getElement().equals(r)) {
+ count++;
+ r= (IResource) element.getElement();
+ }
+ }
+ return count;
+ }
+
+ private Match[] collectMarkers(IFile resource) {
+ List matching= new ArrayList();
+ for (int i= 0; i < fMarkers.size(); i++) {
+ Match marker= (Match)fMarkers.get(i);
+ if (!resource.equals(marker.getElement()))
+ break;
+ matching.add(marker);
+ }
+ Match[] markers= new Match[matching.size()];
+ return (Match[])matching.toArray(markers);
+ }
+
+
+ // some queries -------------------------------------------------------------
+ private boolean hasNextMarker() {
+ return fMarkers.size() > 1;
+ }
+
+ private boolean hasNextFile() {
+ if (!hasNextMarker())
+ return false;
+ IResource currentFile= (IResource) getCurrentMarker().getElement();
+ for (int i= 0; i < fMarkers.size(); i++) {
+ if (!((Match)fMarkers.get(i)).getElement().equals(currentFile))
+ return true;
+ }
+ return false;
+ }
+
+ private boolean canReplace() {
+ return fMarkers.size() > 0;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/SearchAgainConfirmationDialog.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/SearchAgainConfirmationDialog.java
index 22b2d5562..e3ef5c6ee 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/SearchAgainConfirmationDialog.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/SearchAgainConfirmationDialog.java
@@ -26,8 +26,6 @@ import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.search.internal.ui.SearchMessages;
-import org.eclipse.search.internal.ui.SearchPlugin;
-import org.eclipse.search.internal.ui.SearchResultView;
import org.eclipse.search.internal.ui.util.ListContentProvider;
/**
@@ -39,17 +37,10 @@ import org.eclipse.search.internal.ui.util.ListContentProvider;
public class SearchAgainConfirmationDialog extends Dialog {
private List fOutOfSync;
private List fOutOfDate;
+ private ILabelProvider fLabelProvider;
- private static class ProxyLabelProvider extends LabelProvider {
- private ILabelProvider fLabelProvider;
+ private class ProxyLabelProvider extends LabelProvider {
- ProxyLabelProvider() {
- SearchResultView view= (SearchResultView) SearchPlugin.getSearchResultView();
- if (view != null)
- fLabelProvider= view.getLabelProvider();
- else
- fLabelProvider= null;
- }
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
@@ -71,10 +62,11 @@ public class SearchAgainConfirmationDialog extends Dialog {
}
- SearchAgainConfirmationDialog(Shell shell, List outOfSync, List outOfDate) {
+ SearchAgainConfirmationDialog(Shell shell, ILabelProvider labelProvider, List outOfSync, List outOfDate) {
super(shell);
fOutOfSync= outOfSync;
fOutOfDate= outOfDate;
+ fLabelProvider= labelProvider;
setShellStyle(getShellStyle() | SWT.RESIZE);
}

Back to the top