|
25 | 25 | import java.util.ArrayList; |
26 | 26 | import java.util.Arrays; |
27 | 27 | import java.util.Collections; |
| 28 | +import java.util.Deque; |
| 29 | +import java.util.LinkedList; |
28 | 30 | import java.util.List; |
29 | 31 |
|
30 | 32 | import org.eclipse.core.commands.AbstractHandler; |
|
41 | 43 | import org.eclipse.jface.action.IMenuManager; |
42 | 44 | import org.eclipse.jface.action.LegacyActionTools; |
43 | 45 | import org.eclipse.jface.action.MenuManager; |
| 46 | +import org.eclipse.jface.dialogs.DialogSettings; |
44 | 47 | import org.eclipse.jface.dialogs.IDialogConstants; |
45 | 48 | import org.eclipse.jface.dialogs.IDialogSettings; |
46 | 49 | import org.eclipse.jface.layout.GridDataFactory; |
|
83 | 86 | import org.eclipse.swt.layout.GridData; |
84 | 87 | import org.eclipse.swt.layout.GridLayout; |
85 | 88 | import org.eclipse.swt.widgets.Button; |
| 89 | +import org.eclipse.swt.widgets.Combo; |
86 | 90 | import org.eclipse.swt.widgets.Composite; |
87 | 91 | import org.eclipse.swt.widgets.Control; |
88 | 92 | import org.eclipse.swt.widgets.Display; |
@@ -303,6 +307,10 @@ public void update(ViewerCell cell) { |
303 | 307 | private static final String KEEP_OPEN = "KEEP_OPEN"; //$NON-NLS-1$ |
304 | 308 | private static final boolean KEEP_OPEN_DEFAULT = false; |
305 | 309 |
|
| 310 | + private static Deque<String> filterHistory = new LinkedList<>(); |
| 311 | + |
| 312 | + private static final int FILTER_HISTORY_SIZE = 5; |
| 313 | + |
306 | 314 | /** |
307 | 315 | * Represents an empty selection in the pattern input field (used only for |
308 | 316 | * initial pattern). |
@@ -369,7 +377,7 @@ public void update(ViewerCell cell) { |
369 | 377 | private Label headerLabel; |
370 | 378 |
|
371 | 379 | private IWorkbenchWindow window; |
372 | | - private Text searchIn; |
| 380 | + private Combo searchIn; |
373 | 381 | private Label listLabel; |
374 | 382 |
|
375 | 383 | /** |
@@ -409,16 +417,21 @@ public void create() { |
409 | 417 | */ |
410 | 418 | protected void restoreDialog(IDialogSettings settings) { |
411 | 419 | try { |
412 | | - if (initialPatternText==null) { |
| 420 | + if (initialPatternText==null && getLastFilters() != null) { |
413 | 421 | String lastSearch = settings.get(DIALOG_LAST_QUERY); |
| 422 | + |
414 | 423 | if (lastSearch==null) { |
415 | 424 | lastSearch = EMPTY_STRING; |
416 | 425 | } |
417 | 426 | pattern.setText(lastSearch); |
418 | 427 | pattern.selectAll(); |
419 | 428 | } |
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)); |
422 | 435 | searchIn.setText(filter); |
423 | 436 | } |
424 | 437 |
|
@@ -452,6 +465,28 @@ protected void restoreDialog(IDialogSettings settings) { |
452 | 465 | } |
453 | 466 | } |
454 | 467 |
|
| 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 | + |
455 | 490 | private class ToggleKeepOpenAction extends Action { |
456 | 491 | public ToggleKeepOpenAction(IDialogSettings settings) { |
457 | 492 | super( |
@@ -531,9 +566,10 @@ public boolean close() { |
531 | 566 | * settings used to store dialog |
532 | 567 | */ |
533 | 568 | 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 | + |
537 | 573 | if (toggleCaseSensitiveAction!=null) { |
538 | 574 | settings.put(CASE_SENSITIVE, toggleCaseSensitiveAction.isChecked()); |
539 | 575 | } |
@@ -755,7 +791,7 @@ public void getName(AccessibleEvent e) { |
755 | 791 | Label searchInLabel = new Label(searchInComposite, SWT.NONE); |
756 | 792 | searchInLabel.setText(Messages.QuickSearchDialog_In); |
757 | 793 | 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); |
759 | 795 | searchIn.setToolTipText(Messages.QuickSearchDialog_InTooltip); |
760 | 796 | GridDataFactory.fillDefaults().grab(true, false).indent(5, 0).applyTo(searchIn); |
761 | 797 |
|
|
0 commit comments