Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDani Megert2002-09-12 10:46:17 +0000
committerDani Megert2002-09-12 10:46:17 +0000
commit4dc7613af5c182c7b47f5f16355e34c60efc578c (patch)
tree79d0a34c385d823f98916ec7bb85627929e959e6
parentd858c0b0dde7dd98f8f8d6b56b0916d71e863cd2 (diff)
downloadeclipse.platform.text-4dc7613af5c182c7b47f5f16355e34c60efc578c.tar.gz
eclipse.platform.text-4dc7613af5c182c7b47f5f16355e34c60efc578c.tar.xz
eclipse.platform.text-4dc7613af5c182c7b47f5f16355e34c60efc578c.zip
Added feature 23273: Search results needs openWith on context menu
-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/TextSearchResultCollector.java36
2 files changed, 37 insertions, 1 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 cf70b6c22..6acc39581 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
@@ -196,3 +196,5 @@ RemovePotentialMatchesAction.removePotentialMatches.text= Remove Inexact Matches
RemovePotentialMatchesAction.removePotentialMatches.tooltip= Remove all inexact matches
RemovePotentialMatchesAction.dialog.title= Remove Inexact Matches
RemovePotentialMatchesAction.dialog.message= The current search result does not contain inexact matches.
+
+OpenWithMenu.label= Open Wit&h \ No newline at end of file
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchResultCollector.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchResultCollector.java
index c8b297e54..7800fe6c9 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchResultCollector.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchResultCollector.java
@@ -8,12 +8,14 @@ import java.text.MessageFormat;
import java.util.HashMap;
import java.util.List;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.util.Assert;
import org.eclipse.jface.viewers.ISelectionProvider;
@@ -21,10 +23,15 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.actions.ActionGroup;
+import org.eclipse.ui.actions.OpenWithMenu;
import org.eclipse.search.ui.IActionGroupFactory;
+import org.eclipse.search.ui.IContextMenuConstants;
import org.eclipse.search.ui.ISearchResultView;
+import org.eclipse.search.ui.ISearchResultViewEntry;
import org.eclipse.search.ui.SearchUI;
import org.eclipse.search.internal.core.text.ITextSearchResultCollector;
@@ -55,15 +62,19 @@ public class TextSearchResultCollector implements ITextSearchResultCollector {
private class TextSearchActionGroup extends ActionGroup {
private ISelectionProvider fSelectionProvider;
+ private IWorkbenchPage fPage;
public TextSearchActionGroup(IViewPart part) {
Assert.isNotNull(part);
- fSelectionProvider= part.getSite().getSelectionProvider();
+ IWorkbenchPartSite site= part.getSite();
+ fSelectionProvider= site.getSelectionProvider();
+ fPage= site.getPage();
}
public void fillContextMenu(IMenuManager menu) {
if (!isTextSearch())
return;
+
// view must exist if we create a context menu for it.
ISearchResultView view= SearchUI.getSearchResultView();
IStructuredSelection selection= null;
@@ -71,6 +82,9 @@ public class TextSearchResultCollector implements ITextSearchResultCollector {
selection= (IStructuredSelection)getContext().getSelection();
else
selection= StructuredSelection.EMPTY;
+
+ addOpenWithMenu(menu, selection);
+
ReplaceAction replaceAll= new ReplaceAction(view.getSite(), (List)getContext().getInput());
if (replaceAll.isEnabled())
menu.add(replaceAll);
@@ -87,6 +101,26 @@ public class TextSearchResultCollector implements ITextSearchResultCollector {
}
return false;
}
+
+ private void addOpenWithMenu(IMenuManager menu, IStructuredSelection selection) {
+ if (selection == null || selection.size() != 1)
+ return;
+
+ Object o= selection.getFirstElement();
+ if (!(o instanceof ISearchResultViewEntry))
+ return;
+
+ Object resource= ((ISearchResultViewEntry)o).getResource();
+ if (!(resource instanceof IFile))
+ return;
+
+ // Create a menu flyout.
+ IMenuManager submenu= new MenuManager(SearchMessages.getString("OpenWithMenu.label")); //$NON-NLS-1$
+ submenu.add(new OpenWithMenu(fPage, (IFile)resource));
+
+ // Add the submenu.
+ menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu);
+ }
}
/**

Back to the top