Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mw find next action use find replace logic #2309

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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 @@ -26,6 +26,9 @@
* the nodes using the DialogSettings mechanism.
*/
public class HistoryStore {
public static final String SEARCH_HISTORY_KEY = "searchhistory"; //$NON-NLS-1$
public static final String REPLACE_HISTORY_KEY = "replacehistory"; //$NON-NLS-1$

private IDialogSettings settingsManager;
private int historySize;
private List<String> history;
Expand All @@ -44,10 +47,12 @@ 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);
}

Expand All @@ -68,9 +73,17 @@ public void remove(String historyItem) {
if (indexInHistory >= 0) {
history.remove(indexInHistory);
}

writeHistory();
}

public void addOrPushToTop(String historyItem) {
remove(historyItem);
add(historyItem);
}

public boolean isEmpty() {
loadSection(sectionName);
return history.isEmpty();
}

Expand Down Expand Up @@ -110,10 +123,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 @@ -628,7 +628,7 @@ private ContentAssistCommandAdapter createContentAssistField(HistoryTextWrapper
}

private void createSearchBar() {
HistoryStore searchHistory = new HistoryStore(getDialogSettings(), "searchhistory", //$NON-NLS-1$
HistoryStore searchHistory = new HistoryStore(getDialogSettings(), HistoryStore.SEARCH_HISTORY_KEY,
HISTORY_SIZE);
searchBar = new HistoryTextWrapper(searchHistory, searchBarContainer, SWT.SINGLE);
GridDataFactory.fillDefaults().grab(true, true).align(GridData.FILL, GridData.FILL).applyTo(searchBar);
Expand Down Expand Up @@ -663,7 +663,8 @@ private void updateIncrementalSearch() {
}

private void createReplaceBar() {
HistoryStore replaceHistory = new HistoryStore(getDialogSettings(), "replacehistory", HISTORY_SIZE); //$NON-NLS-1$
HistoryStore replaceHistory = new HistoryStore(getDialogSettings(), HistoryStore.REPLACE_HISTORY_KEY,
HISTORY_SIZE);
replaceBar = new HistoryTextWrapper(replaceHistory, replaceBarContainer, SWT.SINGLE);
GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.END).applyTo(replaceBar);
replaceBar.setMessage(FindReplaceMessages.FindReplaceOverlay_replaceBar_message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ private void navigateInHistory(int navigationOffset) {

public void storeHistory() {
String string = textBar.getText();
history.remove(string); // ensure findString is now on the newest index of the history
history.add(string);
history.addOrPushToTop(string);
}

private static boolean okayToUse(final Widget widget) {
Expand Down
Loading
Loading