diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index 61f5ad8de92..97111894d01 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -196,7 +196,8 @@ CPluginFileTypesPreferencePage.name=File Types CodeStylePreferencePage.name=Code Style codeTemplatePreferencePage.name=Code Templates codeFormatterPreferencePage.name=Formatter -includeStylePreferencePage.name=Includes +includeStylePreferencePage.name=Include Style +organizeIncludesPreferencePage.name=Organize Includes nameStylePreferencePage.name=Name Style CodeAssistPreferencePage.name=Content Assist CodeAssistAdvancedPreferencePage.name=Advanced @@ -567,8 +568,9 @@ preferenceKeywords.common=c cpp cplusplus cdt preferenceKeywords.codeformatter=profile codestyle project specific comment indentation brace white space blank line new control statement wrapping tab parenthesis bracket preferenceKeywords.codestyle=class member visibility order ordering preferenceKeywords.codetemplates=comment code constructor method file type content -preferenceKeywords.includestyle=include includes style header file system preferenceKeywords.namestyle=name style file getter setter field variable +preferenceKeywords.includestyle=include includes style partner system header file system +preferenceKeywords.organizeincludes=include includes organize preferenceKeywords.todo=case sensitive task tag todo xxx fix fixme project comments preferenceKeywords.indexer=index skip references type macro search build configuration cache memory performance diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 7872c7016c1..830d60d2f2f 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -1223,14 +1223,6 @@ - - - - + + + + + + + + + + label="%preferenceKeywords.organizeincludes" + id="org.eclipse.cdt.ui.organizeincludes"/> diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java index b56cc60ed52..44a508859bf 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java @@ -88,6 +88,7 @@ public interface ICHelpContextIds { public static final String CODE_STYLE_PREFERENCE_PAGE = PREFIX + "code_style_preference_context"; //$NON-NLS-1$ public static final String CODE_TEMPLATES_PREFERENCE_PAGE = PREFIX + "code_templates_preference_context"; //$NON-NLS-1$ public static final String INCLUDE_STYLE_PREFERENCE_PAGE = PREFIX + "include_style_preference_context"; //$NON-NLS-1$ + public static final String ORGANIZE_INCLUDES_PREFERENCE_PAGE = PREFIX + "organize_includes_preference_context"; //$NON-NLS-1$ public static final String NAME_STYLE_PREFERENCE_PAGE = PREFIX + "name_style_preference_context"; //$NON-NLS-1$ // Console view diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/IncludeCategoriesBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/IncludeCategoriesBlock.java index be0c1cd36aa..70aa8b24166 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/IncludeCategoriesBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/IncludeCategoriesBlock.java @@ -10,8 +10,11 @@ *******************************************************************************/ package org.eclipse.cdt.internal.ui.preferences; + import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.eclipse.core.resources.IProject; import org.eclipse.jface.layout.PixelConverter; @@ -33,7 +36,6 @@ import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; import org.eclipse.cdt.internal.ui.refactoring.includes.IncludeGroupStyle; import org.eclipse.cdt.internal.ui.refactoring.includes.IncludeGroupStyle.IncludeKind; -import org.eclipse.cdt.internal.ui.refactoring.includes.IncludePreferences; import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter; @@ -43,63 +45,39 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.TreeListDialogField; * The preference block for configuring styles of different categories of include statements. */ public class IncludeCategoriesBlock extends OptionsConfigurationBlock { - private static final Key KEY_STYLE_GROUP_RELATED = getCDTUIKey(IncludePreferences.INCLUDE_STYLE_GROUP_RELATED); - private static final Key KEY_STYLE_PARTNER = getCDTUIKey(IncludePreferences.INCLUDE_STYLE_PARTNER); - private static final Key KEY_STYLE_GROUP_PARTNER = getCDTUIKey(IncludePreferences.INCLUDE_STYLE_GROUP_PARTNER); - private static final Key KEY_STYLE_SAME_FOLDER = getCDTUIKey(IncludePreferences.INCLUDE_STYLE_SAME_FOLDER); - private static final Key KEY_STYLE_GROUP_SAME_FOLDER = getCDTUIKey(IncludePreferences.INCLUDE_STYLE_GROUP_SAME_FOLDER); - private static final Key KEY_STYLE_SUBFOLDER = getCDTUIKey(IncludePreferences.INCLUDE_STYLE_SUBFOLDER); - private static final Key KEY_STYLE_GROUP_SUBFOLDER = getCDTUIKey(IncludePreferences.INCLUDE_STYLE_GROUP_SUBFOLDER); - private static final Key KEY_STYLE_GROUP_SYSTEM = getCDTUIKey(IncludePreferences.INCLUDE_STYLE_GROUP_SYSTEM); - - private static Key[] getAllKeys() { - return new Key[] { - KEY_STYLE_GROUP_RELATED, - KEY_STYLE_PARTNER, - KEY_STYLE_GROUP_PARTNER, - KEY_STYLE_SAME_FOLDER, - KEY_STYLE_GROUP_SAME_FOLDER, - KEY_STYLE_SUBFOLDER, - KEY_STYLE_GROUP_SUBFOLDER, - KEY_STYLE_GROUP_SYSTEM, - }; - } - - private final Category[] rootCategories; + private final List styles; + private final Map categories = new HashMap(); private TreeListDialogField categoryTree; private PixelConverter pixelConverter; private StackLayout editorAreaStack; private Category selectedCategory; public IncludeCategoriesBlock(IStatusChangeListener context, IProject project, - IWorkbenchPreferenceContainer container) { - super(context, project, getAllKeys(), container); - rootCategories = createCategories(); + IWorkbenchPreferenceContainer container, List styles) { + super(context, project, new Key[0], container); + this.styles = styles; + createCategories(); } - private static Category[] createCategories() { - Category related = new Category(PreferencesMessages.IncludeCategoriesBlock_related_headers_node, - PreferencesMessages.IncludeCategoriesBlock_related_headers_node_description) - .setGroupingKey(KEY_STYLE_GROUP_RELATED); - new Category(PreferencesMessages.IncludeCategoriesBlock_partner_header_node, - PreferencesMessages.IncludeCategoriesBlock_partner_header_node_description, related) - .setIncludeKind(IncludeKind.PARTNER) - .setGroupingKey(KEY_STYLE_GROUP_PARTNER) - .setStyleKey(KEY_STYLE_PARTNER); - new Category(PreferencesMessages.IncludeCategoriesBlock_same_folder_header_node, - PreferencesMessages.IncludeCategoriesBlock_same_folder_header_node_description, related) - .setIncludeKind(IncludeKind.IN_SAME_FOLDER) - .setGroupingKey(KEY_STYLE_GROUP_SAME_FOLDER) - .setStyleKey(KEY_STYLE_SAME_FOLDER); - new Category(PreferencesMessages.IncludeCategoriesBlock_subfolder_header_node, - PreferencesMessages.IncludeCategoriesBlock_subfolder_header_node_description, related) - .setIncludeKind(IncludeKind.IN_SUBFOLDERS) - .setGroupingKey(KEY_STYLE_GROUP_SUBFOLDER) - .setStyleKey(KEY_STYLE_SUBFOLDER); - Category system = new Category(PreferencesMessages.IncludeCategoriesBlock_system_headers_node, - PreferencesMessages.IncludeCategoriesBlock_system_headers_node_description) - .setGroupingKey(KEY_STYLE_GROUP_SYSTEM); - return new Category[] { related, system }; + private void createCategories() { + createCategory(IncludeKind.RELATED); + createCategory(IncludeKind.PARTNER); + createCategory(IncludeKind.IN_SAME_FOLDER); + createCategory(IncludeKind.IN_SUBFOLDER); + createCategory(IncludeKind.SYSTEM); + createCategory(IncludeKind.SYSTEM_WITH_EXTENSION); + createCategory(IncludeKind.SYSTEM_WITHOUT_EXTENSION); + createCategory(IncludeKind.OTHER); + createCategory(IncludeKind.IN_SAME_PROJECT); + createCategory(IncludeKind.IN_OTHER_PROJECT); + createCategory(IncludeKind.EXTERNAL); + } + + private Category createCategory(IncludeKind includeKind) { + Category parentCategory = categories.get(includeKind.parent); + Category category = new Category(includeKind, parentCategory); + categories.put(category.getIncludeKind(), category); + return category; } public void postSetSelection(Object element) { @@ -123,31 +101,24 @@ public class IncludeCategoriesBlock extends OptionsConfigurationBlock { IncludeStyleAdapter adapter = new IncludeStyleAdapter(); categoryTree = new TreeListDialogField(adapter, null, new IncludeStyleLabelProvider()); categoryTree.setDialogFieldListener(adapter); - categoryTree.setLabelText(PreferencesMessages.NameStyleBlock_categories_label); + categoryTree.setLabelText(PreferencesMessages.IncludeCategoriesBlock_header_categories); categoryTree.setViewerComparator(adapter); - createCategories(); - - for (Category category : rootCategories) { - categoryTree.addElement(category); + for (Category category : categories.values()) { + if (category.parent == null) + categoryTree.addElement(category); } Label label = categoryTree.getLabelControl(composite); - GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); - gd.verticalAlignment = GridData.BEGINNING; - label.setLayoutData(gd); + label.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false)); Control tree = categoryTree.getTreeControl(composite); - gd = new GridData(); - gd.horizontalAlignment = GridData.FILL; - gd.grabExcessHorizontalSpace = true; - gd.verticalAlignment = GridData.FILL; - gd.grabExcessVerticalSpace = false; + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.widthHint = pixelConverter.convertWidthInCharsToPixels(50); - gd.heightHint = pixelConverter.convertHeightInCharsToPixels(12); + gd.heightHint = pixelConverter.convertHeightInCharsToPixels(2); tree.setLayoutData(gd); - createCategoryEditorArea(composite); + createCategoryEditors(composite); categoryTree.setTreeExpansionLevel(2); categoryTree.selectFirstElement(); @@ -156,43 +127,37 @@ public class IncludeCategoriesBlock extends OptionsConfigurationBlock { return composite; } - private void createCategoryEditorArea(Composite parent) { + private void createCategoryEditors(Composite parent) { Composite editorArea = new Composite(parent, SWT.NONE); - editorArea.setLayoutData(new GridData(GridData.FILL_BOTH)); + editorArea.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false)); editorArea.setFont(parent.getFont()); editorAreaStack = new StackLayout(); editorArea.setLayout(editorAreaStack); - for (Category category : rootCategories) { - createCategoryEditor(editorArea, category); + Map stylesByKind = new HashMap(); + for (IncludeGroupStyle style : styles) { + if (style.getIncludeKind() != IncludeKind.MATCHING_PATTERN) + stylesByKind.put(style.getIncludeKind(), style); } - } - private void createCategoryEditor(Composite parent, Category category) { - IncludeGroupStyle style = null; - Key styleKey = category.getStyleKey(); - if (styleKey != null) { - IncludeKind includeKind = category.getIncludeKind(); - String str = getValue(styleKey); - if (str != null) - style = IncludeGroupStyle.fromString(str, includeKind); - if (style == null) - style = new IncludeGroupStyle(includeKind); - } - IncludeGroupStyleBlock block = new IncludeGroupStyleBlock(fContext, fProject, fContainer, - category.getDescription(), category.getGroupingKey(), style); - Control composite = block.createContents(parent); - - category.setEditorArea(composite); - - for (Category child : category.getChildren()) { - createCategoryEditor(parent, child); + for (Category category : categories.values()) { + IncludeGroupStyleBlock block = new IncludeGroupStyleBlock(fContext, fProject, fContainer, + category.getDescription()); + IncludeGroupStyle style = stylesByKind.get(category.getIncludeKind()); + block.setStyle(style); + Control composite = block.createContents(editorArea); + category.setEditor(block, composite); } } @Override protected void updateControls() { super.updateControls(); - // XXX Implement + // Refresh + categoryTree.refresh(); + updateConfigurationBlock(categoryTree.getSelectedElements()); + for (Category category : categories.values()) { + category.getEditor().updateControls(); + } } private void updateConfigurationBlock(List selection) { @@ -203,56 +168,29 @@ public class IncludeCategoriesBlock extends OptionsConfigurationBlock { editorAreaStack.topControl.getParent().layout(); } - @Override - public void performDefaults() { - super.performDefaults(); - - // Refresh - categoryTree.refresh(); - updateConfigurationBlock(categoryTree.getSelectedElements()); - } - - @Override - public boolean performOk() { - return super.performOk(); - } - @Override protected void validateSettings(Key changedKey, String oldValue, String newValue) { - StatusInfo status = new StatusInfo(); - fContext.statusChanged(status); + fContext.statusChanged(new StatusInfo()); } /** * Represents a category of settings. */ private final static class Category { - public final String name; - public final String description; public final Category parent; public final int index; // Index in the siblings list private final List children; - private IncludeKind includeKind; - private Key styleKey; - private Key groupingKey; - + private final IncludeKind includeKind; private Control editorArea; + private IncludeGroupStyleBlock editor; - Category(String name, String description, Category parent) { - this.name = name; - this.description = description; + Category(IncludeKind includeKind, Category parent) { + this.includeKind = includeKind; this.parent = parent; children = new ArrayList(); index = parent != null ? parent.addChild(this) : 0; } - /** - * @param name Category name - */ - Category(String name, String description) { - this(name, description, null); - } - private int addChild(Category category) { children.add(category); return children.size() - 1; @@ -268,47 +206,32 @@ public class IncludeCategoriesBlock extends OptionsConfigurationBlock { @Override public String toString() { - return name; + return includeKind.name; } IncludeKind getIncludeKind() { return includeKind; } - Category setIncludeKind(IncludeKind includeKind) { - this.includeKind = includeKind; - return this; - } - - Key getStyleKey() { - return styleKey; - } - - Category setStyleKey(Key key) { - this.styleKey = key; - return this; - } - - Key getGroupingKey() { - return groupingKey; - } - - Category setGroupingKey(Key key) { - this.groupingKey = key; - return this; + IncludeGroupStyleBlock getEditor() { + return editor; } Control getEditorArea() { return editorArea; } - Category setEditorArea(Control editorArea) { + void setEditor(IncludeGroupStyleBlock editor, Control editorArea) { + this.editor = editor; this.editorArea = editorArea; - return this; } - public String getDescription() { - return description; + String getName() { + return includeKind.name; + } + + String getDescription() { + return includeKind.description; } } @@ -364,7 +287,7 @@ public class IncludeCategoriesBlock extends OptionsConfigurationBlock { @Override public String getText(Object element) { - return ((Category) element).name; + return ((Category) element).getName(); } } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/IncludeGroupStyleBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/IncludeGroupStyleBlock.java index 0e0d3c8284d..487e722436a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/IncludeGroupStyleBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/IncludeGroupStyleBlock.java @@ -23,6 +23,7 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Widget; import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; import org.eclipse.cdt.utils.ui.controls.ControlFactory; @@ -36,20 +37,24 @@ import org.eclipse.cdt.internal.ui.refactoring.includes.IncludeGroupStyle; */ public class IncludeGroupStyleBlock extends OptionsConfigurationBlock { private final String description; - private final Key groupingKey; - private final IncludeGroupStyle style; - @SuppressWarnings("hiding") - private final ArrayList