Skip to content

Commit 77f5171

Browse files
committed
Drop Down menu in Quick Search implemented
1 parent b379121 commit 77f5171

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

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

Lines changed: 27 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,12 @@ 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+
97+
private static final String EMPTY_SEARCH = ""; //$NON-NLS-1$
98+
9199
private static final String TAG_SECTION = "section";//$NON-NLS-1$
92100

93101
private static final String TAG_NAME = "name";//$NON-NLS-1$
@@ -113,6 +121,7 @@ public DialogSettings(String sectionName) {
113121
items = new LinkedHashMap<>();
114122
arrayItems = new LinkedHashMap<>();
115123
sections = new LinkedHashMap<>();
124+
filterHistory = new LinkedList<>();
116125
}
117126

118127
@Override
@@ -364,6 +373,24 @@ public void put(String key, String value) {
364373
}
365374
}
366375

376+
public void inputNewSearchFilter(String searchIn) {
377+
filterHistory.remove(searchIn);
378+
filterHistory.remove(EMPTY_SEARCH);
379+
380+
filterHistory.addFirst(searchIn);
381+
382+
if (filterHistory.size() > FILTER_HISTORY_SIZE) {
383+
filterHistory.removeLast();
384+
}
385+
}
386+
387+
public Deque<String> getLastFilters() {
388+
if (filterHistory.isEmpty()) {
389+
return null;
390+
}
391+
return filterHistory;
392+
}
393+
367394
@Override
368395
public void put(String key, boolean value) {
369396
put(key, String.valueOf(value));

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
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;
@@ -41,6 +42,7 @@
4142
import org.eclipse.jface.action.IMenuManager;
4243
import org.eclipse.jface.action.LegacyActionTools;
4344
import org.eclipse.jface.action.MenuManager;
45+
import org.eclipse.jface.dialogs.DialogSettings;
4446
import org.eclipse.jface.dialogs.IDialogConstants;
4547
import org.eclipse.jface.dialogs.IDialogSettings;
4648
import org.eclipse.jface.layout.GridDataFactory;
@@ -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;
@@ -369,7 +372,7 @@ public void update(ViewerCell cell) {
369372
private Label headerLabel;
370373

371374
private IWorkbenchWindow window;
372-
private Text searchIn;
375+
private Combo searchIn;
373376
private Label listLabel;
374377

375378
/**
@@ -409,16 +412,21 @@ public void create() {
409412
*/
410413
protected void restoreDialog(IDialogSettings settings) {
411414
try {
412-
if (initialPatternText==null) {
413-
String lastSearch = settings.get(DIALOG_LAST_QUERY);
415+
DialogSettings dialogSettings = (DialogSettings) settings;
416+
417+
if (initialPatternText==null && dialogSettings.getLastFilters() != null) {
418+
String lastSearch = dialogSettings.get(DIALOG_LAST_QUERY);
419+
414420
if (lastSearch==null) {
415421
lastSearch = EMPTY_STRING;
416422
}
417423
pattern.setText(lastSearch);
418424
pattern.selectAll();
419425
}
420-
if (settings.get(DIALOG_PATH_FILTER)!=null) {
421-
String filter = settings.get(DIALOG_PATH_FILTER);
426+
if (dialogSettings.getLastFilters() != null) {
427+
String filter = dialogSettings.getLastFilters().getFirst();
428+
429+
searchIn.setItems(dialogSettings.getLastFilters().toArray(String[]::new));
422430
searchIn.setText(filter);
423431
}
424432

@@ -531,9 +539,10 @@ public boolean close() {
531539
* settings used to store dialog
532540
*/
533541
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());
542+
((DialogSettings)settings).inputNewSearchFilter(searchIn.getText());
543+
544+
settings.put(DIALOG_LAST_QUERY, pattern.getText());
545+
537546
if (toggleCaseSensitiveAction!=null) {
538547
settings.put(CASE_SENSITIVE, toggleCaseSensitiveAction.isChecked());
539548
}
@@ -755,7 +764,7 @@ public void getName(AccessibleEvent e) {
755764
Label searchInLabel = new Label(searchInComposite, SWT.NONE);
756765
searchInLabel.setText(Messages.QuickSearchDialog_In);
757766
GridDataFactory.swtDefaults().indent(5, 0).applyTo(searchInLabel);
758-
searchIn = new Text(searchInComposite, SWT.SINGLE | SWT.BORDER | SWT.ICON_CANCEL);
767+
searchIn = new Combo(searchInComposite, SWT.SINGLE | SWT.BORDER | SWT.ICON_CANCEL);
759768
searchIn.setToolTipText(Messages.QuickSearchDialog_InTooltip);
760769
GridDataFactory.fillDefaults().grab(true, false).indent(5, 0).applyTo(searchIn);
761770

0 commit comments

Comments
 (0)