Skip to content

Commit a162c72

Browse files
Maximilian WittmerHeikoKlare
authored andcommitted
Find/Replace Overlay: Add a search history
Add a search history for the Find/Replace overlay, displayed as a dropdown below the find/replace inputs. fixes #1907
1 parent be68f2f commit a162c72

File tree

10 files changed

+385
-16
lines changed

10 files changed

+385
-16
lines changed
331 Bytes
Loading
556 Bytes
Loading

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/FindReplaceMessages.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ private FindReplaceMessages() {
7373
public static String FindReplaceOverlay_searchBar_message;
7474
public static String FindReplaceOverlay_replaceBar_message;
7575
public static String FindReplaceOverlay_replaceToggle_toolTip;
76+
public static String FindReplaceOverlay_searchHistory_toolTip;
77+
public static String FindReplaceOverlay_replaceHistory_toolTip;
7678
public static String FindReplaceOverlayFirstTimePopup_FindReplaceOverlayFirstTimePopup_message;
7779
public static String FindReplaceOverlayFirstTimePopup_FindReplaceOverlayFirstTimePopup_title;
80+
public static String SearchHistoryMenu_SEARCH_HISTORY_EMPTY_STRING;
7881
}

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/FindReplaceMessages.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ FindReplace_CloseButton_label=Close
4747

4848
# Messages for the find/replace overlay
4949
FindReplaceOverlay_closeButton_toolTip=Close
50-
# Messages for the "new" Find-Replace-Overlay
5150
FindReplaceOverlay_upSearchButton_toolTip=Search backward
5251
FindReplaceOverlay_downSearchButton_toolTip=Search forward
5352
FindReplaceOverlay_searchAllButton_toolTip=Search all
@@ -60,5 +59,8 @@ FindReplaceOverlay_replaceAllButton_toolTip=Replace all
6059
FindReplaceOverlay_searchBar_message=Find
6160
FindReplaceOverlay_replaceBar_message=Replace
6261
FindReplaceOverlay_replaceToggle_toolTip=Toggle input for replace
62+
FindReplaceOverlay_searchHistory_toolTip=Show search history
63+
FindReplaceOverlay_replaceHistory_toolTip=Show replace history
6364
FindReplaceOverlayFirstTimePopup_FindReplaceOverlayFirstTimePopup_message=Find and replace can now be done using an overlay embedded inside the editor. If you prefer the dialog, you can disable the overlay in the preferences or <a>disable it now</a>.
6465
FindReplaceOverlayFirstTimePopup_FindReplaceOverlayFirstTimePopup_title=New Find/Replace Overlay
66+
SearchHistoryMenu_SEARCH_HISTORY_EMPTY_STRING=perform search for search history

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/HistoryStore.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,11 @@ private void writeHistory() {
109109
settingsManager.put(sectionName, names);
110110
}
111111

112+
public int indexOf(String entry) {
113+
return history.indexOf(entry);
114+
}
115+
116+
public int size() {
117+
return history.size();
118+
}
112119
}

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import org.eclipse.ui.PlatformUI;
6868
import org.eclipse.ui.internal.findandreplace.FindReplaceLogic;
6969
import org.eclipse.ui.internal.findandreplace.FindReplaceMessages;
70+
import org.eclipse.ui.internal.findandreplace.HistoryStore;
7071
import org.eclipse.ui.internal.findandreplace.SearchOptions;
7172
import org.eclipse.ui.internal.findandreplace.status.IFindReplaceStatus;
7273

