### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.workbench Index: Eclipse UI/org/eclipse/ui/dialogs/PatternFilter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/dialogs/PatternFilter.java,v retrieving revision 1.8 diff -u -r1.8 PatternFilter.java --- Eclipse UI/org/eclipse/ui/dialogs/PatternFilter.java 15 Nov 2006 17:19:59 -0000 1.8 +++ Eclipse UI/org/eclipse/ui/dialogs/PatternFilter.java 8 May 2007 19:15:15 -0000 @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.ui.dialogs; -import com.ibm.icu.text.BreakIterator; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -24,6 +23,8 @@ import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.ui.internal.misc.StringMatcher; +import com.ibm.icu.text.BreakIterator; + /** * A filter used in conjunction with FilteredTree. In order to * determine if a node should be filtered it uses the content provider of the @@ -55,13 +56,17 @@ */ private StringMatcher matcher; + private boolean useFilterOptimization = true; + private static Object[] EMPTY = new Object[0]; /* (non-Javadoc) * @see org.eclipse.jface.viewers.ViewerFilter#filter(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object[]) */ public final Object[] filter(Viewer viewer, Object parent, Object[] elements) { - if (matcher == null) { + // we don't want to optimize if we've extended the filter ... this + // needs to be addressed in 3.4 + if (matcher == null && useFilterOptimization) { return elements; } @@ -134,6 +139,13 @@ * @param patternString */ public void setPattern(String patternString) { + if ("org.eclipse.ui.keys.optimization.true".equals(patternString)) { //$NON-NLS-1$ + useFilterOptimization = true; + return; + } else if ("org.eclipse.ui.keys.optimization.false".equals(patternString)) { //$NON-NLS-1$ + useFilterOptimization = false; + return; + } cache.clear(); foundAnyCache.clear(); if (patternString == null || patternString.equals("")) { //$NON-NLS-1$ Index: Eclipse UI/org/eclipse/ui/internal/keys/KeysPreferenceFiltersDialog.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/KeysPreferenceFiltersDialog.java,v retrieving revision 1.2 diff -u -r1.2 KeysPreferenceFiltersDialog.java --- Eclipse UI/org/eclipse/ui/internal/keys/KeysPreferenceFiltersDialog.java 2 May 2007 03:47:58 -0000 1.2 +++ Eclipse UI/org/eclipse/ui/internal/keys/KeysPreferenceFiltersDialog.java 8 May 2007 19:15:15 -0000 @@ -31,9 +31,11 @@ private Button actionSetFilterCheckBox; private Button internalFilterCheckBox; + private Button uncategorizedFilterCheckBox; private boolean filterActionSet; private boolean filterInternal; + private boolean filterUncategorized; void setFilterActionSet(boolean b) { filterActionSet = b; @@ -42,6 +44,10 @@ void setFilterInternal(boolean b) { filterInternal = b; } + + void setFilterUncategorized(boolean b) { + filterUncategorized = b; + } boolean getFilterActionSet() { return filterActionSet; @@ -50,6 +56,10 @@ boolean getFilterInternal() { return filterInternal; } + + boolean getFilterUncategorized() { + return filterUncategorized; + } /** * @param parentShell @@ -66,6 +76,7 @@ protected void performDefaults() { actionSetFilterCheckBox.setSelection(true); internalFilterCheckBox.setSelection(true); + uncategorizedFilterCheckBox.setSelection(true); super.performDefaults(); } @@ -85,9 +96,13 @@ internalFilterCheckBox = new Button(topComposite, SWT.CHECK); internalFilterCheckBox .setText(NewKeysPreferenceMessages.InternalFilterCheckBox_Text); + uncategorizedFilterCheckBox = new Button(topComposite, SWT.CHECK); + uncategorizedFilterCheckBox + .setText(NewKeysPreferenceMessages.UncategorizedFilterCheckBox_Text); actionSetFilterCheckBox.setSelection(filterActionSet); internalFilterCheckBox.setSelection(filterInternal); + uncategorizedFilterCheckBox.setSelection(filterUncategorized); applyDialogFont(topComposite); return topComposite; @@ -101,6 +116,7 @@ protected void okPressed() { filterActionSet = actionSetFilterCheckBox.getSelection(); filterInternal = internalFilterCheckBox.getSelection(); + filterUncategorized = uncategorizedFilterCheckBox.getSelection(); super.okPressed(); } Index: Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.java,v retrieving revision 1.59 diff -u -r1.59 NewKeysPreferencePage.java --- Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.java 8 May 2007 19:02:46 -0000 1.59 +++ Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.java 8 May 2007 19:15:16 -0000 @@ -115,7 +115,6 @@ import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.contexts.IContextService; import org.eclipse.ui.dialogs.FilteredTree; -import org.eclipse.ui.dialogs.PatternFilter; import org.eclipse.ui.internal.WorkbenchPlugin; import org.eclipse.ui.internal.commands.ICommandImageService; import org.eclipse.ui.internal.misc.Policy; @@ -399,80 +398,30 @@ * display elements in the tree according to the selected criteria. * */ - protected class GroupedFilteredTree extends FilteredTree { + protected class CategoryFilterTree extends FilteredTree { + + private CategoryPatternFilter filter; /** - * Constructor for GroupedFilteredTree. + * Constructor for PatternFilteredTree. * * @param parent * @param treeStyle * @param filter */ - protected GroupedFilteredTree(Composite parent, int treeStyle, - PatternFilter filter) { + protected CategoryFilterTree(Composite parent, int treeStyle, + CategoryPatternFilter filter) { super(parent, treeStyle, filter); + this.filter = filter; } - protected void createControl(final Composite parent, final int treeStyle) { - GridData gridData; - GridLayout layout; - - layout = new GridLayout(); - // Why doesn't this seem to be working?? - layout.marginHeight = 0; - layout.marginWidth = 0; - setLayout(layout); - setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - setFont(parent.getFont()); - - // Create the filter controls - filterComposite = new Composite(this, SWT.NONE); - GridLayout filterLayout = new GridLayout(2, false); - filterLayout.marginHeight = 0; - filterLayout.marginWidth = 0; - filterComposite.setLayout(filterLayout); - filterComposite.setFont(parent.getFont()); - - createFilterControls(filterComposite); - filterComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, - true, false)); - - // Create a table tree viewer. - final Control treeControl = createTreeControl(this, treeStyle); - gridData = new GridData(SWT.FILL, SWT.FILL, true, true); - gridData.horizontalSpan = 3; - treeControl.setLayoutData(gridData); + public void filterCategories(boolean b) { + filter.filterCategories(b); + textChanged(); } - /** - *

