Skip to content

Commit b0d7509

Browse files
Maximilian WittmerHeikoKlare
authored andcommitted
[FindNextAction] synchronize find history with FindReplaceOverlay #2285
Synchronize search history with the FindReplaceOverlay, FindReplaceDialog and FindNextAction. Fixes #2285
1 parent 4fbbe1b commit b0d7509

File tree

4 files changed

+37
-34
lines changed

4 files changed

+37
-34
lines changed

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
public class HistoryStore {
2929
private IDialogSettings settingsManager;
3030
private int historySize;
31-
private List<String> history;
3231
private String sectionName;
3332

3433
/**
@@ -38,56 +37,58 @@ public class HistoryStore {
3837
* @param historySize how many entries to keep in the history
3938
*/
4039
public HistoryStore(IDialogSettings settingsManager, String sectionName, int historySize) {
40+
if (sectionName == null) {
41+
throw new IllegalStateException("No section loaded"); //$NON-NLS-1$
42+
}
43+
4144
this.settingsManager = settingsManager;
4245
this.historySize = historySize;
43-
loadSection(sectionName);
46+
this.sectionName = sectionName;
4447
}
4548

4649
public Iterable<String> get() {
47-
return history;
50+
return getHistory();
4851
}
4952

5053
public String get(int index) {
51-
return history.get(index);
54+
return getHistory().get(index);
5255
}
5356

5457

5558
public void add(String historyItem) {
56-
if (sectionName == null) {
57-
throw new IllegalStateException("No section loaded"); //$NON-NLS-1$
58-
}
59+
List<String> history = getHistory();
5960
if (historyItem != null && !historyItem.isEmpty()) {
6061
history.add(0, historyItem);
6162
}
62-
63-
writeHistory();
63+
write(history);
6464
}
6565

6666
public void remove(String historyItem) {
67+
List<String> history = getHistory();
6768
int indexInHistory = history.indexOf(historyItem);
6869
if (indexInHistory >= 0) {
6970
history.remove(indexInHistory);
7071
}
72+
write(history);
7173
}
7274

7375
public boolean isEmpty() {
74-
return history.isEmpty();
76+
return getHistory().isEmpty();
7577
}
7678

77-
private void loadSection(String newSectionName) {
78-
this.sectionName = newSectionName;
79-
history = new ArrayList<>();
80-
81-
String[] newHistoryEntries = settingsManager.getArray(newSectionName);
82-
if (newHistoryEntries != null) {
83-
history.addAll(Arrays.asList(newHistoryEntries));
79+
private List<String> getHistory() {
80+
String[] historyEntries = settingsManager.getArray(sectionName);
81+
List<String> result = new ArrayList<>();
82+
if (historyEntries != null) {
83+
result.addAll(Arrays.asList(historyEntries));
8484
}
85+
return result;
8586
}
8687

8788
/**
8889
* Writes the given history into the given dialog store.
8990
*/
90-
private void writeHistory() {
91+
private void write(List<String> history) {
9192
int itemCount = history.size();
9293
Set<String> distinctItems = new HashSet<>(itemCount);
9394
for (int i = 0; i < itemCount; i++) {
@@ -110,10 +111,10 @@ private void writeHistory() {
110111
}
111112

112113
public int indexOf(String entry) {
113-
return history.indexOf(entry);
114+
return getHistory().indexOf(entry);
114115
}
115116

116117
public int size() {
117-
return history.size();
118+
return getHistory().size();
118119
}
119120
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import org.eclipse.ui.internal.texteditor.TextEditorPlugin;
7272

7373
import org.eclipse.ui.texteditor.AbstractTextEditor;
74+
import org.eclipse.ui.texteditor.FindReplaceAction;
7475
import org.eclipse.ui.texteditor.IAbstractTextEditorHelpContextIds;
7576
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
7677
import org.eclipse.ui.texteditor.StatusTextEditor;
@@ -228,10 +229,13 @@ private void asyncExecIfOpen(Runnable operation) {
228229
*
229230
* @return the dialog settings to be used
230231
*/
231-
private static IDialogSettings getDialogSettings() {
232+
private IDialogSettings getDialogSettings() {
232233
IDialogSettings settings = PlatformUI
233-
.getDialogSettingsProvider(FrameworkUtil.getBundle(FindReplaceOverlay.class)).getDialogSettings();
234-
return settings;
234+
.getDialogSettingsProvider(FrameworkUtil.getBundle(FindReplaceAction.class)).getDialogSettings();
235+
IDialogSettings dialogSettings = settings.getSection(FindReplaceAction.class.getClass().getName());
236+
if (dialogSettings == null)
237+
dialogSettings = settings.addNewSection(FindReplaceAction.class.getClass().getName());
238+
return dialogSettings;
235239
}
236240

237241
public void close() {
@@ -542,8 +546,7 @@ private void createSearchBar() {
542546
searchBarContainer = new Composite(searchContainer, SWT.NONE);
543547
GridDataFactory.fillDefaults().grab(true, true).align(GridData.FILL, GridData.FILL).applyTo(searchBarContainer);
544548
GridLayoutFactory.fillDefaults().numColumns(1).applyTo(searchBarContainer);
545-
546-
HistoryStore searchHistory = new HistoryStore(getDialogSettings(), "searchhistory", //$NON-NLS-1$
549+
HistoryStore searchHistory = new HistoryStore(getDialogSettings(), "findhistory", //$NON-NLS-1$
547550
HISTORY_SIZE);
548551
searchBar = new HistoryTextWrapper(searchHistory, searchBarContainer, SWT.SINGLE);
549552
searchBarDecoration = new ControlDecoration(searchBar, SWT.BOTTOM | SWT.LEFT);

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindNextAction.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,13 @@ private int findAndSelect(int offset, String findString, boolean forwardSearch,
340340
* @return the dialog settings to be used
341341
*/
342342
private IDialogSettings getDialogSettings() {
343-
IDialogSettings settings = PlatformUI.getDialogSettingsProvider(FrameworkUtil.getBundle(FindNextAction.class))
344-
.getDialogSettings();
345-
fDialogSettings= settings.getSection(FindReplaceDialog.class.getName());
343+
IDialogSettings settings = PlatformUI
344+
.getDialogSettingsProvider(FrameworkUtil.getBundle(FindReplaceAction.class)).getDialogSettings();
345+
fDialogSettings = settings.getSection(FindReplaceAction.class.getClass().getName());
346346
if (fDialogSettings == null)
347-
fDialogSettings= settings.addNewSection(FindReplaceDialog.class.getName());
347+
fDialogSettings = settings.addNewSection(FindReplaceAction.class.getClass().getName());
348348
return fDialogSettings;
349349
}
350-
351350
/**
352351
* Initializes itself from the dialog settings with the same state
353352
* as at the previous invocation.

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public void widgetSelected(SelectionEvent e) {
318318

319319
writeSelection();
320320
updateButtonState(!somethingFound);
321-
321+
322322
updateFindHistory();
323323
evaluateFindReplaceStatus();
324324
}
@@ -1278,10 +1278,10 @@ private void setupSearchHistory() {
12781278
*/
12791279
private IDialogSettings getDialogSettings() {
12801280
IDialogSettings settings = PlatformUI
1281-
.getDialogSettingsProvider(FrameworkUtil.getBundle(FindReplaceDialog.class)).getDialogSettings();
1282-
fDialogSettings = settings.getSection(getClass().getName());
1281+
.getDialogSettingsProvider(FrameworkUtil.getBundle(FindReplaceAction.class)).getDialogSettings();
1282+
fDialogSettings = settings.getSection(FindReplaceAction.class.getClass().getName());
12831283
if (fDialogSettings == null)
1284-
fDialogSettings = settings.addNewSection(getClass().getName());
1284+
fDialogSettings = settings.addNewSection(FindReplaceAction.class.getClass().getName());
12851285
return fDialogSettings;
12861286
}
12871287

0 commit comments

Comments
 (0)