diff --git a/bundles/org.eclipse.text.quicksearch/META-INF/MANIFEST.MF b/bundles/org.eclipse.text.quicksearch/META-INF/MANIFEST.MF index d656db96eda..dae450f163e 100644 --- a/bundles/org.eclipse.text.quicksearch/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.text.quicksearch/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.text.quicksearch;singleton:=true -Bundle-Version: 1.2.500.qualifier +Bundle-Version: 1.2.600.qualifier Bundle-Activator: org.eclipse.text.quicksearch.internal.ui.QuickSearchActivator Require-Bundle: org.eclipse.ui;bundle-version="[3.113.0,4.0.0)", org.eclipse.core.resources;bundle-version="[3.13.0,4.0.0)", diff --git a/bundles/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchDialog.java b/bundles/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchDialog.java index a2ddfbbef5b..532d255c4da 100644 --- a/bundles/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchDialog.java +++ b/bundles/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchDialog.java @@ -25,6 +25,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Deque; +import java.util.LinkedList; import java.util.List; import org.eclipse.core.commands.AbstractHandler; @@ -83,6 +85,7 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; @@ -296,13 +299,17 @@ public void update(ViewerCell cell) { private static final String DIALOG_SASH_WEIGHTS = "SASH_WEIGHTS"; //$NON-NLS-1$ private static final String DIALOG_LAST_QUERY = "LAST_QUERY"; //$NON-NLS-1$ - private static final String DIALOG_PATH_FILTER = "PATH_FILTER"; //$NON-NLS-1$ private static final String CASE_SENSITIVE = "CASE_SENSITIVE"; //$NON-NLS-1$ private static final boolean CASE_SENSITIVE_DEFAULT = true; private static final String KEEP_OPEN = "KEEP_OPEN"; //$NON-NLS-1$ private static final boolean KEEP_OPEN_DEFAULT = false; + private final Deque filterHistory = new LinkedList<>(); + + private static final int FILTER_HISTORY_SIZE = 5; + + private static final String FILTER_HISTORY = "FILTER_HISTORY"; //$NON-NLS-1$ /** * Represents an empty selection in the pattern input field (used only for * initial pattern). @@ -369,7 +376,7 @@ public void update(ViewerCell cell) { private Label headerLabel; private IWorkbenchWindow window; - private Text searchIn; + private Combo searchIn; private Label listLabel; /** @@ -417,8 +424,16 @@ protected void restoreDialog(IDialogSettings settings) { pattern.setText(lastSearch); pattern.selectAll(); } - if (settings.get(DIALOG_PATH_FILTER)!=null) { - String filter = settings.get(DIALOG_PATH_FILTER); + + // Retrieve the last locations where the user searched (works across restarts) + filterHistory.addAll(List.of(settings.getArray(FILTER_HISTORY))); + if (!filterHistory.isEmpty()) { + String filter = filterHistory.getFirst(); + + // Filter out blanks + filterHistory.removeIf(String::isBlank); + + searchIn.setItems(filterHistory.toArray(String[]::new)); searchIn.setText(filter); } @@ -452,6 +467,15 @@ protected void restoreDialog(IDialogSettings settings) { } } + private void inputNewSearchFilter(String searchIn) { + filterHistory.remove(searchIn); + filterHistory.addFirst(searchIn); + + if (filterHistory.size() > FILTER_HISTORY_SIZE) { + filterHistory.removeLast(); + } + } + private class ToggleKeepOpenAction extends Action { public ToggleKeepOpenAction(IDialogSettings settings) { super( @@ -533,7 +557,10 @@ public boolean close() { protected void storeDialog(IDialogSettings settings) { String currentSearch = pattern.getText(); settings.put(DIALOG_LAST_QUERY, currentSearch); - settings.put(DIALOG_PATH_FILTER, searchIn.getText()); + + inputNewSearchFilter(searchIn.getText()); + settings.put(FILTER_HISTORY, filterHistory.toArray(String[]::new)); + if (toggleCaseSensitiveAction!=null) { settings.put(CASE_SENSITIVE, toggleCaseSensitiveAction.isChecked()); } @@ -755,7 +782,7 @@ public void getName(AccessibleEvent e) { Label searchInLabel = new Label(searchInComposite, SWT.NONE); searchInLabel.setText(Messages.QuickSearchDialog_In); GridDataFactory.swtDefaults().indent(5, 0).applyTo(searchInLabel); - searchIn = new Text(searchInComposite, SWT.SINGLE | SWT.BORDER | SWT.ICON_CANCEL); + searchIn = new Combo(searchInComposite, SWT.SINGLE | SWT.BORDER | SWT.ICON_CANCEL); searchIn.setToolTipText(Messages.QuickSearchDialog_InTooltip); GridDataFactory.fillDefaults().grab(true, false).indent(5, 0).applyTo(searchIn);