Skip to content

Commit

Permalink
[FindNextAction] synchronize search history with FindReplaceOverlay
Browse files Browse the repository at this point in the history
synchronize search history with the FindReplaceOverlay and
FindReplaceDialog.
  • Loading branch information
Maximilian Wittmer authored and HeikoKlare committed Oct 25, 2024
1 parent 5c9af91 commit 048dbb0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,18 @@ public HistoryStore(IDialogSettings settingsManager, String sectionName, int his
}

public Iterable<String> get() {
loadSection(sectionName);
return history;
}

public String get(int index) {
loadSection(sectionName);
return history.get(index);
}


public void add(String historyItem) {
loadSection(sectionName);
if (sectionName == null) {
throw new IllegalStateException("No section loaded"); //$NON-NLS-1$
}
Expand All @@ -68,6 +71,7 @@ public void remove(String historyItem) {
if (indexInHistory >= 0) {
history.remove(indexInHistory);
}
writeHistory();
}

public boolean isEmpty() {
Expand Down Expand Up @@ -110,10 +114,12 @@ private void writeHistory() {
}

public int indexOf(String entry) {
loadSection(sectionName);
return history.indexOf(entry);
}

public int size() {
loadSection(sectionName);
return history.size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.eclipse.ui.internal.texteditor.TextEditorPlugin;

import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.ui.texteditor.FindReplaceAction;
import org.eclipse.ui.texteditor.IAbstractTextEditorHelpContextIds;
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
import org.eclipse.ui.texteditor.StatusTextEditor;
Expand Down Expand Up @@ -228,10 +229,13 @@ private void asyncExecIfOpen(Runnable operation) {
*
* @return the dialog settings to be used
*/
private static IDialogSettings getDialogSettings() {
private IDialogSettings getDialogSettings() {
IDialogSettings settings = PlatformUI
.getDialogSettingsProvider(FrameworkUtil.getBundle(FindReplaceOverlay.class)).getDialogSettings();
return settings;
.getDialogSettingsProvider(FrameworkUtil.getBundle(FindReplaceAction.class)).getDialogSettings();
IDialogSettings dialogSettings = settings.getSection(FindReplaceAction.class.getClass().getName());
if (dialogSettings == null)
dialogSettings = settings.addNewSection(FindReplaceAction.class.getClass().getName());
return dialogSettings;
}

public void close() {
Expand Down Expand Up @@ -542,8 +546,7 @@ private void createSearchBar() {
searchBarContainer = new Composite(searchContainer, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, true).align(GridData.FILL, GridData.FILL).applyTo(searchBarContainer);
GridLayoutFactory.fillDefaults().numColumns(1).applyTo(searchBarContainer);

HistoryStore searchHistory = new HistoryStore(getDialogSettings(), "searchhistory", //$NON-NLS-1$
HistoryStore searchHistory = new HistoryStore(getDialogSettings(), "findhistory", //$NON-NLS-1$
HISTORY_SIZE);
searchBar = new HistoryTextWrapper(searchHistory, searchBarContainer, SWT.SINGLE);
searchBarDecoration = new ControlDecoration(searchBar, SWT.BOTTOM | SWT.LEFT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,13 @@ private int findAndSelect(int offset, String findString, boolean forwardSearch,
* @return the dialog settings to be used
*/
private IDialogSettings getDialogSettings() {
IDialogSettings settings = PlatformUI.getDialogSettingsProvider(FrameworkUtil.getBundle(FindNextAction.class))
.getDialogSettings();
fDialogSettings= settings.getSection(FindReplaceDialog.class.getName());
IDialogSettings settings = PlatformUI
.getDialogSettingsProvider(FrameworkUtil.getBundle(FindReplaceAction.class)).getDialogSettings();
fDialogSettings = settings.getSection(FindReplaceAction.class.getClass().getName());
if (fDialogSettings == null)
fDialogSettings= settings.addNewSection(FindReplaceDialog.class.getName());
fDialogSettings = settings.addNewSection(FindReplaceAction.class.getClass().getName());
return fDialogSettings;
}

/**
* Initializes itself from the dialog settings with the same state
* as at the previous invocation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public void widgetSelected(SelectionEvent e) {

writeSelection();
updateButtonState(!somethingFound);

updateFindHistory();
evaluateFindReplaceStatus();
}
Expand Down Expand Up @@ -1278,10 +1278,10 @@ private void setupSearchHistory() {
*/
private IDialogSettings getDialogSettings() {
IDialogSettings settings = PlatformUI
.getDialogSettingsProvider(FrameworkUtil.getBundle(FindReplaceDialog.class)).getDialogSettings();
fDialogSettings = settings.getSection(getClass().getName());
.getDialogSettingsProvider(FrameworkUtil.getBundle(FindReplaceAction.class)).getDialogSettings();
fDialogSettings = settings.getSection(FindReplaceAction.class.getClass().getName());
if (fDialogSettings == null)
fDialogSettings = settings.addNewSection(getClass().getName());
fDialogSettings = settings.addNewSection(FindReplaceAction.class.getClass().getName());
return fDialogSettings;
}

Expand Down

0 comments on commit 048dbb0

Please sign in to comment.