diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/HistoryStore.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/HistoryStore.java index 2d5e063a745..d0d0ca022c3 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/HistoryStore.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/HistoryStore.java @@ -28,7 +28,6 @@ public class HistoryStore { private IDialogSettings settingsManager; private int historySize; - private List history; private String sectionName; /** @@ -38,56 +37,58 @@ public class HistoryStore { * @param historySize how many entries to keep in the history */ public HistoryStore(IDialogSettings settingsManager, String sectionName, int historySize) { + if (sectionName == null) { + throw new IllegalStateException("No section loaded"); //$NON-NLS-1$ + } + this.settingsManager = settingsManager; this.historySize = historySize; - loadSection(sectionName); + this.sectionName = sectionName; } public Iterable get() { - return history; + return getHistory(); } public String get(int index) { - return history.get(index); + return getHistory().get(index); } public void add(String historyItem) { - if (sectionName == null) { - throw new IllegalStateException("No section loaded"); //$NON-NLS-1$ - } + List history = getHistory(); if (historyItem != null && !historyItem.isEmpty()) { history.add(0, historyItem); } - - writeHistory(); + write(history); } public void remove(String historyItem) { + List history = getHistory(); int indexInHistory = history.indexOf(historyItem); if (indexInHistory >= 0) { history.remove(indexInHistory); } + write(history); } public boolean isEmpty() { - return history.isEmpty(); + return getHistory().isEmpty(); } - private void loadSection(String newSectionName) { - this.sectionName = newSectionName; - history = new ArrayList<>(); - - String[] newHistoryEntries = settingsManager.getArray(newSectionName); - if (newHistoryEntries != null) { - history.addAll(Arrays.asList(newHistoryEntries)); + private List getHistory() { + String[] historyEntries = settingsManager.getArray(sectionName); + List result = new ArrayList<>(); + if (historyEntries != null) { + result.addAll(Arrays.asList(historyEntries)); } + return result; } /** * Writes the given history into the given dialog store. */ - private void writeHistory() { + private void write(List history) { int itemCount = history.size(); Set distinctItems = new HashSet<>(itemCount); for (int i = 0; i < itemCount; i++) { @@ -110,10 +111,10 @@ private void writeHistory() { } public int indexOf(String entry) { - return history.indexOf(entry); + return getHistory().indexOf(entry); } public int size() { - return history.size(); + return getHistory().size(); } } diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java index 551fc8e6562..4472e94a6ec 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java @@ -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; @@ -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() { @@ -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); diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindNextAction.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindNextAction.java index 3fbe7f732c3..3755132e0ec 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindNextAction.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindNextAction.java @@ -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. diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java index d71941d293f..ee8ea79abb4 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java @@ -318,7 +318,7 @@ public void widgetSelected(SelectionEvent e) { writeSelection(); updateButtonState(!somethingFound); - + updateFindHistory(); evaluateFindReplaceStatus(); } @@ -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; }