Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
public class HistoryStore {
private IDialogSettings settingsManager;
private int historySize;
private List<String> history;
private String sectionName;

/**
Expand All @@ -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<String> 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<String> history = getHistory();
if (historyItem != null && !historyItem.isEmpty()) {
history.add(0, historyItem);
}

writeHistory();
write(history);
}

public void remove(String historyItem) {
List<String> 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<String> getHistory() {
String[] historyEntries = settingsManager.getArray(sectionName);
List<String> 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<String> history) {
int itemCount = history.size();
Set<String> distinctItems = new HashSet<>(itemCount);
for (int i = 0; i < itemCount; i++) {
Expand All @@ -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();
}
}
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
Loading