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 7c5f124fc5a..bf05078e769 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, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 @@ -54,6 +54,7 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben private SelectionButtonDialogField fOutlineGroupMembers; private SelectionButtonDialogField fOutlineGroupMacros; private SelectionButtonDialogField fShowSourceRootsAtTopOfProject; + private SelectionButtonDialogField fCViewSortOrderOfExcludedFiles; public AppearancePreferencePage() { @@ -100,7 +101,11 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben fCViewGroupMacros= new SelectionButtonDialogField(SWT.CHECK); fCViewGroupMacros.setDialogFieldListener(listener); - fCViewGroupMacros.setLabelText(PreferencesMessages.AppearancePreferencePage_cviewGroupMacros_label); + fCViewGroupMacros.setLabelText(PreferencesMessages.AppearancePreferencePage_cviewGroupMacros_label); + + fCViewSortOrderOfExcludedFiles= new SelectionButtonDialogField(SWT.CHECK); + fCViewSortOrderOfExcludedFiles.setDialogFieldListener(listener); + fCViewSortOrderOfExcludedFiles.setLabelText(PreferencesMessages.AppearancePreferencePage_cviewKeepSortOrderOfExcludedFiles_label); } private void initFields() { @@ -115,6 +120,7 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben fOutlineGroupMacros.setSelection(prefs.getBoolean(PreferenceConstants.OUTLINE_GROUP_MACROS)); boolean showSourceRootsAtTopOfProject = CCorePlugin.showSourceRootsAtTopOfProject(); fShowSourceRootsAtTopOfProject.setSelection(showSourceRootsAtTopOfProject); + fCViewSortOrderOfExcludedFiles.setSelection(prefs.getBoolean(PreferenceConstants.SORT_ORDER_OF_EXCLUDED_FILES)); } /* @@ -152,6 +158,7 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben new Separator().doFillIntoGrid(result, nColumns); fCViewSeparateHeaderAndSource.doFillIntoGrid(result, nColumns); + fCViewSortOrderOfExcludedFiles.doFillIntoGrid(result, nColumns); String noteTitle= PreferencesMessages.AppearancePreferencePage_note; String noteMessage= PreferencesMessages.AppearancePreferencePage_preferenceOnlyForNewViews; @@ -203,9 +210,10 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben prefs.setValue(PreferenceConstants.OUTLINE_GROUP_NAMESPACES, fOutlineGroupNamespaces.isSelected()); prefs.setValue(PreferenceConstants.OUTLINE_GROUP_MEMBERS, fOutlineGroupMembers.isSelected()); prefs.setValue(PreferenceConstants.OUTLINE_GROUP_MACROS, fOutlineGroupMacros.isSelected()); + prefs.setValue(PreferenceConstants.SORT_ORDER_OF_EXCLUDED_FILES, fCViewSortOrderOfExcludedFiles.isSelected()); try { - new InstanceScope().getNode(CUIPlugin.PLUGIN_ID).flush(); - IEclipsePreferences corePluginNode = new InstanceScope().getNode(CCorePlugin.PLUGIN_ID); + InstanceScope.INSTANCE.getNode(CUIPlugin.PLUGIN_ID).flush(); + IEclipsePreferences corePluginNode = InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID); corePluginNode.putBoolean( CCorePreferenceConstants.SHOW_SOURCE_ROOTS_AT_TOP_LEVEL_OF_PROJECT, fShowSourceRootsAtTopOfProject.isSelected()); @@ -230,8 +238,9 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben fOutlineGroupNamespaces.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_NAMESPACES)); fOutlineGroupMembers.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_MEMBERS)); fOutlineGroupMacros.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_MACROS)); - boolean showSourceRootsPref = new DefaultScope().getNode(CCorePlugin.PLUGIN_ID).getBoolean(CCorePreferenceConstants.SHOW_SOURCE_ROOTS_AT_TOP_LEVEL_OF_PROJECT, true); + boolean showSourceRootsPref = DefaultScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID).getBoolean(CCorePreferenceConstants.SHOW_SOURCE_ROOTS_AT_TOP_LEVEL_OF_PROJECT, true); fShowSourceRootsAtTopOfProject.setSelection(showSourceRootsPref); + fCViewSortOrderOfExcludedFiles.setSelection(prefs.getDefaultBoolean(PreferenceConstants.SORT_ORDER_OF_EXCLUDED_FILES)); 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 15addb7640b..66d55bc62a7 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 @@ -140,6 +140,7 @@ public final class PreferencesMessages extends NLS { public static String AppearancePreferencePage_showTUChildren_label; public static String AppearancePreferencePage_cviewGroupIncludes_label; public static String AppearancePreferencePage_cviewSeparateHeaderAndSource_label; + public static String AppearancePreferencePage_cviewKeepSortOrderOfExcludedFiles_label; public static String AppearancePreferencePage_cviewGroupMacros_label; public static String AppearancePreferencePage_outlineGroupIncludes_label; public static String AppearancePreferencePage_outlineGroupMethods_label; 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 27c4f78e5c8..b1b938601e7 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 @@ -159,13 +159,14 @@ 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 include directives in Project Explorer and C/C++ Projects view +AppearancePreferencePage_cviewKeepSortOrderOfExcludedFiles_label=Keep sort order of excluded sources 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_cviewGroupMacros_label= Group macro definitions in Project Explorer and C/C++ Projects view AppearancePreferencePage_outlineGroupIncludes_label= Group include directives in the Outline view AppearancePreferencePage_outlineGroupMethods_label=Group method definitions in the Outline view AppearancePreferencePage_outlineGroupNamespaces_label= Group namespaces in the Outline view AppearancePreferencePage_note=Note: -AppearancePreferencePage_preferenceOnlyForNewViews=This preference does not affect open views +AppearancePreferencePage_preferenceOnlyForNewViews=These two preferences do not affect open views AppearancePreferencePage_outlineGroupMacros_label=Group macro definitions in the Outline view AppearancePreferencePage_showSourceRootsAtTopOfProject_label=Show source roots at top of project 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 4e19ab3fbd6..58485bb8556 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, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2011 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 @@ -15,6 +15,7 @@ package org.eclipse.cdt.ui; import java.util.Comparator; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IStorage; import org.eclipse.core.runtime.IAdaptable; @@ -124,6 +125,8 @@ public class CElementSorter extends ViewerSorter { * otherwise header and source files will be sorted by name. */ private boolean fSeparateHeaderAndSource; + + private boolean fKeepSortOrderOfExcludedFiles; /** * Default constructor for use as executable extension. @@ -131,6 +134,7 @@ public class CElementSorter extends ViewerSorter { public CElementSorter() { final IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore(); fSeparateHeaderAndSource= store.getBoolean(PreferenceConstants.CVIEW_SEPARATE_HEADER_AND_SOURCE); + fKeepSortOrderOfExcludedFiles= store.getBoolean(PreferenceConstants.SORT_ORDER_OF_EXCLUDED_FILES); } @Override @@ -159,15 +163,7 @@ public class CElementSorter extends ViewerSorter { } return CCONTAINERS; case ICElement.C_UNIT: - if (fSeparateHeaderAndSource) { - if (CoreModel.isValidHeaderUnitName(cElement.getCProject().getProject(), cElement.getElementName())) { - return TRANSLATIONUNIT_HEADERS; - } - if (CoreModel.isValidSourceUnitName(cElement.getCProject().getProject(), cElement.getElementName())) { - return TRANSLATIONUNIT_SOURCE; - } - } - return TRANSLATIONUNITS; + return getTranslationUnitCategory(cElement.getCProject().getProject(), cElement.getElementName()); case ICElement.C_INCLUDE: return INCLUDES; case ICElement.C_MACRO: @@ -219,7 +215,11 @@ public class CElementSorter extends ViewerSorter { return PROJECTS; case IResource.FOLDER: return RESOURCEFOLDERS; - default: + default: // translation unit that was excluded from the build + if(fKeepSortOrderOfExcludedFiles && + CoreModel.isValidTranslationUnitName(resource.getProject(), resource.getName())) { + return getTranslationUnitCategory(resource.getProject(), resource.getName()); + } return RESOURCES; } } else if (element instanceof IStorage) { @@ -254,6 +254,18 @@ public class CElementSorter extends ViewerSorter { } return NORMAL; } + + private int getTranslationUnitCategory(IProject project, String name) { + if (fSeparateHeaderAndSource) { + if (CoreModel.isValidHeaderUnitName(project, name)) { + return TRANSLATIONUNIT_HEADERS; + } + if (CoreModel.isValidSourceUnitName(project, name)) { + return TRANSLATIONUNIT_SOURCE; + } + } + return TRANSLATIONUNITS; + } @Override public int compare(Viewer viewer, Object e1, Object e2) { @@ -314,6 +326,8 @@ public class CElementSorter extends ViewerSorter { if (name1.length() > 0 && name1.charAt(0) == '~') { name1 = name1.substring(1); } + } else if (e1 instanceof IResource) { + name1 = ((IResource)e1).getName(); } else { name1 = e1.toString(); } @@ -327,6 +341,8 @@ public class CElementSorter extends ViewerSorter { if (name2.length() > 0 && name2.charAt(0) == '~') { name2 = name2.substring(1); } + } else if(e2 instanceof IResource) { + name2 = ((IResource)e2).getName(); } else { name2 = e2.toString(); } 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 4051ccf89f1..b1ad0c3bf24 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2011 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 @@ -803,7 +803,18 @@ public class PreferenceConstants { * @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 whether the sorting order of source files should be changed + * in the C/C++ Projects view and the Project Explorer view when they are excluded from build. + *
+ * Value is of type Boolean
.
+ *