Skip to content

Commit bb59c93

Browse files
committed
Drop Down menu in Quick Search implemented
1 parent f5354b7 commit bb59c93

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

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

Lines changed: 44 additions & 8 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;
@@ -41,6 +43,7 @@
4143
import org.eclipse.jface.action.IMenuManager;
4244
import org.eclipse.jface.action.LegacyActionTools;
4345
import org.eclipse.jface.action.MenuManager;
46+
import org.eclipse.jface.dialogs.DialogSettings;
4447
import org.eclipse.jface.dialogs.IDialogConstants;
4548
import org.eclipse.jface.dialogs.IDialogSettings;
4649
import org.eclipse.jface.layout.GridDataFactory;
@@ -83,6 +86,7 @@
8386
import org.eclipse.swt.layout.GridData;
8487
import org.eclipse.swt.layout.GridLayout;
8588
import org.eclipse.swt.widgets.Button;
89+
import org.eclipse.swt.widgets.Combo;
8690
import org.eclipse.swt.widgets.Composite;
8791
import org.eclipse.swt.widgets.Control;
8892
import org.eclipse.swt.widgets.Display;
@@ -303,6 +307,10 @@ public void update(ViewerCell cell) {
303307
private static final String KEEP_OPEN = "KEEP_OPEN"; //$NON-NLS-1$
304308
private static final boolean KEEP_OPEN_DEFAULT = false;
305309

310+
private static Deque<String> filterHistory = new LinkedList<>();
311+
312+
private static final int FILTER_HISTORY_SIZE = 5;
313+
306314
/**
307315
* Represents an empty selection in the pattern input field (used only for
308316
* initial pattern).
@@ -369,7 +377,7 @@ public void update(ViewerCell cell) {
369377
private Label headerLabel;
370378

371379
private IWorkbenchWindow window;
372-
private Text searchIn;
380+
private Combo searchIn;
373381
private Label listLabel;
374382

375383
/**
@@ -409,16 +417,21 @@ public void create() {
409417
*/
410418
protected void restoreDialog(IDialogSettings settings) {
411419
try {
412-
if (initialPatternText==null) {
420+
if (initialPatternText==null && getLastFilters() != null) {
413421
String lastSearch = settings.get(DIALOG_LAST_QUERY);
422+
414423
if (lastSearch==null) {
415424
lastSearch = EMPTY_STRING;
416425
}
417426
pattern.setText(lastSearch);
418427
pattern.selectAll();
419428
}
420-
if (settings.get(DIALOG_PATH_FILTER)!=null) {
421-
String filter = settings.get(DIALOG_PATH_FILTER);
429+
if (getLastFilters() != null) {
430+
Deque<String> lastSearches = getLastFilters();
431+
432+
String filter = lastSearches.getFirst();
433+
434+
searchIn.setItems(filterOutBlanks(lastSearches).toArray(String[]::new));
422435
searchIn.setText(filter);
423436
}
424437

@@ -452,6 +465,28 @@ protected void restoreDialog(IDialogSettings settings) {
452465
}
453466
}
454467

468+
public void inputNewSearchFilter(String searchIn) {
469+
filterHistory.remove(searchIn);
470+
filterHistory.addFirst(searchIn);
471+
472+
if (filterHistory.size() > FILTER_HISTORY_SIZE) {
473+
filterHistory.removeLast();
474+
}
475+
}
476+
477+
public Deque<String> getLastFilters() {
478+
if (filterHistory.isEmpty()) {
479+
return null;
480+
}
481+
return filterHistory;
482+
}
483+
484+
private Deque<String> filterOutBlanks(Deque<String> lastFiveSearches) {
485+
lastFiveSearches.removeIf(str -> str.isBlank());
486+
return lastFiveSearches;
487+
488+
}
489+
455490
private class ToggleKeepOpenAction extends Action {
456491
public ToggleKeepOpenAction(IDialogSettings settings) {
457492
super(
@@ -531,9 +566,10 @@ public boolean close() {
531566
* settings used to store dialog
532567
*/
533568
protected void storeDialog(IDialogSettings settings) {
534-
String currentSearch = pattern.getText();
535-
settings.put(DIALOG_LAST_QUERY, currentSearch);
536-
settings.put(DIALOG_PATH_FILTER, searchIn.getText());
569+
inputNewSearchFilter(searchIn.getText());
570+
571+
settings.put(DIALOG_LAST_QUERY, pattern.getText());
572+
537573
if (toggleCaseSensitiveAction!=null) {
538574
settings.put(CASE_SENSITIVE, toggleCaseSensitiveAction.isChecked());
539575
}
@@ -755,7 +791,7 @@ public void getName(AccessibleEvent e) {
755791
Label searchInLabel = new Label(searchInComposite, SWT.NONE);
756792
searchInLabel.setText(Messages.QuickSearchDialog_In);
757793
GridDataFactory.swtDefaults().indent(5, 0).applyTo(searchInLabel);
758-
searchIn = new Text(searchInComposite, SWT.SINGLE | SWT.BORDER | SWT.ICON_CANCEL);
794+
searchIn = new Combo(searchInComposite, SWT.SINGLE | SWT.BORDER | SWT.ICON_CANCEL);
759795
searchIn.setToolTipText(Messages.QuickSearchDialog_InTooltip);
760796
GridDataFactory.fillDefaults().grab(true, false).indent(5, 0).applyTo(searchIn);
761797

0 commit comments

Comments
 (0)