# HG changeset patch # User timkelly # Date 1248982446 18000 # Node ID 3c5a41c680a8d846825b271909b97aa4b342f62f # Parent 8f5c938a2b9794c1552e5be6e57940ed1e230926 merge in fix for Carbide bug 9031 diff -r 8f5c938a2b97 -r 3c5a41c680a8 cdt/cdt_6_0_x/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/CElementBaseLabels.java --- a/cdt/cdt_6_0_x/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/CElementBaseLabels.java Thu Jul 30 14:23:38 2009 -0500 +++ b/cdt/cdt_6_0_x/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/CElementBaseLabels.java Thu Jul 30 14:34:06 2009 -0500 @@ -33,6 +33,7 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; /** * Creates labels for ICElement objects. @@ -758,7 +759,14 @@ if (rootQualified) { buf.append(container.getPath().makeRelative().toString()); } else { - buf.append(container.getElementName()); + if (CCorePlugin.showSourceRootsAtTopOfProject()) { + buf.append(container.getElementName()); + } + else { + String elementName = container.getElementName(); + IPath path = new Path(elementName); + buf.append(path.lastSegment()); + } if (getFlag(flags, ROOT_QUALIFIED)) { if (resource != null && container instanceof ISourceRoot && isReferenced((ISourceRoot)container)) { buf.append(CONCAT_STRING); diff -r 8f5c938a2b97 -r 3c5a41c680a8 cdt/cdt_6_0_x/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java --- a/cdt/cdt_6_0_x/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java Thu Jul 30 14:23:38 2009 -0500 +++ b/cdt/cdt_6_0_x/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java Thu Jul 30 14:34:06 2009 -0500 @@ -1170,7 +1170,15 @@ public static IUserVarSupplier getUserVarSupplier() { return UserVarSupplier.getInstance(); } - + /** + * Returns preference controlling whether source roots are shown at the top of projects + * or embedded within the resource tree of projects when they are not top level folders. + * + * @return boolean preference value + */ + public static boolean showSourceRootsAtTopOfProject() { + return getDefault().getPluginPreferences().getBoolean( CCorePreferenceConstants.SHOW_SOURCE_ROOTS_AT_TOP_LEVEL_OF_PROJECT) == true; + } // NON-API /** diff -r 8f5c938a2b97 -r 3c5a41c680a8 cdt/cdt_6_0_x/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePreferenceConstants.java --- a/cdt/cdt_6_0_x/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePreferenceConstants.java Thu Jul 30 14:23:38 2009 -0500 +++ b/cdt/cdt_6_0_x/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePreferenceConstants.java Thu Jul 30 14:34:06 2009 -0500 @@ -135,4 +135,9 @@ * Attempt to show source files for executable binaries. */ public static final String SHOW_SOURCE_FILES_IN_BINARIES = CCorePlugin.PLUGIN_ID + ".showSourceFilesInBinaries"; //$NON-NLS-1$ + + /** + * Show source roots at the top level of projects. + */ + public static final String SHOW_SOURCE_ROOTS_AT_TOP_LEVEL_OF_PROJECT = CCorePlugin.PLUGIN_ID + ".showSourceRootsAtTopLevelOfProject"; //$NON-NLS-1$ } diff -r 8f5c938a2b97 -r 3c5a41c680a8 cdt/cdt_6_0_x/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePreferenceInitializer.java --- a/cdt/cdt_6_0_x/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePreferenceInitializer.java Thu Jul 30 14:23:38 2009 -0500 +++ b/cdt/cdt_6_0_x/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePreferenceInitializer.java Thu Jul 30 14:34:06 2009 -0500 @@ -59,6 +59,8 @@ defaultPreferences.putBoolean(CCorePreferenceConstants.SHOW_SOURCE_FILES_IN_BINARIES, true); defaultPreferences.putBoolean(CCorePlugin.PREF_USE_STRUCTURAL_PARSE_MODE, false); + + defaultPreferences.putBoolean(CCorePreferenceConstants.SHOW_SOURCE_ROOTS_AT_TOP_LEVEL_OF_PROJECT, true); // indexer defaults IndexerPreferences.initializeDefaultPreferences(defaultPreferences); diff -r 8f5c938a2b97 -r 3c5a41c680a8 cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java --- a/cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java Thu Jul 30 14:23:38 2009 -0500 +++ b/cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java Thu Jul 30 14:34:06 2009 -0500 @@ -26,6 +26,7 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IArchive; @@ -389,6 +390,7 @@ List list= new ArrayList(); ICElement[] children = cproject.getChildren(); + for (int i= 0; i < children.length; i++) { ICElement child = children[i]; if (child instanceof ISourceRoot && child.getResource().getType() == IResource.PROJECT) { @@ -396,8 +398,12 @@ ICElement[] c2 = ((ISourceRoot)child).getChildren(); for (int k = 0; k < c2.length; ++k) list.add(c2[k]); - } else + } else if (CCorePlugin.showSourceRootsAtTopOfProject()) { list.add(child); + } else if (child instanceof ISourceRoot && + child.getResource().getParent().equals(cproject.getProject())) { + list.add(child); + } } Object[] objects = list.toArray(); @@ -576,16 +582,19 @@ // folder we have to exclude it as a normal child. if (o instanceof IFolder) { IFolder folder = (IFolder)o; - boolean found = false; + ISourceRoot root = null; for (int j = 0; j < roots.length; j++) { if (roots[j].getPath().equals(folder.getFullPath())) { - found = true; + root = roots[j]; break; } } // it is a sourceRoot skip it. - if (found) { - continue; + if (root != null) { + if (CCorePlugin.showSourceRootsAtTopOfProject()) + continue; + else + o = root; } } else if (o instanceof IFile){ boolean found = false; diff -r 8f5c938a2b97 -r 3c5a41c680a8 cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java --- a/cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java Thu Jul 30 14:23:38 2009 -0500 +++ b/cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java Thu Jul 30 14:34:06 2009 -0500 @@ -98,6 +98,7 @@ public static final String IMG_OBJS_TUNIT_RESOURCE_H= NAME_PREFIX + "ch_resource_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_TUNIT_RESOURCE_A= NAME_PREFIX + "asm_resource_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_SOURCE_ROOT= NAME_PREFIX + "sroot_obj.gif"; // $NON-NLS-1$ //$NON-NLS-1$ + public static final String IMG_OBJS_SOURCE2_ROOT= NAME_PREFIX + "sroot2_obj.gif"; // $NON-NLS-1$ //$NON-NLS-1$ public static final String IMG_OBJS_CFOLDER= NAME_PREFIX + "cfolder_obj.gif"; // $NON-NLS-1$ //$NON-NLS-1$ public static final String IMG_OBJS_CONFIG = NAME_PREFIX + "config.gif"; // $NON-NLS-1$ //$NON-NLS-1$ public static final String IMG_OBJS_ARCHIVE= NAME_PREFIX + "ar_obj.gif"; //$NON-NLS-1$ @@ -180,6 +181,7 @@ public static final ImageDescriptor DESC_OBJS_TUNIT_RESOURCE_H= createManaged(T_OBJ, IMG_OBJS_TUNIT_RESOURCE_H); public static final ImageDescriptor DESC_OBJS_TUNIT_RESOURCE_A= createManaged(T_OBJ, IMG_OBJS_TUNIT_RESOURCE_A); public static final ImageDescriptor DESC_OBJS_SOURCE_ROOT= createManaged(T_OBJ, IMG_OBJS_SOURCE_ROOT); + public static final ImageDescriptor DESC_OBJS_SOURCE2_ROOT= createManaged(T_OBJ, IMG_OBJS_SOURCE2_ROOT); public static final ImageDescriptor DESC_OBJS_CFOLDER= createManaged(T_OBJ, IMG_OBJS_CFOLDER); public static final ImageDescriptor DESC_OBJS_CONFIG = createManaged(T_OBJ, IMG_OBJS_CONFIG); public static final ImageDescriptor DESC_OBJS_ARCHIVE= createManaged(T_OBJ, IMG_OBJS_ARCHIVE); diff -r 8f5c938a2b97 -r 3c5a41c680a8 cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/AppearancePreferencePage.java --- a/cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/AppearancePreferencePage.java Thu Jul 30 14:23:38 2009 -0500 +++ b/cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/AppearancePreferencePage.java Thu Jul 30 14:34:06 2009 -0500 @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.ui.preferences; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Preferences; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; @@ -27,7 +28,10 @@ import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.PlatformUI; import org.osgi.service.prefs.BackingStoreException; +import org.eclipse.ui.navigator.CommonNavigator; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.CCorePreferenceConstants; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.PreferenceConstants; @@ -46,6 +50,7 @@ private SelectionButtonDialogField fOutlineGroupNamespaces; private SelectionButtonDialogField fCViewGroupIncludes; private SelectionButtonDialogField fCViewSeparateHeaderAndSource; + private SelectionButtonDialogField fShowSourceRootsAtTopOfProject; private SelectionButtonDialogField fOutlineGroupMembers; public AppearancePreferencePage() { @@ -81,6 +86,12 @@ fCViewSeparateHeaderAndSource= new SelectionButtonDialogField(SWT.CHECK); fCViewSeparateHeaderAndSource.setDialogFieldListener(listener); fCViewSeparateHeaderAndSource.setLabelText(PreferencesMessages.AppearancePreferencePage_cviewSeparateHeaderAndSource_label); + + fShowSourceRootsAtTopOfProject= new SelectionButtonDialogField(SWT.CHECK); + fShowSourceRootsAtTopOfProject.setDialogFieldListener(listener); + fShowSourceRootsAtTopOfProject.setLabelText(PreferencesMessages.AppearancePreferencePage_showSourceRootsAtTopOfProject_label); + + } private void initFields() { @@ -90,6 +101,8 @@ 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)); + boolean showSourceRootsAtTopOfProject = CCorePlugin.showSourceRootsAtTopOfProject(); + fShowSourceRootsAtTopOfProject.setSelection(showSourceRootsAtTopOfProject); fOutlineGroupMembers.setSelection(prefs.getBoolean(PreferenceConstants.OUTLINE_GROUP_MEMBERS)); } @@ -126,7 +139,6 @@ new Separator().doFillIntoGrid(result, nColumns); fCViewSeparateHeaderAndSource.doFillIntoGrid(result, nColumns); - String noteTitle= PreferencesMessages.AppearancePreferencePage_note; String noteMessage= PreferencesMessages.AppearancePreferencePage_preferenceOnlyForNewViews; Composite noteControl= createNoteComposite(JFaceResources.getDialogFont(), result, noteTitle, noteMessage); @@ -134,6 +146,10 @@ gd.horizontalSpan= 2; noteControl.setLayoutData(gd); + + new Separator().doFillIntoGrid(result, nColumns); + fShowSourceRootsAtTopOfProject.doFillIntoGrid(result, nColumns); + initFields(); Dialog.applyDialogFont(result); @@ -171,6 +187,8 @@ prefs.setValue(PreferenceConstants.OUTLINE_GROUP_INCLUDES, fOutlineGroupIncludes.isSelected()); prefs.setValue(PreferenceConstants.OUTLINE_GROUP_NAMESPACES, fOutlineGroupNamespaces.isSelected()); prefs.setValue(PreferenceConstants.OUTLINE_GROUP_MEMBERS, fOutlineGroupMembers.isSelected()); + CCorePlugin.getDefault().getPluginPreferences().setValue(CCorePreferenceConstants.SHOW_SOURCE_ROOTS_AT_TOP_LEVEL_OF_PROJECT, fShowSourceRootsAtTopOfProject.isSelected()); + CCorePlugin.getDefault().savePluginPreferences(); try { new InstanceScope().getNode(CUIPlugin.PLUGIN_ID).flush(); } catch (BackingStoreException exc) { @@ -185,6 +203,8 @@ @Override protected void performDefaults() { IPreferenceStore prefs= getPreferenceStore(); + Preferences corePrefs = CCorePlugin.getDefault().getPluginPreferences(); + fShowSourceRootsAtTopOfProject.setSelection(corePrefs.getDefaultBoolean(CCorePreferenceConstants.SHOW_SOURCE_ROOTS_AT_TOP_LEVEL_OF_PROJECT)); 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)); diff -r 8f5c938a2b97 -r 3c5a41c680a8 cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java --- a/cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java Thu Jul 30 14:23:38 2009 -0500 +++ b/cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java Thu Jul 30 14:34:06 2009 -0500 @@ -138,6 +138,7 @@ public static String AppearancePreferencePage_outlineGroupNamespaces_label; public static String AppearancePreferencePage_note; public static String AppearancePreferencePage_preferenceOnlyForNewViews; + public static String AppearancePreferencePage_showSourceRootsAtTopOfProject_label; public static String CEditorPreferencePage_folding_title; public static String FoldingConfigurationBlock_enable; public static String FoldingConfigurationBlock_combo_caption; diff -r 8f5c938a2b97 -r 3c5a41c680a8 cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties --- a/cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties Thu Jul 30 14:23:38 2009 -0500 +++ b/cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties Thu Jul 30 14:34:06 2009 -0500 @@ -157,6 +157,7 @@ AppearancePreferencePage_outlineGroupNamespaces_label= Group namespaces in the Outline view AppearancePreferencePage_note=Note: AppearancePreferencePage_preferenceOnlyForNewViews=This preference does not affect open views +AppearancePreferencePage_showSourceRootsAtTopOfProject_label=Show source roots at top of project #Folding CEditorPreferencePage_folding_title= &Folding diff -r 8f5c938a2b97 -r 3c5a41c680a8 cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CElementImageProvider.java --- a/cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CElementImageProvider.java Thu Jul 30 14:23:38 2009 -0500 +++ b/cdt/cdt_6_0_x/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CElementImageProvider.java Thu Jul 30 14:34:06 2009 -0500 @@ -14,8 +14,12 @@ package org.eclipse.cdt.internal.ui.viewsupport; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; @@ -23,6 +27,7 @@ import org.eclipse.ui.ide.IDE; import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IArchiveContainer; @@ -46,6 +51,9 @@ import org.eclipse.cdt.ui.CElementImageDescriptor; import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.internal.core.model.CModel; +import org.eclipse.cdt.internal.core.model.CModelManager; + import org.eclipse.cdt.internal.ui.CPluginImages; @@ -138,6 +146,9 @@ Point size= useSmallSize(flags) ? SMALL_SIZE : BIG_SIZE; descriptor = new CElementImageDescriptor(descriptor, 0, size); } + } else if (!CCorePlugin.showSourceRootsAtTopOfProject() && + element instanceof IFolder && isParentOfSourceRoot(element)) { + descriptor = CPluginImages.DESC_OBJS_SOURCE2_ROOT; } if (descriptor == null && element instanceof IAdaptable) { descriptor= getWorkbenchImageDescriptor((IAdaptable) element, flags); @@ -148,6 +159,24 @@ return null; } + private boolean isParentOfSourceRoot(Object element) { + IFolder folder = (IFolder)element; + ICProject cproject = CModelManager.getDefault().getCModel().findCProject(folder.getProject()); + if (cproject != null) { + try { + IPath folderPath = folder.getFullPath(); + for (ICElement sourceRoot : cproject.getSourceRoots()) { + if (folderPath.isPrefixOf(sourceRoot.getPath())) { + return true; + } + } + } catch (CModelException e) { + } + } + + return false; + } + public static ImageDescriptor getImageDescriptor(int type) { switch (type) { case ICElement.C_VCONTAINER: