mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 14:15:23 +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
|
||||
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
|
||||
|
||||
|
|
|
@ -4043,6 +4043,7 @@
|
|||
label="%indexedFilesDecorator.label"
|
||||
lightweight="true"
|
||||
state="false">
|
||||
<description>%indexedFilesDecorator.description</description>
|
||||
<enablement>
|
||||
<or>
|
||||
<objectClass name="org.eclipse.cdt.core.model.ITranslationUnit"/>
|
||||
|
@ -4050,6 +4051,34 @@
|
|||
</or>
|
||||
</enablement>
|
||||
</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>
|
||||
|
||||
<!-- Hyperlinking support -->
|
||||
|
@ -4247,16 +4276,6 @@
|
|||
</complexArray>
|
||||
</processType>
|
||||
</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
|
||||
point="org.eclipse.ui.commands">
|
||||
<command
|
||||
|
|
|
@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.ui.cview;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
|
@ -44,7 +45,7 @@ public class CViewContentProvider extends CElementContentProvider {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public CViewContentProvider(TreeViewer viewer, IWorkbenchPartSite site) {
|
||||
super();
|
||||
|
@ -84,7 +85,7 @@ public class CViewContentProvider extends CElementContentProvider {
|
|||
objs = fManager.getChildren(element);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (objs == null) {
|
||||
objs = super.getChildren(element);
|
||||
}
|
||||
|
@ -125,14 +126,14 @@ public class CViewContentProvider extends CElementContentProvider {
|
|||
}
|
||||
return ref.getChildren();
|
||||
}
|
||||
|
||||
|
||||
private Object[] getProjectChildren(ICProject cproject) throws CModelException {
|
||||
Object[] extras = null;
|
||||
IArchiveContainer archive = cproject.getArchiveContainer();
|
||||
IArchiveContainer archive = cproject.getArchiveContainer();
|
||||
if (getArchives(archive).length > 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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