@@ -104,6 +105,7 @@ private final class KeyboardShortcuts {
104105
private static final double BIG_WIDTH_RATIO_EDITOR_TO_OVERLAY = 0.7;
105106
private static final String MINIMAL_WIDTH_TEXT = "THIS TEXT IS SHORT "; //$NON-NLS-1$
106107
private static final String IDEAL_WIDTH_TEXT = "THIS TEXT HAS A REASONABLE LENGTH FOR SEARCHING"; //$NON-NLS-1$
108+
private static final int HISTORY_SIZE = 15;
107109

108110
private final Map<KeyStroke, Runnable> searchKeyStrokeHandlers = new HashMap<>();
109111
private final Map<KeyStroke, Runnable> replaceKeyStrokeHandlers = new HashMap<>();
@@ -120,7 +122,7 @@ private final class KeyboardShortcuts {
120122

121123
private Composite searchContainer;
122124
private Composite searchBarContainer;
123-
private Text searchBar;
125+
private HistoryTextWrapper searchBar;
124126
private AccessibleToolBar searchTools;
125127
private ToolItem searchInSelectionButton;
126128
private ToolItem wholeWordSearchButton;
@@ -134,7 +136,7 @@ private final class KeyboardShortcuts {
134136

135137
private Composite replaceContainer;
136138
private Composite replaceBarContainer;
137-
private Text replaceBar;
139+
private HistoryTextWrapper replaceBar;
138140
private AccessibleToolBar replaceTools;
139141
private ToolItem replaceButton;
140142
private ToolItem replaceAllButton;
@@ -151,7 +153,6 @@ public FindReplaceOverlay(Shell parent, IWorkbenchPart part, IFindReplaceTarget
151153
setShellStyle(SWT.MODELESS);
152154
setBlockOnOpen(false);
153155
targetPart = part;
154-
155156
}
156157

157158
@Override
@@ -176,12 +177,14 @@ private void performReplaceAll() {
176177
BusyIndicator.showWhile(getShell() != null ? getShell().getDisplay() : Display.getCurrent(),
177178
() -> findReplaceLogic.performReplaceAll(getFindString(), getReplaceString()));
178179
evaluateFindReplaceStatus();
180+
replaceBar.storeHistory();
181+
searchBar.storeHistory();
179182
}
180183

181184
private void performSelectAll() {
182185
BusyIndicator.showWhile(getShell() != null ? getShell().getDisplay() : Display.getCurrent(),
183186
() -> findReplaceLogic.performSelectAll(getFindString()));
184-
evaluateFindReplaceStatus();
187+
searchBar.storeHistory();
185188
}
186189

187190
private void toggleToolItem(ToolItem toolItem) {
@@ -372,6 +375,7 @@ private void applyOverlayColors(Color color, boolean tryToColorReplaceBar) {
372375
replaceContainer.setBackground(color);
373376
replaceBar.setBackground(color);
374377
replaceBarContainer.setBackground(color);
378+
replaceTools.setBackground(color);
375379
replaceAllButton.setBackground(color);
376380
replaceButton.setBackground(color);
377381
}
@@ -441,17 +445,19 @@ private void retrieveBackgroundColor() {
441445
textBarForRetrievingTheRightColor.dispose();
442446
}
443447

448+
444449
private void createSearchTools() {
445450
searchTools = new AccessibleToolBar(searchContainer);
446451
GridDataFactory.fillDefaults().grab(false, true).align(GridData.END, GridData.END).applyTo(searchTools);
447452

453+
searchTools.createToolItem(SWT.SEPARATOR);
454+
448455
createCaseSensitiveButton();
449456
createRegexSearchButton();
450457
createWholeWordsButton();
451458
createAreaSearchButton();
452459

453-
@SuppressWarnings("unused")
454-
ToolItem separator = searchTools.createToolItem(SWT.SEPARATOR);
460+
searchTools.createToolItem(SWT.SEPARATOR);
455461

456462
Runnable searchUpOperation = () -> performSearch(false);
457463
searchUpButton = new AccessibleToolItemBuilder(searchTools).withStyleBits(SWT.PUSH)
@@ -564,6 +570,9 @@ private void createReplaceTools() {
564570
Color warningColor = JFaceColors.getErrorText(getShell().getDisplay());
565571

566572
replaceTools = new AccessibleToolBar(replaceContainer);
573+
574+
replaceTools.createToolItem(SWT.SEPARATOR);
575+
567576
GridDataFactory.fillDefaults().grab(false, true).align(GridData.CENTER, GridData.END).applyTo(replaceTools);
568577
replaceButton = new AccessibleToolItemBuilder(replaceTools).withStyleBits(SWT.PUSH)
569578
.withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_REPLACE))
@@ -593,7 +602,9 @@ private void createReplaceTools() {
593602
}
594603

595604
private void createSearchBar() {
596-
searchBar = new Text(searchBarContainer, SWT.SINGLE);
605+
HistoryStore searchHistory = new HistoryStore(getDialogSettings(), "searchhistory", //$NON-NLS-1$
606+
HISTORY_SIZE);
607+
searchBar = new HistoryTextWrapper(searchHistory, searchBarContainer, SWT.SINGLE);
597608
GridDataFactory.fillDefaults().grab(true, false).align(GridData.FILL, GridData.END).applyTo(searchBar);
598609
searchBar.forceFocus();
599610
searchBar.selectAll();
@@ -656,7 +667,8 @@ private void updateIncrementalSearch() {
656667
}
657668

658669
private void createReplaceBar() {
659-
replaceBar = new Text(replaceBarContainer, SWT.SINGLE);
670+
HistoryStore replaceHistory = new HistoryStore(getDialogSettings(), "replacehistory", HISTORY_SIZE); //$NON-NLS-1$
671+
replaceBar = new HistoryTextWrapper(replaceHistory, replaceBarContainer, SWT.SINGLE);
660672
GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.END).applyTo(replaceBar);
661673
replaceBar.setMessage(FindReplaceMessages.FindReplaceOverlay_replaceBar_message);
662674
replaceBar.addFocusListener(FocusListener.focusLostAdapter(e -> {
@@ -922,6 +934,8 @@ private String getReplaceString() {
922934
private void performSingleReplace() {
923935
findReplaceLogic.performReplaceAndFind(getFindString(), getReplaceString());
924936
evaluateFindReplaceStatus();
937+
replaceBar.storeHistory();
938+
searchBar.storeHistory();
925939
}
926940

927941
private void performSearch(boolean forward) {
@@ -932,6 +946,7 @@ private void performSearch(boolean forward) {
932946
activateInFindReplacerIf(SearchOptions.FORWARD, oldForwardSearchSetting);
933947
findReplaceLogic.activate(SearchOptions.INCREMENTAL);
934948
evaluateFindReplaceStatus();
949+
searchBar.storeHistory();
935950
}
936951

937952
private void updateFromTargetSelection() {

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayImages.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
*/
3535
class FindReplaceOverlayImages {
3636
private static final String PREFIX_ELCL = TextEditorPlugin.PLUGIN_ID + ".elcl."; //$NON-NLS-1$
37-
3837
static final String KEY_CLOSE = PREFIX_ELCL + "close"; //$NON-NLS-1$
3938
static final String KEY_FIND_NEXT = PREFIX_ELCL + "select_next"; //$NON-NLS-1$
4039
static final String KEY_FIND_PREV = PREFIX_ELCL + "select_prev"; //$NON-NLS-1$
@@ -47,6 +46,7 @@ class FindReplaceOverlayImages {
4746
static final String KEY_SEARCH_IN_AREA = PREFIX_ELCL + "search_in_selection"; //$NON-NLS-1$
4847
static final String KEY_OPEN_REPLACE_AREA = PREFIX_ELCL + "open_replace"; //$NON-NLS-1$
4948
static final String KEY_CLOSE_REPLACE_AREA = PREFIX_ELCL + "close_replace"; //$NON-NLS-1$
49+
static final String KEY_OPEN_HISTORY = "open_history"; //$NON-NLS-1$
5050

5151
/**
5252
* The image registry containing {@link Image images}.
@@ -73,6 +73,7 @@ private static void declareImages() {
7373
declareRegistryImage(KEY_SEARCH_IN_AREA, ELCL + "search_in_area.png"); //$NON-NLS-1$
7474
declareRegistryImage(KEY_OPEN_REPLACE_AREA, ELCL + "open_replace.png"); //$NON-NLS-1$
7575
declareRegistryImage(KEY_CLOSE_REPLACE_AREA, ELCL + "close_replace.png"); //$NON-NLS-1$
76+
declareRegistryImage(KEY_OPEN_HISTORY, ELCL + "open_history.png"); //$NON-NLS-1$
7677
}
7778

7879
/**

0 commit comments

Comments
 (0)