- * Creates the grouping controls that will appear in the top-right in - * the default layout. The default grouping controls are a label and a - * combo box. - *

- *

- * Subclasses may extend or override this method. Before this method - * completes, groupingCombo should be initialized. - * Subclasses must create a combo box which contains the possible - * groupings. - *

- * - * @param parent - * The composite in which the grouping control should be - * placed; must not be null. - * @return The composite containing the grouping controls, or the - * grouping control itself (if there is only one control). - */ - protected Control createGroupingControl(final Composite parent) { - // Create the composite that will contain the grouping controls. - Composite groupingControl = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - layout.marginHeight = 0; - groupingControl.setLayout(layout); - groupingControl.setFont(parent.getFont()); - - return groupingControl; + public boolean isFilteringCategories() { + return filter.isFilteringCategories(); } } @@ -855,6 +804,8 @@ private static final String TAG_FILTER_INTERNAL = "internalFilter"; //$NON-NLS-1$ + private static final String TAG_FILTER_UNCAT = "uncategorizedFilter"; //$NON-NLS-1$ + /** * Sorts the given array of NamedHandleObject instances based * on their name. This is generally useful if they will be displayed to an @@ -917,7 +868,9 @@ /** * The filtered tree containing the list of commands and bindings to edit. */ - private GroupedFilteredTree filteredTree; + private CategoryFilterTree filteredTree; + + private CategoryPatternFilter patternFilter; /** * The grouping for the bindings tree. Either there should be no group @@ -1186,9 +1139,12 @@ getShell()); dialog.setFilterActionSet(filterActionSetContexts); dialog.setFilterInternal(filterInternalContexts); + dialog.setFilterUncategorized(filteredTree.isFilteringCategories()); if (dialog.open() == Window.OK) { filterActionSetContexts = dialog.getFilterActionSet(); filterInternalContexts = dialog.getFilterInternal(); + filteredTree.filterCategories(dialog + .getFilterUncategorized()); whenCombo.setInput(getContexts()); updateDataControls(); } @@ -1218,6 +1174,12 @@ if (settings.get(TAG_FILTER_INTERNAL) != null) { filterInternalContexts = settings.getBoolean(TAG_FILTER_INTERNAL); } + patternFilter = new CategoryPatternFilter( + true, commandService.getCategory(null)); + if (settings.get(TAG_FILTER_UNCAT) != null) { + patternFilter.filterCategories(settings + .getBoolean(TAG_FILTER_UNCAT)); + } // Creates a composite to hold all of the page contents. final Composite page = new Composite(parent, SWT.NONE); @@ -1487,9 +1449,9 @@ private final Control createTree(final Composite parent) { GridData gridData; - filteredTree = new GroupedFilteredTree(parent, SWT.SINGLE - | SWT.FULL_SELECTION | SWT.BORDER, new PatternFilter()); - final GridLayout layout = new GridLayout(2, false); + filteredTree = new CategoryFilterTree(parent, SWT.SINGLE + | SWT.FULL_SELECTION | SWT.BORDER, patternFilter); + final GridLayout layout = new GridLayout(1, false); layout.marginWidth = 0; filteredTree.setLayout(layout); gridData = new GridData(); @@ -2269,6 +2231,7 @@ dialogSettings.put(TAG_FIELD, showAllCheckBox.getSelection()); dialogSettings.put(TAG_FILTER_ACTION_SETS, filterActionSetContexts); dialogSettings.put(TAG_FILTER_INTERNAL, filterInternalContexts); + dialogSettings.put(TAG_FILTER_UNCAT, filteredTree.isFilteringCategories()); } protected IDialogSettings getDialogSettings() { Index: Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferenceMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferenceMessages.java,v retrieving revision 1.10 diff -u -r1.10 NewKeysPreferenceMessages.java --- Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferenceMessages.java 1 May 2007 02:22:52 -0000 1.10 +++ Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferenceMessages.java 8 May 2007 19:15:15 -0000 @@ -58,6 +58,7 @@ public static String KeysPreferenceFilterDialog_Title; public static String ActionSetFilterCheckBox_Text; public static String InternalFilterCheckBox_Text; + public static String UncategorizedFilterCheckBox_Text; static { // load message values from bundle file Index: Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.properties,v retrieving revision 1.18 diff -u -r1.18 NewKeysPreferencePage.properties --- Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.properties 2 May 2007 00:22:09 -0000 1.18 +++ Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.properties 8 May 2007 19:15:16 -0000 @@ -45,5 +45,6 @@ ActionSetFilterCheckBox_Text= Filter &action set contexts InternalFilterCheckBox_Text = Filter &internal contexts +UncategorizedFilterCheckBox_Text = Filter &uncategorized commands KeysPreferenceFilterDialog_Title= When Context Filters Index: Eclipse UI/org/eclipse/ui/internal/keys/CategoryPatternFilter.java =================================================================== RCS file: Eclipse UI/org/eclipse/ui/internal/keys/CategoryPatternFilter.java diff -N Eclipse UI/org/eclipse/ui/internal/keys/CategoryPatternFilter.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Eclipse UI/org/eclipse/ui/internal/keys/CategoryPatternFilter.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ + +package org.eclipse.ui.internal.keys; + +import org.eclipse.core.commands.Category; +import org.eclipse.core.commands.ParameterizedCommand; +import org.eclipse.core.commands.common.NotDefinedException; +import org.eclipse.jface.bindings.Binding; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.ui.dialogs.PatternFilter; + +class CategoryPatternFilter extends PatternFilter { + private boolean filterCategories; + final Category uncategorized; + + public CategoryPatternFilter(boolean filterCategories, Category c) { + uncategorized = c; + filterCategories(filterCategories); + } + + public void filterCategories(boolean b) { + filterCategories = b; + if (filterCategories) { + setPattern("org.eclipse.ui.keys.optimization.false"); //$NON-NLS-1$ + } else { + setPattern("org.eclipse.ui.keys.optimization.true"); //$NON-NLS-1$ + } + } + + public boolean isFilteringCategories() { + return filterCategories; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.dialogs.PatternFilter#isLeafMatch(org.eclipse.jface.viewers.Viewer, + * java.lang.Object) + */ + protected boolean isLeafMatch(Viewer viewer, Object element) { + if (filterCategories) { + final ParameterizedCommand cmd = getCommand(element); + try { + if (cmd != null + && cmd.getCommand().getCategory() == uncategorized) { + return false; + } + } catch (NotDefinedException e) { + return false; + } + } + return super.isLeafMatch(viewer, element); + } + + private ParameterizedCommand getCommand(Object element) { + if (element instanceof ParameterizedCommand) { + return (ParameterizedCommand) element; + } + if (element instanceof Binding) { + return ((Binding) element).getParameterizedCommand(); + } + return null; + } +}