Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucas Bullen2017-11-10 08:19:49 -0500
committerDani Megert2017-11-20 11:15:41 -0500
commit10309832835db0363c75027e116d47c7028459c3 (patch)
treec3ac57e2575472aac49e4443fd0b63b68d37665b
parent6758b1974631342370488a9a781e6b30b528c5ae (diff)
downloadeclipse.platform.text-10309832835db0363c75027e116d47c7028459c3.tar.gz
eclipse.platform.text-10309832835db0363c75027e116d47c7028459c3.tar.xz
eclipse.platform.text-10309832835db0363c75027e116d47c7028459c3.zip
Bug 526453 - [Search Dialog] disambiguate "Selected Resources"I20171121-0020I20171120-2225I20171120-2000
Button labeling scenarios: {0} selected resources in '<view>' - multiple resources selected in a view Selected resource in '<view>' - one resource selected in a view Resource in selected editor - focused on an editor Selected resources - no selection {0} enclosing projects - multiple enclosing projects Enclosing project - one enclosing project Enclosing projects - else Change-Id: I4e169bbb674a6fded056e75703a71ccf86264d62 Signed-off-by: Lucas Bullen <lbullen@redhat.com>
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java34
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.java4
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.properties12
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java10
4 files changed, 33 insertions, 27 deletions
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java
index 6f8f2b005..9070c84c4 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -38,6 +38,7 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.dialogs.IDialogSettings;
@@ -159,11 +160,17 @@ public class ScopePart {
return null;
}
- public static List<IResource> selectionToResources(ISelection selection) {
- if (selection == null || !(selection instanceof IStructuredSelection)) {
+ public static List<IResource> selectedResourcesFromContainer(ISearchPageContainer container) {
+ if (container == null)
return Collections.emptyList();
- }
+ ISelection selection = container.getSelection();
List<IResource> resources = new ArrayList<>();
+ if (!(selection instanceof IStructuredSelection) || selection.isEmpty()) {
+ if (container.getActiveEditorInput() != null) {
+ resources.add(container.getActiveEditorInput().getAdapter(IFile.class));
+ }
+ return resources;
+ }
Iterator<?> iter = ((IStructuredSelection) selection).iterator();
while (iter.hasNext()) {
Object curr = iter.next();
@@ -194,20 +201,23 @@ public class ScopePart {
}
private String getSelectedResurcesButtonText() {
- List<IResource> resources = selectionToResources(fSearchDialog.getSelection());
- int size = resources.size();
- if (size == 1)
- return NLS.bind(SearchMessages.ScopePart_selectedResourcesScope_text_singular, resources.get(0).getName());
+ int size = selectedResourcesFromContainer(fSearchDialog).size();
+ if (size == 1) {
+ if (fSearchDialog.getActiveEditor() != null)
+ return SearchMessages.ScopePart_selectedResourcesScope_text_editor;
+ return NLS.bind(SearchMessages.ScopePart_selectedResourcesScope_text_singular,
+ fSearchDialog.getWorkbenchWindow().getActivePage().getActivePart().getTitle());
+ }
if (size > 1)
- return NLS.bind(SearchMessages.ScopePart_selectedResourcesScope_text_plural, new Integer(size));
+ return NLS.bind(SearchMessages.ScopePart_selectedResourcesScope_text_plural, new Integer(size),
+ fSearchDialog.getWorkbenchWindow().getActivePage().getActivePart().getTitle());
return SearchMessages.ScopePart_selectedResourcesScope_text;
}
private String getEnclosingProjectsButtonText() {
- String[] projectNames = fSearchDialog.getEnclosingProjectNames();
- int size = projectNames.length;
+ int size = fSearchDialog.getEnclosingProjectNames().length;
if (size == 1)
- return NLS.bind(SearchMessages.ScopePart_enclosingProjectsScope_text_singular, projectNames[0]);
+ return SearchMessages.ScopePart_enclosingProjectsScope_text_singular;
if (size > 1)
return NLS.bind(SearchMessages.ScopePart_enclosingProjectsScope_text_plural, new Integer(size));
return SearchMessages.ScopePart_enclosingProjectsScope_text;
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.java
index 19483966e..dee72a6b2 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
* Christian Walther (Indel AG) - Bug 399094: Add whole word option to file search
* Marco Descher <marco@descher.at> - Open Search dialog with previous page instead of using the current selection to detect the page - http://bugs.eclipse.org/33710
+ * Lucas Bullen (Red Hat Inc.) - [Bug 526453] disambiguate "Selected Resources"
*******************************************************************************/
package org.eclipse.search.internal.ui;
@@ -175,6 +176,7 @@ public final class SearchMessages extends NLS {
public static String ScopePart_selectedResourcesScope_text;
public static String ScopePart_selectedResourcesScope_text_plural;
public static String ScopePart_selectedResourcesScope_text_singular;
+ public static String ScopePart_selectedResourcesScope_text_editor;
public static String ScopePart_enclosingProjectsScope_text;
public static String ScopePart_enclosingProjectsScope_text_plural;
public static String ScopePart_enclosingProjectsScope_text_singular;
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 4c4e36395..925fa2865 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
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2000, 2015 IBM Corporation and others.
+# Copyright (c) 2000, 2017 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
# IBM Corporation - initial API and implementation
# Christian Walther (Indel AG) - Bug 399094: Add whole word option to file search
# Marco Descher <marco@descher.at> - Open Search dialog with previous page instead of using the current selection to detect the page - http://bugs.eclipse.org/33710
+# Lucas Bullen (Red Hat Inc.) - [Bug 526453] disambiguate "Selected Resources"
###############################################################################
SearchDialog_title= Search
@@ -181,11 +182,12 @@ WorkspaceScope= workspace
ScopePart_group_text= Scope
ScopePart_selectedResourcesScope_text=Selecte&d resources
-ScopePart_selectedResourcesScope_text_plural={0} Selecte&d resources
-ScopePart_selectedResourcesScope_text_singular=Selecte&d "{0}" resource
+ScopePart_selectedResourcesScope_text_plural={0} selecte&d resources in ''{1}''
+ScopePart_selectedResourcesScope_text_singular=Selecte&d resource in ''{0}''
+ScopePart_selectedResourcesScope_text_editor=Resource in active e&ditor
ScopePart_enclosingProjectsScope_text=Enclosing pro&jects
-ScopePart_enclosingProjectsScope_text_plural={0} Enclosing pro&jects
-ScopePart_enclosingProjectsScope_text_singular=Enclosing "{0}" pro&ject
+ScopePart_enclosingProjectsScope_text_plural={0} enclosing pro&jects
+ScopePart_enclosingProjectsScope_text_singular=Enclosing pro&ject
ScopePart_workingSetChooseButton_text= C&hoose...
ScopePart_workingSetText_accessible_label=Working set name
ScopePart_workingSetScope_text=Wor&king set:
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java
index fd46d7723..21e3f295e 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java
@@ -55,7 +55,6 @@ import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.fieldassist.ComboContentAdapter;
import org.eclipse.jface.resource.JFaceColors;
import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider;
@@ -336,14 +335,7 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP
}
private FileTextSearchScope getSelectedResourcesScope() {
- HashSet<IResource> resources= new HashSet<>();
- ISelection sel= getContainer().getSelection();
- if (sel instanceof IStructuredSelection && !sel.isEmpty()) {
- resources.addAll(ScopePart.selectionToResources(sel));
- } else if (getContainer().getActiveEditorInput() != null) {
- resources.add(getContainer().getActiveEditorInput().getAdapter(IFile.class));
- }
- IResource[] arr= resources.toArray(new IResource[resources.size()]);
+ IResource[] arr = ScopePart.selectedResourcesFromContainer(getContainer()).toArray(new IResource[0]);
return FileTextSearchScope.newSearchScope(arr, getExtensions(), fSearchDerived);
}

Back to the top