1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

Bug 538849 - Select Processes dialog filter field improvements

This change ensures that the Select Processes dialog remembers the
filter field input. This helps attaching to the same application without
having to input the filter text on each debug attach.

Furthermore with this change its possible to match a process name with
suffixes, without resorting to pattern matching symbols. E.g. match
"Eclipse" by typing "lipse".

Change-Id: I07a3bb1504f2f5e9626023d1097fcad78dfa9ac7
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
This commit is contained in:
Simeon Andreev 2018-09-07 15:00:58 +02:00 committed by Jonah Graham
parent 094543644b
commit a8a29d195a

View file

@ -27,7 +27,9 @@ import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.FilteredList;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.dialogs.SearchPattern;
import org.eclipse.ui.dialogs.TwoPaneElementSelector;
/**
@ -41,12 +43,57 @@ public class ProcessPrompterDialog extends TwoPaneElementSelector {
private static final String DIALOG_SETTINGS_SECTION_ID = "processPrompterDialog"; //$NON-NLS-1$
private static final String DIALOG_SETTINGS_FILTER_KEY = "filter"; //$NON-NLS-1$
private final ILabelProvider elementRenderer;
public ProcessPrompterDialog(Shell parent, ILabelProvider elementRenderer,
ILabelProvider qualifierRenderer) {
super(parent, elementRenderer, qualifierRenderer);
this.elementRenderer = elementRenderer;
setDialogBoundsSettings(getDialogBoundsSettings(), Dialog.DIALOG_PERSISTSIZE);
setFilter(getFilterFromDialogSetting());
}
@Override
protected FilteredList createFilteredList(Composite parent) {
FilteredList list = super.createFilteredList(parent);
list.setFilterMatcher(new FilteredList.FilterMatcher() {
private SearchPattern matcher;
@Override
public void setFilter(String pattern, boolean ignoreCase, boolean ignoreWildCards) {
if (pattern == null) {
pattern = ""; //$NON-NLS-1$
}
if (! pattern.startsWith("*")) { //$NON-NLS-1$
pattern = "*" + pattern; //$NON-NLS-1$
}
int rules = SearchPattern.RULE_BLANK_MATCH | SearchPattern.RULE_PREFIX_MATCH;
if (! ignoreCase) {
rules |= SearchPattern.RULE_CASE_SENSITIVE;
}
if (! ignoreWildCards) {
rules |= SearchPattern.RULE_PATTERN_MATCH;
}
matcher = new SearchPattern(rules);
matcher.setPattern(pattern);
}
@Override
public boolean match(Object element) {
return matcher.matches(elementRenderer.getText(element));
}
});
return list;
}
/*
* The result should be every selected element.
*/
@ -127,6 +174,10 @@ public class ProcessPrompterDialog extends TwoPaneElementSelector {
@Override
protected IDialogSettings getDialogBoundsSettings() {
return getDialogSettings();
}
protected IDialogSettings getDialogSettings() {
IDialogSettings settings = GdbUIPlugin.getDefault().getDialogSettings();
IDialogSettings section = settings.getSection(DIALOG_SETTINGS_SECTION_ID);
if (section == null) {
@ -134,4 +185,19 @@ public class ProcessPrompterDialog extends TwoPaneElementSelector {
}
return section;
}
private String getFilterFromDialogSetting() {
String filter = getDialogSettings().get(DIALOG_SETTINGS_FILTER_KEY);
return filter == null ? "" : filter; //$NON-NLS-1$
}
private void storeDialogSetting() {
getDialogSettings().put(DIALOG_SETTINGS_FILTER_KEY, getFilter());
}
@Override
public boolean close() {
storeDialogSetting();
return super.close();
}
}