diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/AppearancePreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/AppearancePreferencePage.java index f1309a7af00..c17405c373c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/AppearancePreferencePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/AppearancePreferencePage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2008 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.ui.preferences; @@ -41,15 +42,11 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.Separator; public class AppearancePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { - private static final String SHOW_TU_CHILDREN= PreferenceConstants.PREF_SHOW_CU_CHILDREN; - private static final String OUTLINE_GROUP_INCLUDES = PreferenceConstants.OUTLINE_GROUP_INCLUDES; - private static final String OUTLINE_GROUP_NAMESPACES = PreferenceConstants.OUTLINE_GROUP_NAMESPACES; - private static final String CVIEW_GROUP_INCLUDES = PreferenceConstants.CVIEW_GROUP_INCLUDES; - private SelectionButtonDialogField fShowTUChildren; private SelectionButtonDialogField fOutlineGroupIncludes; private SelectionButtonDialogField fOutlineGroupNamespaces; private SelectionButtonDialogField fCViewGroupIncludes; + private SelectionButtonDialogField fCViewSeparateHeaderAndSource; public AppearancePreferencePage() { setPreferenceStore(PreferenceConstants.getPreferenceStore()); @@ -77,14 +74,18 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben fCViewGroupIncludes.setDialogFieldListener(listener); fCViewGroupIncludes.setLabelText(PreferencesMessages.AppearancePreferencePage_cviewGroupIncludes_label); - } + fCViewSeparateHeaderAndSource= new SelectionButtonDialogField(SWT.CHECK); + fCViewSeparateHeaderAndSource.setDialogFieldListener(listener); + fCViewSeparateHeaderAndSource.setLabelText(PreferencesMessages.AppearancePreferencePage_cviewSeparateHeaderAndSource_label); + } private void initFields() { IPreferenceStore prefs= getPreferenceStore(); - fShowTUChildren.setSelection(prefs.getBoolean(SHOW_TU_CHILDREN)); - fCViewGroupIncludes.setSelection(prefs.getBoolean(CVIEW_GROUP_INCLUDES)); - fOutlineGroupIncludes.setSelection(prefs.getBoolean(OUTLINE_GROUP_INCLUDES)); - fOutlineGroupNamespaces.setSelection(prefs.getBoolean(OUTLINE_GROUP_NAMESPACES)); + fShowTUChildren.setSelection(prefs.getBoolean(PreferenceConstants.PREF_SHOW_CU_CHILDREN)); + fCViewGroupIncludes.setSelection(prefs.getBoolean(PreferenceConstants.CVIEW_GROUP_INCLUDES)); + fCViewSeparateHeaderAndSource.setSelection(prefs.getBoolean(PreferenceConstants.CVIEW_SEPARATE_HEADER_AND_SOURCE)); + fOutlineGroupIncludes.setSelection(prefs.getBoolean(PreferenceConstants.OUTLINE_GROUP_INCLUDES)); + fOutlineGroupNamespaces.setSelection(prefs.getBoolean(PreferenceConstants.OUTLINE_GROUP_NAMESPACES)); } /* @@ -110,17 +111,16 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben result.setLayout(layout); fShowTUChildren.doFillIntoGrid(result, nColumns); - fCViewGroupIncludes.doFillIntoGrid(result, nColumns); + fCViewGroupIncludes.doFillIntoGrid(result, nColumns); fOutlineGroupIncludes.doFillIntoGrid(result, nColumns); fOutlineGroupNamespaces.doFillIntoGrid(result, nColumns); new Separator().doFillIntoGrid(result, nColumns); + fCViewSeparateHeaderAndSource.doFillIntoGrid(result, nColumns); - new Separator().doFillIntoGrid(result, nColumns); - - String noteTitle= PreferencesMessages.AppearancePreferencePage_note; - String noteMessage= PreferencesMessages.AppearancePreferencePage_preferenceOnlyEffectiveForNewPerspectives; + String noteTitle= PreferencesMessages.AppearancePreferencePage_note; + String noteMessage= PreferencesMessages.AppearancePreferencePage_preferenceOnlyForNewViews; Composite noteControl= createNoteComposite(JFaceResources.getDialogFont(), result, noteTitle, noteMessage); GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); gd.horizontalSpan= 2; @@ -156,10 +156,11 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben */ public boolean performOk() { IPreferenceStore prefs= getPreferenceStore(); - prefs.setValue(SHOW_TU_CHILDREN, fShowTUChildren.isSelected()); - prefs.setValue(CVIEW_GROUP_INCLUDES, fCViewGroupIncludes.isSelected()); - prefs.setValue(OUTLINE_GROUP_INCLUDES, fOutlineGroupIncludes.isSelected()); - prefs.setValue(OUTLINE_GROUP_NAMESPACES, fOutlineGroupNamespaces.isSelected()); + prefs.setValue(PreferenceConstants.PREF_SHOW_CU_CHILDREN, fShowTUChildren.isSelected()); + prefs.setValue(PreferenceConstants.CVIEW_GROUP_INCLUDES, fCViewGroupIncludes.isSelected()); + prefs.setValue(PreferenceConstants.CVIEW_SEPARATE_HEADER_AND_SOURCE, fCViewSeparateHeaderAndSource.isSelected()); + prefs.setValue(PreferenceConstants.OUTLINE_GROUP_INCLUDES, fOutlineGroupIncludes.isSelected()); + prefs.setValue(PreferenceConstants.OUTLINE_GROUP_NAMESPACES, fOutlineGroupNamespaces.isSelected()); CUIPlugin.getDefault().savePluginPreferences(); return super.performOk(); } @@ -169,10 +170,11 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben */ protected void performDefaults() { IPreferenceStore prefs= getPreferenceStore(); - fShowTUChildren.setSelection(prefs.getDefaultBoolean(SHOW_TU_CHILDREN)); - fCViewGroupIncludes.setSelection(prefs.getDefaultBoolean(CVIEW_GROUP_INCLUDES)); - fOutlineGroupIncludes.setSelection(prefs.getDefaultBoolean(OUTLINE_GROUP_INCLUDES)); - fOutlineGroupNamespaces.setSelection(prefs.getDefaultBoolean(OUTLINE_GROUP_NAMESPACES)); + fShowTUChildren.setSelection(prefs.getDefaultBoolean(PreferenceConstants.PREF_SHOW_CU_CHILDREN)); + fCViewGroupIncludes.setSelection(prefs.getDefaultBoolean(PreferenceConstants.CVIEW_GROUP_INCLUDES)); + fCViewSeparateHeaderAndSource.setSelection(prefs.getDefaultBoolean(PreferenceConstants.CVIEW_SEPARATE_HEADER_AND_SOURCE)); + fOutlineGroupIncludes.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_INCLUDES)); + fOutlineGroupNamespaces.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_NAMESPACES)); super.performDefaults(); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java index ce70564f165..a1255440330 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java @@ -137,10 +137,11 @@ public final class PreferencesMessages extends NLS { public static String AppearancePreferencePage_description; public static String AppearancePreferencePage_showTUChildren_label; public static String AppearancePreferencePage_cviewGroupIncludes_label; + public static String AppearancePreferencePage_cviewSeparateHeaderAndSource_label; public static String AppearancePreferencePage_outlineGroupIncludes_label; public static String AppearancePreferencePage_outlineGroupNamespaces_label; public static String AppearancePreferencePage_note; - public static String AppearancePreferencePage_preferenceOnlyEffectiveForNewPerspectives; + public static String AppearancePreferencePage_preferenceOnlyForNewViews; public static String CEditorPreferencePage_folding_title; public static String FoldingConfigurationBlock_enable; public static String FoldingConfigurationBlock_combo_caption; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties index f74554c4c0d..b881d109020 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties @@ -149,14 +149,15 @@ CBufferPreferences_CodeReaderBuffer_Size=Size (MB) CEditorPreferencePage_behaviourPage_EnableEditorProblemAnnotation=Enable editor problem annotation #Appearance Preferences -AppearancePreferencePage_description= Appearance of C elements in viewers: +AppearancePreferencePage_description= Appearance of C/C++ elements in viewers: #AppearancePreferencePage.methodreturntype.label= Show &method return types AppearancePreferencePage_showTUChildren_label= Show translation unit members -AppearancePreferencePage_cviewGroupIncludes_label= Group the includes in the C/C++ projects view -AppearancePreferencePage_outlineGroupIncludes_label= Group the includes in the outliner -AppearancePreferencePage_outlineGroupNamespaces_label= Group the namespaces in the outliner +AppearancePreferencePage_cviewGroupIncludes_label= Group include directives in Project Explorer and C/C++ Projects view +AppearancePreferencePage_cviewSeparateHeaderAndSource_label= Sort header files before source files in Project Explorer and C/C++ Projects view +AppearancePreferencePage_outlineGroupIncludes_label= Group include directives in the Outline view +AppearancePreferencePage_outlineGroupNamespaces_label= Group namespaces in the Outline view AppearancePreferencePage_note=Note: -AppearancePreferencePage_preferenceOnlyEffectiveForNewPerspectives=This preference may only take effect on new perspectives +AppearancePreferencePage_preferenceOnlyForNewViews=This preference does not affect open views #Folding CEditorPreferencePage_folding_title= &Folding diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementSorter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementSorter.java index 3c4f738b629..83aa114d77a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementSorter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementSorter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. + * Copyright (c) 2005, 2008 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 @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * QNX Software System + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.ui; @@ -43,6 +44,7 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IStorage; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.ContentViewer; import org.eclipse.jface.viewers.IBaseLabelProvider; import org.eclipse.jface.viewers.ILabelProvider; @@ -104,7 +106,22 @@ public class CElementSorter extends ViewerSorter { protected static final int RESOURCES= 201; protected static final int STORAGE= 202; protected static final int OTHERS= 500; + + /** + * Flag indicating whether header files and source files should be separated. + * If true, header files will be sorted before source files, + * otherwise header and source files will be sorted by name. + */ + private boolean fSeparateHeaderAndSource; + /** + * Default constructor for use as executable extension. + */ + public CElementSorter() { + final IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore(); + fSeparateHeaderAndSource= store.getBoolean(PreferenceConstants.CVIEW_SEPARATE_HEADER_AND_SOURCE); + } + public int category (Object element) { if (element instanceof ICModel) { return CMODEL; @@ -120,11 +137,13 @@ public class CElementSorter extends ViewerSorter { return CCONTAINERS; } else if (element instanceof ITranslationUnit) { ITranslationUnit tu = (ITranslationUnit)element; - if (CoreModel.isValidHeaderUnitName(tu.getCProject().getProject(), tu.getElementName())) { - return TRANSLATIONUNIT_HEADERS; - } - if (CoreModel.isValidSourceUnitName(tu.getCProject().getProject(), tu.getElementName())) { - return TRANSLATIONUNIT_SOURCE; + if (fSeparateHeaderAndSource) { + if (CoreModel.isValidHeaderUnitName(tu.getCProject().getProject(), tu.getElementName())) { + return TRANSLATIONUNIT_HEADERS; + } + if (CoreModel.isValidSourceUnitName(tu.getCProject().getProject(), tu.getElementName())) { + return TRANSLATIONUNIT_SOURCE; + } } return TRANSLATIONUNITS; } else if (element instanceof IInclude) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java index 0d840be1f76..8b8e937e34f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java @@ -718,7 +718,7 @@ public class PreferenceConstants { public static final String ID_BESTMATCH_HOVER= "org.eclipse.cdt.ui.BestMatchHover"; //$NON-NLS-1$ /** - * A named preference that controls if the Outline view. + * A named preference that controls whether the Outline view should group include directives. *

* Value is of type Boolean. *

@@ -726,7 +726,7 @@ public class PreferenceConstants { public static final String OUTLINE_GROUP_INCLUDES= "org.eclipse.cdt.ui.outline.groupincludes"; //$NON-NLS-1$ /** - * A named preference that controls if the Outline view. + * A named preference that controls whether the Outline view should group namespaces. *

* Value is of type Boolean. *

@@ -735,7 +735,7 @@ public class PreferenceConstants { /** - * A named preference that controls whether the outline view + * A named preference that controls whether the Outline view * selection should stay in sync with with the element at the current cursor position. *

* Value is of type Boolean. @@ -744,13 +744,25 @@ public class PreferenceConstants { public static final String OUTLINE_LINK_TO_EDITOR = "org.eclipse.cdt.ui.outline.linktoeditor"; //$NON-NLS-1$ /** - * A named preference that controls if the CView. + * A named preference that controls whether include directives should be grouped in the + * C/C++ Projects view and the Project Explorer view. *

* Value is of type Boolean. *

*/ public static final String CVIEW_GROUP_INCLUDES= "org.eclipse.cdt.ui.cview.groupincludes"; //$NON-NLS-1$ + /** + * A named preference that controls whether header and source files should be separated in the + * C/C++ Projects view and the Project Explorer view. + *

+ * Value is of type Boolean. + *

+ * + * @since 5.0 + */ + public static final String CVIEW_SEPARATE_HEADER_AND_SOURCE= "org.eclipse.cdt.ui.cview.separateheaderandsource"; //$NON-NLS-1$ + /** * A named preference that controls which completion proposal categories * have been excluded from the default proposal list. diff --git a/doc/org.eclipse.cdt.doc.user/contexts_CDT.xml b/doc/org.eclipse.cdt.doc.user/contexts_CDT.xml index e8d707f1708..3a04a1f15f3 100644 --- a/doc/org.eclipse.cdt.doc.user/contexts_CDT.xml +++ b/doc/org.eclipse.cdt.doc.user/contexts_CDT.xml @@ -349,5 +349,9 @@ Allows you to switch mark occurrences on and off. + + Customize the appearance of C/C++ elements in viewers. + + diff --git a/doc/org.eclipse.cdt.doc.user/images/view_appearance_prefs.png b/doc/org.eclipse.cdt.doc.user/images/view_appearance_prefs.png index a5a92bc10e2..2fb57f4637a 100644 Binary files a/doc/org.eclipse.cdt.doc.user/images/view_appearance_prefs.png and b/doc/org.eclipse.cdt.doc.user/images/view_appearance_prefs.png differ diff --git a/doc/org.eclipse.cdt.doc.user/reference/cdt_u_appearance_pref.htm b/doc/org.eclipse.cdt.doc.user/reference/cdt_u_appearance_pref.htm index 4af86243fe2..2493c35eca1 100644 --- a/doc/org.eclipse.cdt.doc.user/reference/cdt_u_appearance_pref.htm +++ b/doc/org.eclipse.cdt.doc.user/reference/cdt_u_appearance_pref.htm @@ -13,7 +13,7 @@

Appearance preferences

Use the Appearance panel of the Preferences window to customize the appearance of C elements in the viewers.

-

+

- - + + - - + + - - + + - - + + + + + +
@@ -25,20 +25,24 @@
Show translation unit numbers Select this option to show translation unit numbers. Show translation unit members Select this option to show translation unit members in Project Explorer and C/C++ Projects view.
Group the includes in the C/C++ projects view Select this option to group include files in the C/C++ project view. Group include directives in Project Explorer and C/C++ Projects view Select this option to group include directives in Project Explorer and C/C++ Projects view.
Group the includes in the outliner Select this option to group include files in outline views. Group include directives in the Outline view Select this option to group include directives in the Outline view.
Group the namespaces in the outliner Select this option to group files by namespaces in outline views. Group namespaces in the Outline view Select this option to group namespace declarations in the Outline view.
Sort header files before source files in Project Explorer and C/C++ Projects view Select this option to separate header and source files in Project Explorer and C/C++ Projects view.