Skip to content

Commit 0a0a010

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

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/DialogSettings.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
import java.nio.charset.StandardCharsets;
3131
import java.util.ArrayList;
3232
import java.util.Collection;
33+
import java.util.Deque;
3334
import java.util.LinkedHashMap;
35+
import java.util.LinkedList;
3436
import java.util.List;
3537
import java.util.Map;
3638
import java.util.Map.Entry;
@@ -88,6 +90,10 @@ public class DialogSettings implements IDialogSettings {
8890
// A Map with all the keys mapped to array of strings.
8991
private Map<String, String[]> arrayItems;
9092

93+
private Deque<String> filterHistory;
94+
95+
private static final int FILTER_HISTORY_SIZE = 5;
96+
9197
private static final String TAG_SECTION = "section";//$NON-NLS-1$
9298

9399
private static final String TAG_NAME = "name";//$NON-NLS-1$
@@ -113,6 +119,7 @@ public DialogSettings(String sectionName) {
113119
items = new LinkedHashMap<>();
114120
arrayItems = new LinkedHashMap<>();
115121
sections = new LinkedHashMap<>();
122+
filterHistory = new LinkedList<>();
116123
}
117124

118125
@Override
@@ -364,6 +371,22 @@ public void put(String key, String value) {
364371
}
365372
}
366373

374+
public void inputNewSearchFilter(String searchIn) {
375+
filterHistory.remove(searchIn);
376+
filterHistory.addFirst(searchIn);
377+
378+
if (filterHistory.size() > FILTER_HISTORY_SIZE) {
379+
filterHistory.removeLast();
380+
}
381+
}
382+
383+
public Deque<String> getLastFilters() {
384+
if (filterHistory.isEmpty()) {
385+
return null;
386+
}
387+
return filterHistory;
388+
}
389+
367390
@Override
368391
public void put(String key, boolean value) {
369392
put(key, String.valueOf(value));

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

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222

2323
import static org.eclipse.jface.resource.JFaceResources.TEXT_FONT;
2424

25+
import java.awt.event.ItemEvent;
2526
import java.util.ArrayList;
2627
import java.util.Arrays;
2728
import java.util.Collections;
29+
import java.util.Deque;
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;
@@ -369,7 +373,7 @@ public void update(ViewerCell cell) {
369373
private Label headerLabel;
370374

371375
private IWorkbenchWindow window;
372-
private Text searchIn;
376+
private Combo searchIn;
373377
private Label listLabel;
374378

375379
/**
@@ -409,16 +413,23 @@ public void create() {
409413
*/
410414
protected void restoreDialog(IDialogSettings settings) {
411415
try {
412-
if (initialPatternText==null) {
413-
String lastSearch = settings.get(DIALOG_LAST_QUERY);
416+
DialogSettings dialogSettings = (DialogSettings) settings;
417+
418+
if (initialPatternText==null && dialogSettings.getLastFilters() != null) {
419+
String lastSearch = dialogSettings.get(DIALOG_LAST_QUERY);
420+
414421
if (lastSearch==null) {
415422
lastSearch = EMPTY_STRING;
416423
}
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+
if (dialogSettings.getLastFilters() != null) {
428+
Deque<String> lastSearches = dialogSettings.getLastFilters();
429+
430+
String filter = lastSearches.getFirst();
431+
432+
searchIn.setItems(filterOutBlanks(lastSearches).toArray(String[]::new));
422433
searchIn.setText(filter);
423434
}
424435

@@ -452,6 +463,12 @@ protected void restoreDialog(IDialogSettings settings) {
452463
}
453464
}
454465

466+
private Deque<String> filterOutBlanks(Deque<String> lastFiveSearches) {
467+
lastFiveSearches.removeIf(str -> str.isBlank());
468+
return lastFiveSearches;
469+
470+
}
471+
455472
private class ToggleKeepOpenAction extends Action {
456473
public ToggleKeepOpenAction(IDialogSettings settings) {
457474
super(
@@ -531,9 +548,10 @@ public boolean close() {
531548
* settings used to store dialog
532549
*/
533550
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());
551+
((DialogSettings)settings).inputNewSearchFilter(searchIn.getText());
552+
553+
settings.put(DIALOG_LAST_QUERY, pattern.getText());
554+
537555
if (toggleCaseSensitiveAction!=null) {
538556
settings.put(CASE_SENSITIVE, toggleCaseSensitiveAction.isChecked());
539557
}
@@ -755,7 +773,7 @@ public void getName(AccessibleEvent e) {
755773
Label searchInLabel = new Label(searchInComposite, SWT.NONE);
756774
searchInLabel.setText(Messages.QuickSearchDialog_In);
757775
GridDataFactory.swtDefaults().indent(5, 0).applyTo(searchInLabel);
758-
searchIn = new Text(searchInComposite, SWT.SINGLE | SWT.BORDER | SWT.ICON_CANCEL);
776+
searchIn = new Combo(searchInComposite, SWT.SINGLE | SWT.BORDER | SWT.ICON_CANCEL);
759777
searchIn.setToolTipText(Messages.QuickSearchDialog_InTooltip);
760778
GridDataFactory.fillDefaults().grab(true, false).indent(5, 0).applyTo(searchIn);
761779

0 commit comments

Comments
 (0)