From 911ecee8ebd05d278aa068f57edac16d4240643d Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 6 Jan 2012 18:36:08 -0500 Subject: [PATCH] bug 279502: User friendly icons under Includes node in Project Explorer --- core/org.eclipse.cdt.ui/plugin.properties | 9 ++- core/org.eclipse.cdt.ui/plugin.xml | 39 +++++++--- .../ui/cview/CViewContentProvider.java | 30 ++++---- .../internal/ui/cview/CViewLabelProvider.java | 35 +++++---- .../ui/newui/LanguageSettingsImages.java | 2 +- .../viewsupport/IncludeFolderDecorator.java | 76 +++++++++++++++++++ 6 files changed, 149 insertions(+), 42 deletions(-) create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IncludeFolderDecorator.java diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index 60abac21cd9..07261fd7396 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -544,8 +544,6 @@ WriteOccurrenceAnnotation.label= C/C++ Write Occurrences DocCommentOwner.name = DocCommentOwner Doxygen.name = Doxygen -indexedFilesDecorator.label = C/C++ Indexed Files - # Hyperlinking cEditorHyperlinkTarget= C/C++ Editor cElementHyperlinkDetector= C/C++ Elements @@ -598,7 +596,12 @@ ShiftRightAction.label= &Shift Right ShiftLeftAction.label= S&hift Left # Decorators -excluded-file.name = C/C++ Files Excluded from Build +indexedFilesDecorator.label = C/C++ Indexed Files +indexedFilesDecorator.description = Decorates files indexed by C/C++ Indexer. +excludedFile.name = C/C++ Files Excluded from Build +excludedFile.description = Decorates source files excluded from C/C++ build. +includeFolderDecorator.name = C/C++ Missing Include Folders +includeFolderDecorator.description = Decorates missing include folders with error/warning indicator. templatesViewName= Templates diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 66b12967dc3..aa1b14bde18 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -4043,6 +4043,7 @@ label="%indexedFilesDecorator.label" lightweight="true" state="false"> + %indexedFilesDecorator.description @@ -4050,6 +4051,34 @@ + + %excludedFile.description + + + + + + %includeFolderDecorator.description + + + + + + + @@ -4247,16 +4276,6 @@ - - - - - - - 0) { extras = new Object[] {archive}; } - IBinaryContainer bin = cproject.getBinaryContainer(); + IBinaryContainer bin = cproject.getBinaryContainer(); if (getExecutables(bin).length > 0) { Object[] o = new Object[] {bin}; if (extras != null && extras.length > 0) { @@ -151,7 +152,7 @@ public class CViewContentProvider extends CElementContentProvider { extras = o; } } - + IncludeRefContainer incRefCont = new IncludeRefContainer(cproject); Object[] incRefs = incRefCont.getChildren(cproject); if (incRefs != null && incRefs.length > 0) { @@ -230,17 +231,16 @@ public class CViewContentProvider extends CElementContentProvider { return (ars != null) && ars.length > 0; } catch (CModelException e) { return false; - } + } } else if (element instanceof IncludeReferenceProxy) { - IIncludeReference ref = ((IncludeReferenceProxy)element).getReference(); - IPath location = ref.getPath(); - IContainer[] containers = ref.getCModel().getWorkspace().getRoot().findContainersForLocation(location); - for (int i = 0; i < containers.length; ++i) { - if (containers[i].isAccessible()) { - return false; - } + IIncludeReference reference = ((IncludeReferenceProxy)element).getReference(); + IContainer container = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(reference.getPath()); + if (container != null) { + // do not allow to navigate to workspace containers inside "Includes" node + return false; } + return reference.hasChildren(); } return super.hasChildren(element); } @@ -266,5 +266,5 @@ public class CViewContentProvider extends CElementContentProvider { } super.inputChanged(viewer, oldInput, newInput); } - + } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewLabelProvider.java index 4d326cd5d05..5608d8a5ef6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewLabelProvider.java @@ -21,24 +21,25 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.StyledString; import org.eclipse.swt.graphics.Image; -import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.IIncludeReference; import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.ui.CDTSharedImages; import org.eclipse.cdt.ui.CElementImageDescriptor; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.corext.util.Strings; +import org.eclipse.cdt.internal.ui.newui.LanguageSettingsImages; import org.eclipse.cdt.internal.ui.viewsupport.AppearanceAwareLabelProvider; import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; /* - * CViewLabelProvider + * CViewLabelProvider */ public class CViewLabelProvider extends AppearanceAwareLabelProvider { - + public CViewLabelProvider(long textFlags, int imageFlags) { super(textFlags, imageFlags); } @@ -92,14 +93,14 @@ public class CViewLabelProvider extends AppearanceAwareLabelProvider { p = p.removeFirstSegments(parentLocation.segmentCount()); } return decorateText(p.toString(), element); - } + } } return super.getText(element); } - + @Override public StyledString getStyledText(Object element) { - return Strings.markLTR(new StyledString(getText(element))); + return Strings.markLTR(new StyledString(getText(element))); } /* (non-Javadoc) @@ -107,20 +108,28 @@ public class CViewLabelProvider extends AppearanceAwareLabelProvider { */ @Override public Image getImage(Object element) { + String imageKey = null; if (element instanceof IncludeReferenceProxy) { IIncludeReference reference = ((IncludeReferenceProxy)element).getReference(); - IPath path = reference.getPath(); - IContainer container = reference.getCModel().getWorkspace().getRoot().getContainerForLocation(path); - if (container != null && container.isAccessible()) { - ImageDescriptor desc = CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_OBJS_INCLUDES_FOLDER_WORKSPACE); - desc = new CElementImageDescriptor(desc, 0, CElementImageProvider.SMALL_SIZE); - return CUIPlugin.getImageDescriptorRegistry().get(desc); + IContainer container = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(reference.getPath()); + if (container != null) { + ICProject cproject = reference.getCProject(); + IProject project = (cproject != null) ? cproject.getProject() : null; + boolean isProjectRelative = container.getProject().equals(project); + imageKey = LanguageSettingsImages.getImageKey(ICSettingEntry.INCLUDE_PATH, ICSettingEntry.VALUE_WORKSPACE_PATH, isProjectRelative); + } else { + imageKey = CDTSharedImages.IMG_OBJS_INCLUDES_FOLDER; } } else if (element instanceof IIncludeReference) { - ImageDescriptor desc = CElementImageProvider.getImageDescriptor(ICElement.C_CCONTAINER); + imageKey = CDTSharedImages.IMG_OBJS_CFOLDER; + } + + if (imageKey != null) { + ImageDescriptor desc = CDTSharedImages.getImageDescriptor(imageKey); desc = new CElementImageDescriptor(desc, 0, CElementImageProvider.SMALL_SIZE); return CUIPlugin.getImageDescriptorRegistry().get(desc); } + return super.getImage(element); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java index e2166fb7d75..2f96922703a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java @@ -35,7 +35,7 @@ public class LanguageSettingsImages { /** * @return the base key for the image. */ - private static String getImageKey(int kind, int flag, boolean isProjectRelative) { + public static String getImageKey(int kind, int flag, boolean isProjectRelative) { String imageKey = null; boolean isWorkspacePath = (flag & ICSettingEntry.VALUE_WORKSPACE_PATH) != 0; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IncludeFolderDecorator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IncludeFolderDecorator.java new file mode 100644 index 00000000000..31758daad28 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IncludeFolderDecorator.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2010, 2012 Andrew Gvozdev 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: + * Andrew Gvozdev - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.viewsupport; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.preference.JFacePreferences; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.viewers.IDecoration; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ILightweightLabelDecorator; + +import org.eclipse.cdt.core.model.IIncludeReference; +import org.eclipse.cdt.ui.CDTSharedImages; + +import org.eclipse.cdt.internal.ui.cview.IncludeReferenceProxy; + +/** + * Determines whether an include folder under "Includes" node does exist + * and if not decorates the file's icon with warning overlay and + * renders the label using the qualifier (gray) color. + */ +public class IncludeFolderDecorator implements ILightweightLabelDecorator { + @Override + public void decorate(Object element, IDecoration decoration) { + boolean isAccesible = true; + + if (element instanceof IncludeReferenceProxy) { + IIncludeReference reference = ((IncludeReferenceProxy)element).getReference(); + IPath path = reference.getPath(); + IContainer container = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(path); + if (container != null) { + isAccesible = container.isAccessible(); + } else { + isAccesible = path.toFile().exists(); + } + } else if (element instanceof IIncludeReference) { + IPath path = ((IIncludeReference) element).getPath(); + isAccesible = path.toFile().exists(); + } + + if (!isAccesible) { + decoration.addOverlay(CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_OVR_WARNING)); + // JFacePreferences.QUALIFIER_COLOR colors label in gray + decoration.setForegroundColor(JFaceResources.getColorRegistry().get(JFacePreferences.QUALIFIER_COLOR)); + } + } + + @Override + public void addListener(ILabelProviderListener listener) { + // We don't track state changes + } + + @Override + public void dispose() { + } + + @Override + public boolean isLabelProperty(Object element, String property) { + return false; + } + + @Override + public void removeListener(ILabelProviderListener listener) { + // We don't track state changes + } +} \ No newline at end of file