Skip to content

Commit 6c8df42

Browse files
Drop Down menu in Quick Search implemented
Fixes #2329 Co-authored-by: Federico Jeanne <[email protected]>
1 parent 0344b2b commit 6c8df42

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

bundles/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchDialog.java

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.util.ArrayList;
2626
import java.util.Arrays;
2727
import java.util.Collections;
28+
import java.util.Deque;
29+
import java.util.LinkedList;
2830
import java.util.List;
2931

3032
import org.eclipse.core.commands.AbstractHandler;
@@ -83,6 +85,7 @@
8385
import org.eclipse.swt.layout.GridData;
8486
import org.eclipse.swt.layout.GridLayout;
8587
import org.eclipse.swt.widgets.Button;
88+
import org.eclipse.swt.widgets.Combo;
8689
import org.eclipse.swt.widgets.Composite;
8790
import org.eclipse.swt.widgets.Control;
8891
import org.eclipse.swt.widgets.Display;
@@ -296,13 +299,17 @@ public void update(ViewerCell cell) {
296299
private static final String DIALOG_SASH_WEIGHTS = "SASH_WEIGHTS"; //$NON-NLS-1$
297300

298301
private static final String DIALOG_LAST_QUERY = "LAST_QUERY"; //$NON-NLS-1$
299-
private static final String DIALOG_PATH_FILTER = "PATH_FILTER"; //$NON-NLS-1$
300302
private static final String CASE_SENSITIVE = "CASE_SENSITIVE"; //$NON-NLS-1$
301303
private static final boolean CASE_SENSITIVE_DEFAULT = true;
302304

303305
private static final String KEEP_OPEN = "KEEP_OPEN"; //$NON-NLS-1$
304306
private static final boolean KEEP_OPEN_DEFAULT = false;
305307

308+
private final Deque<String> filterHistory = new LinkedList<>();
309+
310+
private static final int FILTER_HISTORY_SIZE = 5;
311+
312+
private static final String FILTER_HISTORY = "FILTER_HISTORY"; //$NON-NLS-1$
306313
/**
307314
* Represents an empty selection in the pattern input field (used only for
308315
* initial pattern).
@@ -369,7 +376,7 @@ public void update(ViewerCell cell) {
369376
private Label headerLabel;
370377

371378
private IWorkbenchWindow window;
372-
private Text searchIn;
379+
private Combo searchIn;
373380
private Label listLabel;
374381

375382
/**
@@ -417,8 +424,16 @@ protected void restoreDialog(IDialogSettings settings) {
417424
pattern.setText(lastSearch);
418425
pattern.selectAll();
419426
}
420-
if (settings.get(DIALOG_PATH_FILTER)!=null) {
421-
String filter = settings.get(DIALOG_PATH_FILTER);
427+
428+
// Retrieve the last locations where the user searched (works across restarts)
429+
filterHistory.addAll(List.of(settings.getArray(FILTER_HISTORY)));
430+
if (!filterHistory.isEmpty()) {
431+
String filter = filterHistory.getFirst();
432+
433+
// Filter out blanks
434+
filterHistory.removeIf(String::isBlank);
435+
436+
searchIn.setItems(filterHistory.toArray(String[]::new));
422437
searchIn.setText(filter);
423438
}
424439

@@ -452,6 +467,15 @@ protected void restoreDialog(IDialogSettings settings) {
452467
}
453468
}
454469

470+
private void inputNewSearchFilter(String searchIn) {
471+
filterHistory.remove(searchIn);
472+
filterHistory.addFirst(searchIn);
473+
474+
if (filterHistory.size() > FILTER_HISTORY_SIZE) {
475+
filterHistory.removeLast();
476+
}
477+
}
478+
455479
private class ToggleKeepOpenAction extends Action {
456480
public ToggleKeepOpenAction(IDialogSettings settings) {
457481
super(
@@ -533,7 +557,10 @@ public boolean close() {
533557
protected void storeDialog(IDialogSettings settings) {
534558
String currentSearch = pattern.getText();
535559
settings.put(DIALOG_LAST_QUERY, currentSearch);
536-
settings.put(DIALOG_PATH_FILTER, searchIn.getText());
560+
561+
inputNewSearchFilter(searchIn.getText());
562+
settings.put(FILTER_HISTORY, filterHistory.toArray(String[]::new));
563+
537564
if (toggleCaseSensitiveAction!=null) {
538565
settings.put(CASE_SENSITIVE, toggleCaseSensitiveAction.isChecked());
539566
}
@@ -755,7 +782,7 @@ public void getName(AccessibleEvent e) {
755782
Label searchInLabel = new Label(searchInComposite, SWT.NONE);
756783
searchInLabel.setText(Messages.QuickSearchDialog_In);
757784
GridDataFactory.swtDefaults().indent(5, 0).applyTo(searchInLabel);
758-
searchIn = new Text(searchInComposite, SWT.SINGLE | SWT.BORDER | SWT.ICON_CANCEL);
785+
searchIn = new Combo(searchInComposite, SWT.SINGLE | SWT.BORDER | SWT.ICON_CANCEL);
759786
searchIn.setToolTipText(Messages.QuickSearchDialog_InTooltip);
760787
GridDataFactory.fillDefaults().grab(true, false).indent(5, 0).applyTo(searchIn);
761788

0 commit comments

Comments
 (0)