|
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; |
|
83 | 85 | import org.eclipse.swt.layout.GridData; |
84 | 86 | import org.eclipse.swt.layout.GridLayout; |
85 | 87 | import org.eclipse.swt.widgets.Button; |
| 88 | +import org.eclipse.swt.widgets.Combo; |
86 | 89 | import org.eclipse.swt.widgets.Composite; |
87 | 90 | import org.eclipse.swt.widgets.Control; |
88 | 91 | import org.eclipse.swt.widgets.Display; |
@@ -296,13 +299,17 @@ public void update(ViewerCell cell) { |
296 | 299 | private static final String DIALOG_SASH_WEIGHTS = "SASH_WEIGHTS"; //$NON-NLS-1$ |
297 | 300 |
|
298 | 301 | 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$ |
300 | 302 | private static final String CASE_SENSITIVE = "CASE_SENSITIVE"; //$NON-NLS-1$ |
301 | 303 | private static final boolean CASE_SENSITIVE_DEFAULT = true; |
302 | 304 |
|
303 | 305 | private static final String KEEP_OPEN = "KEEP_OPEN"; //$NON-NLS-1$ |
304 | 306 | private static final boolean KEEP_OPEN_DEFAULT = false; |
305 | 307 |
|
| 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$ |
306 | 313 | /** |
307 | 314 | * Represents an empty selection in the pattern input field (used only for |
308 | 315 | * initial pattern). |
@@ -369,7 +376,7 @@ public void update(ViewerCell cell) { |
369 | 376 | private Label headerLabel; |
370 | 377 |
|
371 | 378 | private IWorkbenchWindow window; |
372 | | - private Text searchIn; |
| 379 | + private Combo searchIn; |
373 | 380 | private Label listLabel; |
374 | 381 |
|
375 | 382 | /** |
@@ -417,8 +424,16 @@ protected void restoreDialog(IDialogSettings settings) { |
417 | 424 | pattern.setText(lastSearch); |
418 | 425 | pattern.selectAll(); |
419 | 426 | } |
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)); |
422 | 437 | searchIn.setText(filter); |
423 | 438 | } |
424 | 439 |
|
@@ -452,6 +467,15 @@ protected void restoreDialog(IDialogSettings settings) { |
452 | 467 | } |
453 | 468 | } |
454 | 469 |
|
| 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 | + |
455 | 479 | private class ToggleKeepOpenAction extends Action { |
456 | 480 | public ToggleKeepOpenAction(IDialogSettings settings) { |
457 | 481 | super( |
@@ -533,7 +557,10 @@ public boolean close() { |
533 | 557 | protected void storeDialog(IDialogSettings settings) { |
534 | 558 | String currentSearch = pattern.getText(); |
535 | 559 | 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 | + |
537 | 564 | if (toggleCaseSensitiveAction!=null) { |
538 | 565 | settings.put(CASE_SENSITIVE, toggleCaseSensitiveAction.isChecked()); |
539 | 566 | } |
@@ -755,7 +782,7 @@ public void getName(AccessibleEvent e) { |
755 | 782 | Label searchInLabel = new Label(searchInComposite, SWT.NONE); |
756 | 783 | searchInLabel.setText(Messages.QuickSearchDialog_In); |
757 | 784 | 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); |
759 | 786 | searchIn.setToolTipText(Messages.QuickSearchDialog_InTooltip); |
760 | 787 | GridDataFactory.fillDefaults().grab(true, false).indent(5, 0).applyTo(searchIn); |
761 | 788 |
|
|
0 commit comments