mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-14 20:45:22 +02:00
bug 279502: User friendly icons under Includes node in Project Explorer
This commit is contained in:
parent
3e5942e142
commit
911ecee8eb
6 changed files with 149 additions and 42 deletions
|
@ -544,8 +544,6 @@ WriteOccurrenceAnnotation.label= C/C++ Write Occurrences
|
||||||
DocCommentOwner.name = DocCommentOwner
|
DocCommentOwner.name = DocCommentOwner
|
||||||
Doxygen.name = Doxygen
|
Doxygen.name = Doxygen
|
||||||
|
|
||||||
indexedFilesDecorator.label = C/C++ Indexed Files
|
|
||||||
|
|
||||||
# Hyperlinking
|
# Hyperlinking
|
||||||
cEditorHyperlinkTarget= C/C++ Editor
|
cEditorHyperlinkTarget= C/C++ Editor
|
||||||
cElementHyperlinkDetector= C/C++ Elements
|
cElementHyperlinkDetector= C/C++ Elements
|
||||||
|
@ -598,7 +596,12 @@ ShiftRightAction.label= &Shift Right
|
||||||
ShiftLeftAction.label= S&hift Left
|
ShiftLeftAction.label= S&hift Left
|
||||||
|
|
||||||
# Decorators
|
# 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
|
templatesViewName= Templates
|
||||||
|
|
||||||
|
|
|
@ -4043,6 +4043,7 @@
|
||||||
label="%indexedFilesDecorator.label"
|
label="%indexedFilesDecorator.label"
|
||||||
lightweight="true"
|
lightweight="true"
|
||||||
state="false">
|
state="false">
|
||||||
|
<description>%indexedFilesDecorator.description</description>
|
||||||
<enablement>
|
<enablement>
|
||||||
<or>
|
<or>
|
||||||
<objectClass name="org.eclipse.cdt.core.model.ITranslationUnit"/>
|
<objectClass name="org.eclipse.cdt.core.model.ITranslationUnit"/>
|
||||||
|
@ -4050,6 +4051,34 @@
|
||||||
</or>
|
</or>
|
||||||
</enablement>
|
</enablement>
|
||||||
</decorator>
|
</decorator>
|
||||||
|
<decorator
|
||||||
|
adaptable="true"
|
||||||
|
class="org.eclipse.cdt.internal.ui.viewsupport.ExcludedFileDecorator"
|
||||||
|
id="org.eclipse.cdt.managedbuilder.ui.excludedFile"
|
||||||
|
label="%excludedFile.name"
|
||||||
|
lightweight="true"
|
||||||
|
state="true">
|
||||||
|
<description>%excludedFile.description</description>
|
||||||
|
<enablement>
|
||||||
|
<objectClass name="org.eclipse.core.resources.IFile" />
|
||||||
|
</enablement>
|
||||||
|
</decorator>
|
||||||
|
<decorator
|
||||||
|
adaptable="true"
|
||||||
|
class="org.eclipse.cdt.internal.ui.viewsupport.IncludeFolderDecorator"
|
||||||
|
id="org.eclipse.cdt.managedbuilder.ui.includeFolder"
|
||||||
|
label="%includeFolderDecorator.name"
|
||||||
|
lightweight="true"
|
||||||
|
location="BOTTOM_LEFT"
|
||||||
|
state="true">
|
||||||
|
<description>%includeFolderDecorator.description</description>
|
||||||
|
<enablement>
|
||||||
|
<or>
|
||||||
|
<objectClass name="org.eclipse.cdt.internal.ui.cview.IncludeReferenceProxy" />
|
||||||
|
<objectClass name="org.eclipse.cdt.core.model.IIncludeReference" />
|
||||||
|
</or>
|
||||||
|
</enablement>
|
||||||
|
</decorator>
|
||||||
</extension>
|
</extension>
|
||||||
|
|
||||||
<!-- Hyperlinking support -->
|
<!-- Hyperlinking support -->
|
||||||
|
@ -4247,16 +4276,6 @@
|
||||||
</complexArray>
|
</complexArray>
|
||||||
</processType>
|
</processType>
|
||||||
</extension>
|
</extension>
|
||||||
<extension point="org.eclipse.ui.decorators">
|
|
||||||
<decorator adaptable="true"
|
|
||||||
class="org.eclipse.cdt.internal.ui.viewsupport.ExcludedFileDecorator"
|
|
||||||
id="org.eclipse.cdt.managedbuilder.ui.excludedFile" label="%excluded-file.name"
|
|
||||||
lightweight="true" state="true">
|
|
||||||
<enablement>
|
|
||||||
<objectClass name="org.eclipse.core.resources.IFile" />
|
|
||||||
</enablement>
|
|
||||||
</decorator>
|
|
||||||
</extension>
|
|
||||||
<extension
|
<extension
|
||||||
point="org.eclipse.ui.commands">
|
point="org.eclipse.ui.commands">
|
||||||
<command
|
<command
|
||||||
|
|
|
@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.ui.cview;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IContainer;
|
import org.eclipse.core.resources.IContainer;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.jface.viewers.TreeViewer;
|
import org.eclipse.jface.viewers.TreeViewer;
|
||||||
import org.eclipse.jface.viewers.Viewer;
|
import org.eclipse.jface.viewers.Viewer;
|
||||||
|
@ -44,7 +45,7 @@ public class CViewContentProvider extends CElementContentProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public CViewContentProvider(TreeViewer viewer, IWorkbenchPartSite site) {
|
public CViewContentProvider(TreeViewer viewer, IWorkbenchPartSite site) {
|
||||||
super();
|
super();
|
||||||
|
@ -84,7 +85,7 @@ public class CViewContentProvider extends CElementContentProvider {
|
||||||
objs = fManager.getChildren(element);
|
objs = fManager.getChildren(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objs == null) {
|
if (objs == null) {
|
||||||
objs = super.getChildren(element);
|
objs = super.getChildren(element);
|
||||||
}
|
}
|
||||||
|
@ -125,14 +126,14 @@ public class CViewContentProvider extends CElementContentProvider {
|
||||||
}
|
}
|
||||||
return ref.getChildren();
|
return ref.getChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object[] getProjectChildren(ICProject cproject) throws CModelException {
|
private Object[] getProjectChildren(ICProject cproject) throws CModelException {
|
||||||
Object[] extras = null;
|
Object[] extras = null;
|
||||||
IArchiveContainer archive = cproject.getArchiveContainer();
|
IArchiveContainer archive = cproject.getArchiveContainer();
|
||||||
if (getArchives(archive).length > 0) {
|
if (getArchives(archive).length > 0) {
|
||||||
extras = new Object[] {archive};
|
extras = new Object[] {archive};
|
||||||
}
|
}
|
||||||
IBinaryContainer bin = cproject.getBinaryContainer();
|
IBinaryContainer bin = cproject.getBinaryContainer();
|
||||||
if (getExecutables(bin).length > 0) {
|
if (getExecutables(bin).length > 0) {
|
||||||
Object[] o = new Object[] {bin};
|
Object[] o = new Object[] {bin};
|
||||||
if (extras != null && extras.length > 0) {
|
if (extras != null && extras.length > 0) {
|
||||||
|
@ -151,7 +152,7 @@ public class CViewContentProvider extends CElementContentProvider {
|
||||||
extras = o;
|
extras = o;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IncludeRefContainer incRefCont = new IncludeRefContainer(cproject);
|
IncludeRefContainer incRefCont = new IncludeRefContainer(cproject);
|
||||||
Object[] incRefs = incRefCont.getChildren(cproject);
|
Object[] incRefs = incRefCont.getChildren(cproject);
|
||||||
if (incRefs != null && incRefs.length > 0) {
|
if (incRefs != null && incRefs.length > 0) {
|
||||||
|
@ -230,17 +231,16 @@ public class CViewContentProvider extends CElementContentProvider {
|
||||||
return (ars != null) && ars.length > 0;
|
return (ars != null) && ars.length > 0;
|
||||||
} catch (CModelException e) {
|
} catch (CModelException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (element instanceof IncludeReferenceProxy) {
|
} else if (element instanceof IncludeReferenceProxy) {
|
||||||
IIncludeReference ref = ((IncludeReferenceProxy)element).getReference();
|
IIncludeReference reference = ((IncludeReferenceProxy)element).getReference();
|
||||||
IPath location = ref.getPath();
|
IContainer container = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(reference.getPath());
|
||||||
IContainer[] containers = ref.getCModel().getWorkspace().getRoot().findContainersForLocation(location);
|
if (container != null) {
|
||||||
for (int i = 0; i < containers.length; ++i) {
|
// do not allow to navigate to workspace containers inside "Includes" node
|
||||||
if (containers[i].isAccessible()) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return reference.hasChildren();
|
||||||
}
|
}
|
||||||
return super.hasChildren(element);
|
return super.hasChildren(element);
|
||||||
}
|
}
|
||||||
|
@ -266,5 +266,5 @@ public class CViewContentProvider extends CElementContentProvider {
|
||||||
}
|
}
|
||||||
super.inputChanged(viewer, oldInput, newInput);
|
super.inputChanged(viewer, oldInput, newInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,24 +21,25 @@ import org.eclipse.jface.resource.ImageDescriptor;
|
||||||
import org.eclipse.jface.viewers.StyledString;
|
import org.eclipse.jface.viewers.StyledString;
|
||||||
import org.eclipse.swt.graphics.Image;
|
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.ICProject;
|
||||||
import org.eclipse.cdt.core.model.IIncludeReference;
|
import org.eclipse.cdt.core.model.IIncludeReference;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
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.CDTSharedImages;
|
||||||
import org.eclipse.cdt.ui.CElementImageDescriptor;
|
import org.eclipse.cdt.ui.CElementImageDescriptor;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.corext.util.Strings;
|
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.AppearanceAwareLabelProvider;
|
||||||
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
|
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CViewLabelProvider
|
* CViewLabelProvider
|
||||||
*/
|
*/
|
||||||
public class CViewLabelProvider extends AppearanceAwareLabelProvider {
|
public class CViewLabelProvider extends AppearanceAwareLabelProvider {
|
||||||
|
|
||||||
public CViewLabelProvider(long textFlags, int imageFlags) {
|
public CViewLabelProvider(long textFlags, int imageFlags) {
|
||||||
super(textFlags, imageFlags);
|
super(textFlags, imageFlags);
|
||||||
}
|
}
|
||||||
|
@ -92,14 +93,14 @@ public class CViewLabelProvider extends AppearanceAwareLabelProvider {
|
||||||
p = p.removeFirstSegments(parentLocation.segmentCount());
|
p = p.removeFirstSegments(parentLocation.segmentCount());
|
||||||
}
|
}
|
||||||
return decorateText(p.toString(), element);
|
return decorateText(p.toString(), element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.getText(element);
|
return super.getText(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StyledString getStyledText(Object element) {
|
public StyledString getStyledText(Object element) {
|
||||||
return Strings.markLTR(new StyledString(getText(element)));
|
return Strings.markLTR(new StyledString(getText(element)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -107,20 +108,28 @@ public class CViewLabelProvider extends AppearanceAwareLabelProvider {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Image getImage(Object element) {
|
public Image getImage(Object element) {
|
||||||
|
String imageKey = null;
|
||||||
if (element instanceof IncludeReferenceProxy) {
|
if (element instanceof IncludeReferenceProxy) {
|
||||||
IIncludeReference reference = ((IncludeReferenceProxy)element).getReference();
|
IIncludeReference reference = ((IncludeReferenceProxy)element).getReference();
|
||||||
IPath path = reference.getPath();
|
IContainer container = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(reference.getPath());
|
||||||
IContainer container = reference.getCModel().getWorkspace().getRoot().getContainerForLocation(path);
|
if (container != null) {
|
||||||
if (container != null && container.isAccessible()) {
|
ICProject cproject = reference.getCProject();
|
||||||
ImageDescriptor desc = CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_OBJS_INCLUDES_FOLDER_WORKSPACE);
|
IProject project = (cproject != null) ? cproject.getProject() : null;
|
||||||
desc = new CElementImageDescriptor(desc, 0, CElementImageProvider.SMALL_SIZE);
|
boolean isProjectRelative = container.getProject().equals(project);
|
||||||
return CUIPlugin.getImageDescriptorRegistry().get(desc);
|
imageKey = LanguageSettingsImages.getImageKey(ICSettingEntry.INCLUDE_PATH, ICSettingEntry.VALUE_WORKSPACE_PATH, isProjectRelative);
|
||||||
|
} else {
|
||||||
|
imageKey = CDTSharedImages.IMG_OBJS_INCLUDES_FOLDER;
|
||||||
}
|
}
|
||||||
} else if (element instanceof IIncludeReference) {
|
} 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);
|
desc = new CElementImageDescriptor(desc, 0, CElementImageProvider.SMALL_SIZE);
|
||||||
return CUIPlugin.getImageDescriptorRegistry().get(desc);
|
return CUIPlugin.getImageDescriptorRegistry().get(desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.getImage(element);
|
return super.getImage(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class LanguageSettingsImages {
|
||||||
/**
|
/**
|
||||||
* @return the base key for the image.
|
* @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;
|
String imageKey = null;
|
||||||
|
|
||||||
boolean isWorkspacePath = (flag & ICSettingEntry.VALUE_WORKSPACE_PATH) != 0;
|
boolean isWorkspacePath = (flag & ICSettingEntry.VALUE_WORKSPACE_PATH) != 0;
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue