Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2019-09-23 15:32:04 +0000
committerMickael Istria2019-10-14 08:21:43 +0000
commit4252e53c7d5373092cacd6128d39cea35618b21e (patch)
tree38a03a903b151cb8714f96a0ec2ddbab607284d3
parent8df6b9afc574d825dba07a5c9d1019c7cef88929 (diff)
downloadeclipse.platform.text-4252e53c7d5373092cacd6128d39cea35618b21e.tar.gz
eclipse.platform.text-4252e53c7d5373092cacd6128d39cea35618b21e.tar.xz
eclipse.platform.text-4252e53c7d5373092cacd6128d39cea35618b21e.zip
Bug 551970 - Quick Test Search directly in Find Actions/Ctrl+3
Change-Id: I6d1f08938fc1a0903349f8d93fe19f9a0a399bb8 Signed-off-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--org.eclipse.text.quicksearch/plugin.properties1
-rw-r--r--org.eclipse.text.quicksearch/plugin.xml8
-rw-r--r--org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/core/QuickTextSearcher.java2
-rw-r--r--org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/Messages.java1
-rw-r--r--org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchQuickAccessComputer.java118
-rw-r--r--org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/messages.properties3
6 files changed, 131 insertions, 2 deletions
diff --git a/org.eclipse.text.quicksearch/plugin.properties b/org.eclipse.text.quicksearch/plugin.properties
index 35b84c918..1e5d5466c 100644
--- a/org.eclipse.text.quicksearch/plugin.properties
+++ b/org.eclipse.text.quicksearch/plugin.properties
@@ -17,3 +17,4 @@ searchMenu.label= Se&arch
quickSearch.label= Quick Search
quickSearch.ellipsis= &Quick Search...
quickSearch.tooltip=Search for a text pattern in the workspace
+quickAccess.category.label=File content
diff --git a/org.eclipse.text.quicksearch/plugin.xml b/org.eclipse.text.quicksearch/plugin.xml
index c46b2c7f7..40f76acfa 100644
--- a/org.eclipse.text.quicksearch/plugin.xml
+++ b/org.eclipse.text.quicksearch/plugin.xml
@@ -107,5 +107,13 @@
name="%quickSearch.label">
</page>
</extension>
+ <extension
+ point="org.eclipse.ui.quickAccess">
+ <computer
+ class="org.eclipse.text.quicksearch.internal.ui.QuickSearchQuickAccessComputer"
+ name="%quickAccess.category.label"
+ requiresUIAccess="false">
+ </computer>
+ </extension>
</plugin>
diff --git a/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/core/QuickTextSearcher.java b/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/core/QuickTextSearcher.java
index 2fd13aab3..0fc64840e 100644
--- a/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/core/QuickTextSearcher.java
+++ b/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/core/QuickTextSearcher.java
@@ -308,7 +308,7 @@ public class QuickTextSearcher {
//Walker can be null if job was canceled because dialog closed. But stuff like
//the job that shows 'Searching ...' doesn't instantly stop and may still
//be asking the incremental update job whether its done.
- return walker!=null && walker.isDone();
+ return /*(incrementalUpdate != null && incrementalUpdate.getState() != Job.NONE) ||*/ (walker!=null && walker.isDone());
}
public void requestMoreResults() {
diff --git a/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/Messages.java b/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/Messages.java
index 7f92dfc60..7a22ba63d 100644
--- a/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/Messages.java
+++ b/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/Messages.java
@@ -40,6 +40,7 @@ public class Messages extends NLS {
public static String QuickSearchDialog_caseInsensitive_label;
public static String QuickSearchDialog_patternHint;
public static String QuickTextSearch_updateMatchesJob;
+ public static String quickAccessMatch;
static {
// initialize resource bundle
diff --git a/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchQuickAccessComputer.java b/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchQuickAccessComputer.java
new file mode 100644
index 000000000..96ca299a9
--- /dev/null
+++ b/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchQuickAccessComputer.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Red Hat Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+package org.eclipse.text.quicksearch.internal.ui;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.text.quicksearch.internal.core.LineItem;
+import org.eclipse.text.quicksearch.internal.core.QuickTextQuery;
+import org.eclipse.text.quicksearch.internal.core.QuickTextSearchRequestor;
+import org.eclipse.text.quicksearch.internal.core.QuickTextSearcher;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.quickaccess.IQuickAccessComputer;
+import org.eclipse.ui.quickaccess.IQuickAccessComputerExtension;
+import org.eclipse.ui.quickaccess.QuickAccessElement;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+public class QuickSearchQuickAccessComputer extends QuickTextSearchRequestor implements IQuickAccessComputer, IQuickAccessComputerExtension {
+
+ private static final int MAX_ENTRIES = 20;
+ private QuickSearchContext context;
+
+ public QuickSearchQuickAccessComputer() {
+ context = new QuickSearchContext(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
+ }
+
+ @Override public QuickAccessElement[] computeElements(String query, IProgressMonitor monitor) {
+ List<LineItem> matches = Collections.synchronizedList(new ArrayList<>());
+ QuickTextSearcher searcher = new QuickTextSearcher(new QuickTextQuery("", false), context.createPriorityFun(), 100, new QuickTextSearchRequestor() { //$NON-NLS-1$
+ @Override public void add(LineItem match) {
+ matches.add(match);
+ }
+
+ @Override public void clear() {
+ matches.clear();
+ }
+
+ @Override public void revoke(LineItem line) {
+ matches.remove(line);
+ }
+ });
+ searcher.setMaxResults(MAX_ENTRIES);
+ searcher.setQuery(new QuickTextQuery(query, false), true);
+ long start = System.currentTimeMillis();
+ while (matches.size() < 20 && !searcher.isDone() && System.currentTimeMillis() - start < 3000) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ QuickSearchActivator.log(e);
+ }
+ }
+ searcher.cancel();
+ return matches.stream().map(LineItemQuickAccessElement::new).toArray(QuickAccessElement[]::new);
+ }
+
+ @Override public QuickAccessElement[] computeElements() {
+ return new QuickAccessElement[0];
+ }
+
+ @Override public void resetState() {
+ // stateless
+
+ }
+
+ @Override public boolean needsRefresh() {
+ return false;
+ }
+
+ private class LineItemQuickAccessElement extends QuickAccessElement {
+
+ private final LineItem item;
+
+ public LineItemQuickAccessElement(LineItem item) {
+ this.item = item;
+ }
+
+ @Override public String getLabel() {
+ return NLS.bind(Messages.quickAccessMatch, item.getText(), item.getFile().getName());
+ }
+
+ @Override public ImageDescriptor getImageDescriptor() {
+ return null;
+ }
+
+ @Override public String getId() {
+ return item.getFile().getFullPath().toString() + '[' + item.getOffset() + ':' + (item.getOffset() + item.getText().length() - 1) + ']';
+ }
+
+ @Override public void execute() {
+ IEditorPart part;
+ try {
+ part = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), item.getFile());
+ if (part instanceof ITextEditor) {
+ ((ITextEditor) part).getSelectionProvider().setSelection(new TextSelection(item.getOffset(), item.getText().length()));
+ }
+ } catch (PartInitException e) {
+ QuickSearchActivator.log(e);
+ }
+ }
+
+ }
+
+}
diff --git a/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/messages.properties b/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/messages.properties
index 5b5c8f768..7166b95d7 100644
--- a/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/messages.properties
+++ b/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/messages.properties
@@ -21,4 +21,5 @@ QuickSearchDialog_title=Quick Search
QuickSearchDialog_caseSensitive_label=Case SENSITIVE
QuickSearchDialog_caseInsensitive_label=Case INSENSITIVE
QuickSearchDialog_patternHint=&Pattern (? = any character, * = any string)
-QuickTextSearch_updateMatchesJob=Update matches \ No newline at end of file
+QuickTextSearch_updateMatchesJob=Update matches
+quickAccessMatch=`{0}` in {1} \ No newline at end of file

Back to the top