mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-08 16:55:38 +02:00
bug 339015: Preference "Show source roots at the top of project" should also apply for Make Target View
This commit is contained in:
parent
9002e4e9c1
commit
2242cfd362
9 changed files with 353 additions and 44 deletions
|
@ -12,6 +12,7 @@
|
|||
package org.eclipse.cdt.make.internal.ui.dnd;
|
||||
|
||||
import org.eclipse.cdt.make.core.IMakeTarget;
|
||||
import org.eclipse.cdt.make.ui.TargetSourceContainer;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.jface.util.TransferDropTargetListener;
|
||||
import org.eclipse.swt.dnd.DND;
|
||||
|
@ -257,6 +258,9 @@ public abstract class AbstractContainerAreaDropAdapter implements TransferDropTa
|
|||
return ((IMakeTarget) dropTarget).getContainer();
|
||||
} else if (dropTarget instanceof IContainer) {
|
||||
return (IContainer) dropTarget;
|
||||
} else if (dropTarget instanceof TargetSourceContainer) {
|
||||
IContainer dropContainer = ((TargetSourceContainer) dropTarget).getContainer();
|
||||
return dropContainer;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -7,19 +7,33 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* Andrew Gvozdev - some improvements such as adding source folders bug 339015
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.make.ui;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICDescriptionDelta;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingObject;
|
||||
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
|
||||
import org.eclipse.cdt.make.core.IMakeTarget;
|
||||
import org.eclipse.cdt.make.core.IMakeTargetListener;
|
||||
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
||||
import org.eclipse.cdt.make.core.MakeTargetEvent;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IResourceChangeEvent;
|
||||
import org.eclipse.core.resources.IResourceChangeListener;
|
||||
|
@ -27,7 +41,6 @@ import org.eclipse.core.resources.IResourceDelta;
|
|||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.jface.viewers.AbstractTreeViewer;
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
import org.eclipse.jface.viewers.StructuredViewer;
|
||||
|
@ -36,63 +49,132 @@ import org.eclipse.swt.widgets.Control;
|
|||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
/**
|
||||
* Content provider for Make Targets view and for Make Targets dialog from
|
||||
* "Make Targets"->"Build..." in project context menu.
|
||||
*
|
||||
* @noextend This class is not intended to be subclassed by clients.
|
||||
* @noinstantiate This class is not intended to be instantiated by clients.
|
||||
*/
|
||||
public class MakeContentProvider implements ITreeContentProvider, IMakeTargetListener, IResourceChangeListener {
|
||||
public class MakeContentProvider implements ITreeContentProvider, IMakeTargetListener, IResourceChangeListener, ICProjectDescriptionListener {
|
||||
/** presentation of the content, i.e. for MakeView tree of for BuildTargetDialog table */
|
||||
protected boolean bFlatten;
|
||||
|
||||
protected StructuredViewer viewer;
|
||||
|
||||
/**
|
||||
* Constructor for MakeContentProvider
|
||||
* Default constructor.
|
||||
*/
|
||||
public MakeContentProvider() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param flat - {@code true} for "flat" representation for a table
|
||||
* or {@code false} to represent as a tree.
|
||||
*/
|
||||
public MakeContentProvider(boolean flat) {
|
||||
bFlatten = flat;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
|
||||
*/
|
||||
public Object[] getChildren(Object obj) {
|
||||
if (obj instanceof IWorkspaceRoot) {
|
||||
try {
|
||||
return MakeCorePlugin.getDefault().getTargetManager().getTargetBuilderProjects();
|
||||
} catch (CoreException e) {
|
||||
// ignore
|
||||
MakeCorePlugin.log(e);
|
||||
}
|
||||
} else if (obj instanceof IContainer) {
|
||||
ArrayList<IAdaptable> children = new ArrayList<IAdaptable>();
|
||||
try {
|
||||
IResource[] resource = ((IContainer)obj).members();
|
||||
for (int i = 0; i < resource.length; i++) {
|
||||
if (resource[i] instanceof IContainer) {
|
||||
children.add(resource[i]);
|
||||
IContainer container = (IContainer)obj;
|
||||
ArrayList<Object> children = new ArrayList<Object>();
|
||||
|
||||
boolean isAddingSourceRoots = !bFlatten && (container instanceof IProject) && CCorePlugin.showSourceRootsAtTopOfProject();
|
||||
|
||||
// add source roots if necessary
|
||||
if (isAddingSourceRoots) {
|
||||
IProject project = (IProject) container;
|
||||
ICSourceEntry[] srcEntries = getSourceEntries(project);
|
||||
for (ICSourceEntry srcEntry : srcEntries) {
|
||||
if (!srcEntry.getFullPath().equals(project.getFullPath())) {
|
||||
children.add(new TargetSourceContainer(srcEntry));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add regular folders
|
||||
try {
|
||||
IResource[] resources = container.members();
|
||||
for (IResource rc : resources) {
|
||||
if (rc instanceof IContainer) {
|
||||
if (!(isAddingSourceRoots && isSourceEntry(rc))) {
|
||||
children.add(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
children.addAll(Arrays.asList(MakeCorePlugin.getDefault().getTargetManager().getTargets((IContainer)obj)));
|
||||
} catch (CoreException e) {
|
||||
// ignore
|
||||
MakeCorePlugin.log(e);
|
||||
}
|
||||
|
||||
// finally add targets
|
||||
try {
|
||||
IMakeTarget[] targets = MakeCorePlugin.getDefault().getTargetManager().getTargets(container);
|
||||
children.addAll(Arrays.asList(targets));
|
||||
} catch (CoreException e) {
|
||||
MakeCorePlugin.log(e);
|
||||
}
|
||||
return children.toArray();
|
||||
|
||||
} else if (obj instanceof TargetSourceContainer) {
|
||||
ArrayList<Object> children = new ArrayList<Object>();
|
||||
try {
|
||||
IContainer container = ((TargetSourceContainer) obj).getContainer();
|
||||
IResource[] resources = container.members();
|
||||
for (IResource rc : resources) {
|
||||
if (rc instanceof IContainer) {
|
||||
children.add(rc);
|
||||
}
|
||||
}
|
||||
children.addAll(Arrays.asList(MakeCorePlugin.getDefault().getTargetManager().getTargets(container)));
|
||||
} catch (CoreException e) {
|
||||
MakeCorePlugin.log(e);
|
||||
}
|
||||
return children.toArray();
|
||||
}
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
|
||||
*/
|
||||
public Object getParent(Object obj) {
|
||||
if (obj instanceof IMakeTarget) {
|
||||
// this is ambiguous as make target can sit in 2 places, in its container
|
||||
// or source folder represented by TargetSourceContainer
|
||||
return ((IMakeTarget)obj).getContainer();
|
||||
} else if (obj instanceof IContainer) {
|
||||
return ((IContainer)obj).getParent();
|
||||
} else if (obj instanceof TargetSourceContainer) {
|
||||
IContainer container = ((TargetSourceContainer)obj).getContainer();
|
||||
// TargetSourceContainer sits at project root
|
||||
return container.getProject();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
|
||||
*/
|
||||
public boolean hasChildren(Object obj) {
|
||||
return getChildren(obj).length > 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
|
||||
*/
|
||||
public Object[] getElements(Object obj) {
|
||||
if (bFlatten) {
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
|
@ -106,12 +188,18 @@ public class MakeContentProvider implements ITreeContentProvider, IMakeTargetLis
|
|||
return getChildren(obj);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
if (viewer != null) {
|
||||
MakeCorePlugin.getDefault().getTargetManager().removeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
if (this.viewer == null) {
|
||||
MakeCorePlugin.getDefault().getTargetManager().addListener(this);
|
||||
|
@ -123,22 +211,32 @@ public class MakeContentProvider implements ITreeContentProvider, IMakeTargetLis
|
|||
oldWorkspace = (IWorkspace) oldInput;
|
||||
} else if (oldInput instanceof IContainer) {
|
||||
oldWorkspace = ((IContainer) oldInput).getWorkspace();
|
||||
} else if (oldInput instanceof TargetSourceContainer) {
|
||||
oldWorkspace = ((TargetSourceContainer) oldInput).getContainer().getWorkspace();
|
||||
}
|
||||
if (newInput instanceof IWorkspace) {
|
||||
newWorkspace = (IWorkspace) newInput;
|
||||
} else if (newInput instanceof IContainer) {
|
||||
newWorkspace = ((IContainer) newInput).getWorkspace();
|
||||
} else if (newInput instanceof TargetSourceContainer) {
|
||||
newWorkspace = ((TargetSourceContainer) newInput).getContainer().getWorkspace();
|
||||
}
|
||||
if (oldWorkspace != newWorkspace) {
|
||||
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
|
||||
if (oldWorkspace != null) {
|
||||
oldWorkspace.removeResourceChangeListener(this);
|
||||
mngr.removeCProjectDescriptionListener(this);
|
||||
}
|
||||
if (newWorkspace != null) {
|
||||
newWorkspace.addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
|
||||
mngr.addCProjectDescriptionListener(this, CProjectDescriptionEvent.APPLIED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.make.core.IMakeTargetListener#targetChanged(org.eclipse.cdt.make.core.MakeTargetEvent)
|
||||
*/
|
||||
public void targetChanged(final MakeTargetEvent event) {
|
||||
final Control ctrl = viewer.getControl();
|
||||
if (ctrl != null && !ctrl.isDisposed()) {
|
||||
|
@ -166,14 +264,21 @@ public class MakeContentProvider implements ITreeContentProvider, IMakeTargetLis
|
|||
} else {
|
||||
//We can't just call refresh on the container target that
|
||||
//has been created since it may be that the container has
|
||||
//been filtered out and the fiters in the viewer don't know
|
||||
//been filtered out and the filters in the viewer don't know
|
||||
//any better how to call out to the filter selection again.
|
||||
//Instead we walk to the root container and refresh it.
|
||||
IContainer container = event.getTarget().getContainer();
|
||||
while(container.getParent() != null) {
|
||||
container = container.getParent();
|
||||
//Instead we walk to the root project container and refresh it.
|
||||
Set<IContainer> containers = new HashSet<IContainer>();
|
||||
IMakeTarget[] targets = event.getTargets();
|
||||
for (IMakeTarget target : targets) {
|
||||
IContainer container = target.getContainer();
|
||||
while(!(container instanceof IProject) && container.getParent()!=null) {
|
||||
container = container.getParent();
|
||||
}
|
||||
containers.add(container);
|
||||
}
|
||||
for (IContainer container : containers) {
|
||||
viewer.refresh(container);
|
||||
}
|
||||
viewer.refresh(container);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -183,7 +288,7 @@ public class MakeContentProvider implements ITreeContentProvider, IMakeTargetLis
|
|||
}
|
||||
}
|
||||
|
||||
void processDelta(IResourceDelta delta) {
|
||||
private void processDelta(IResourceDelta delta) {
|
||||
// Bail out if the widget was disposed.
|
||||
Control ctrl = viewer.getControl();
|
||||
if (ctrl == null || ctrl.isDisposed() || delta == null) {
|
||||
|
@ -256,10 +361,83 @@ public class MakeContentProvider implements ITreeContentProvider, IMakeTargetLis
|
|||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
|
||||
*/
|
||||
public void resourceChanged(IResourceChangeEvent event) {
|
||||
final IResourceDelta delta = event.getDelta();
|
||||
Control ctrl = viewer.getControl();
|
||||
if (ctrl != null && !ctrl.isDisposed())
|
||||
processDelta(delta);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @since 7.1
|
||||
*/
|
||||
public void handleEvent(final CProjectDescriptionEvent event) {
|
||||
Display display = Display.getDefault();
|
||||
display.asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
ICDescriptionDelta delta = event.getDefaultSettingCfgDelta();
|
||||
if (delta==null)
|
||||
return;
|
||||
|
||||
int flags = delta.getChangeFlags();
|
||||
if ( ((flags & ICDescriptionDelta.SOURCE_ADDED) != 0) ||
|
||||
((flags & ICDescriptionDelta.SOURCE_REMOVED) != 0) ) {
|
||||
|
||||
IProject project = null;
|
||||
ICSettingObject setting = delta.getOldSetting();
|
||||
if (setting==null)
|
||||
setting = delta.getNewSetting();
|
||||
|
||||
if (setting instanceof ICConfigurationDescription)
|
||||
project = ((ICConfigurationDescription) setting).getProjectDescription().getProject();
|
||||
|
||||
if (project!=null)
|
||||
viewer.refresh(project);
|
||||
else
|
||||
viewer.refresh();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get source entries for default setting configuration (i.e. configuration shown in UI).
|
||||
*/
|
||||
private static ICSourceEntry[] getSourceEntries(IProject project) {
|
||||
ICProjectDescriptionManager mgr = CCorePlugin.getDefault().getProjectDescriptionManager();
|
||||
ICProjectDescription prjDescription = mgr.getProjectDescription(project, false);
|
||||
if (prjDescription!=null) {
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
if (cfgDescription!=null) {
|
||||
ICSourceEntry[] srcEntries = cfgDescription.getResolvedSourceEntries();
|
||||
return srcEntries;
|
||||
}
|
||||
}
|
||||
|
||||
return new ICSourceEntry[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the resource is in the list of source entries.
|
||||
|
||||
* @param rc - resource to check.
|
||||
* @return {@code true} if the resource is a source folder, {@code false} otherwise.
|
||||
*
|
||||
* @since 7.1
|
||||
*/
|
||||
public static boolean isSourceEntry(IResource rc) {
|
||||
IProject project = rc.getProject();
|
||||
ICSourceEntry[] srcEntries = getSourceEntries(project);
|
||||
for (ICSourceEntry srcEntry : srcEntries) {
|
||||
if (srcEntry.getFullPath().equals(rc.getFullPath()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,13 +7,16 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* Andrew Gvozdev - some improvements such as adding source folders bug 339015
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.make.ui;
|
||||
|
||||
|
||||
import org.eclipse.cdt.make.core.IMakeTarget;
|
||||
import org.eclipse.cdt.make.internal.ui.MakeUIImages;
|
||||
import org.eclipse.cdt.ui.CDTSharedImages;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.jface.viewers.ILabelProvider;
|
||||
import org.eclipse.jface.viewers.ITableLabelProvider;
|
||||
|
@ -22,13 +25,15 @@ import org.eclipse.swt.graphics.Image;
|
|||
import org.eclipse.ui.model.WorkbenchLabelProvider;
|
||||
|
||||
/**
|
||||
* Label provider for Make Targets view and for Make Targets dialog from
|
||||
* "Make Targets"->"Build..." in project context menu.
|
||||
*
|
||||
* @noextend This class is not intended to be subclassed by clients.
|
||||
* @noinstantiate This class is not intended to be instantiated by clients.
|
||||
*/
|
||||
public class MakeLabelProvider extends LabelProvider implements ITableLabelProvider {
|
||||
private IPath pathPrefix;
|
||||
|
||||
WorkbenchLabelProvider fLableProvider = new WorkbenchLabelProvider();
|
||||
private WorkbenchLabelProvider fLableProvider = new WorkbenchLabelProvider();
|
||||
|
||||
public MakeLabelProvider() {
|
||||
this(null);
|
||||
|
@ -43,10 +48,14 @@ public class MakeLabelProvider extends LabelProvider implements ITableLabelProvi
|
|||
@Override
|
||||
public Image getImage(Object obj) {
|
||||
Image image = null;
|
||||
if (obj instanceof IMakeTarget) {
|
||||
return MakeUIImages.getImage(MakeUIImages.IMG_OBJS_BUILD_TARGET);
|
||||
if (obj instanceof TargetSourceContainer) {
|
||||
return CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_SOURCE_ROOT);
|
||||
} else if (obj instanceof IContainer) {
|
||||
if (!(obj instanceof IProject) && MakeContentProvider.isSourceEntry((IContainer) obj))
|
||||
return CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_SOURCE_ROOT);
|
||||
return fLableProvider.getImage(obj);
|
||||
} else if (obj instanceof IMakeTarget) {
|
||||
return MakeUIImages.getImage(MakeUIImages.IMG_OBJS_BUILD_TARGET);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
@ -56,10 +65,16 @@ public class MakeLabelProvider extends LabelProvider implements ITableLabelProvi
|
|||
*/
|
||||
@Override
|
||||
public String getText(Object obj) {
|
||||
if (obj instanceof IMakeTarget) {
|
||||
return ((IMakeTarget) obj).getName();
|
||||
if (obj instanceof TargetSourceContainer) {
|
||||
IContainer container = ((TargetSourceContainer) obj).getContainer();
|
||||
IPath path = container.getFullPath();
|
||||
// remove leading project name
|
||||
path = path.removeFirstSegments(1);
|
||||
return path.toString();
|
||||
} else if (obj instanceof IContainer) {
|
||||
return fLableProvider.getText(obj);
|
||||
} else if (obj instanceof IMakeTarget) {
|
||||
return ((IMakeTarget) obj).getName();
|
||||
}
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2011, 2011 Andrew Gvozdev.
|
||||
* 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 implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.ui;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
|
||||
/**
|
||||
* A class to represent source folders added to Make Targets View on top.
|
||||
*
|
||||
* @noextend This class is not intended to be subclassed by clients.
|
||||
* @noinstantiate This class is not intended to be instantiated by clients.
|
||||
*
|
||||
* @since 7.1
|
||||
*/
|
||||
public class TargetSourceContainer {
|
||||
private IContainer container;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param srcEntry - source entry backing the container.
|
||||
*/
|
||||
public TargetSourceContainer(ICSourceEntry srcEntry) {
|
||||
IWorkspaceRoot wspRoot = ResourcesPlugin.getWorkspace().getRoot();
|
||||
container = wspRoot.getFolder(srcEntry.getFullPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns resource container associated with the source entry.
|
||||
*
|
||||
* @return resource container.
|
||||
*/
|
||||
public IContainer getContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return container.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof TargetSourceContainer)
|
||||
return container.equals(((TargetSourceContainer) obj).container);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -17,6 +17,7 @@ import org.eclipse.cdt.core.model.ICProject;
|
|||
import org.eclipse.cdt.make.core.IMakeTarget;
|
||||
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
||||
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||
import org.eclipse.cdt.make.ui.TargetSourceContainer;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
@ -84,6 +85,8 @@ public abstract class AbstractTargetAction
|
|||
} else {
|
||||
fContainer = ((IResource)obj).getParent();
|
||||
}
|
||||
} else if (obj instanceof TargetSourceContainer) {
|
||||
fContainer = ((TargetSourceContainer)obj).getContainer();
|
||||
} else if (obj instanceof IMakeTarget) {
|
||||
fContainer = ((IMakeTarget)obj).getContainer();
|
||||
} else {
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.eclipse.cdt.make.core.IMakeTarget;
|
|||
import org.eclipse.cdt.make.internal.ui.MakeUIImages;
|
||||
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||
import org.eclipse.cdt.make.internal.ui.dnd.MakeTargetDndUtil;
|
||||
import org.eclipse.cdt.make.ui.TargetSourceContainer;
|
||||
import org.eclipse.cdt.make.ui.dialogs.MakeTargetDialog;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -43,12 +44,20 @@ public class AddTargetAction extends SelectionListenerAction {
|
|||
public void run() {
|
||||
Object selection = getSelectedElement();
|
||||
try {
|
||||
if (selection instanceof IContainer) {
|
||||
MakeTargetDialog dialog = new MakeTargetDialog(shell, (IContainer) selection);
|
||||
dialog.open();
|
||||
} else if (selection instanceof IMakeTarget) {
|
||||
if (selection instanceof IMakeTarget) {
|
||||
IMakeTarget makeTarget = (IMakeTarget)selection;
|
||||
MakeTargetDndUtil.copyOneTarget(makeTarget, makeTarget.getContainer(), DND.DROP_COPY, shell, false);
|
||||
} else {
|
||||
IContainer container = null;
|
||||
if (selection instanceof TargetSourceContainer) {
|
||||
container = ((TargetSourceContainer) selection).getContainer();
|
||||
} else if (selection instanceof IContainer) {
|
||||
container = (IContainer) selection;
|
||||
}
|
||||
if (container!=null) {
|
||||
MakeTargetDialog dialog = new MakeTargetDialog(shell, container);
|
||||
dialog.open();
|
||||
}
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
MakeUIPlugin.errorDialog(shell, MakeUIPlugin.getResourceString("AddTargetAction.exception.title"), //$NON-NLS-1$
|
||||
|
@ -65,7 +74,7 @@ public class AddTargetAction extends SelectionListenerAction {
|
|||
private Object getSelectedElement() {
|
||||
if (getStructuredSelection().size()==1) {
|
||||
Object element = getStructuredSelection().getFirstElement();
|
||||
if (element instanceof IContainer || element instanceof IMakeTarget) {
|
||||
if (element instanceof IContainer || element instanceof TargetSourceContainer || element instanceof IMakeTarget) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,11 +11,15 @@
|
|||
|
||||
package org.eclipse.cdt.make.ui.views;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.make.core.IMakeTarget;
|
||||
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
||||
import org.eclipse.cdt.make.internal.ui.MakeUIImages;
|
||||
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.cdt.make.ui.MakeContentProvider;
|
||||
import org.eclipse.cdt.make.ui.TargetSourceContainer;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IResourceProxy;
|
||||
import org.eclipse.core.resources.IResourceProxyVisitor;
|
||||
|
@ -57,7 +61,7 @@ public class FilterEmtpyFoldersAction extends Action {
|
|||
//Check the make targets of the specified container, and if they don't exist, run
|
||||
//through the children looking for the first match that we can find that contains
|
||||
//a make target.
|
||||
private boolean hasMakeTargets(IFolder container) throws CoreException {
|
||||
private boolean hasMakeTargets(IContainer container) throws CoreException {
|
||||
IMakeTarget [] targets = MakeCorePlugin.getDefault().getTargetManager().getTargets(container);
|
||||
if(targets != null && targets.length > 0) {
|
||||
return true;
|
||||
|
@ -65,7 +69,7 @@ public class FilterEmtpyFoldersAction extends Action {
|
|||
|
||||
final boolean [] haveTargets = new boolean[1];
|
||||
haveTargets[0] = false;
|
||||
|
||||
|
||||
IResourceProxyVisitor visitor = new IResourceProxyVisitor() {
|
||||
public boolean visit(IResourceProxy proxy) throws CoreException {
|
||||
if(haveTargets[0]) {
|
||||
|
@ -74,7 +78,14 @@ public class FilterEmtpyFoldersAction extends Action {
|
|||
if(proxy.getType() != IResource.FOLDER) {
|
||||
return true; //We only look at folders for content
|
||||
}
|
||||
IFolder folder = (IFolder) proxy.requestResource();
|
||||
IContainer folder = (IContainer) proxy.requestResource();
|
||||
if (CCorePlugin.showSourceRootsAtTopOfProject() && !(folder instanceof IProject)) {
|
||||
boolean isSourceEntry = MakeContentProvider.isSourceEntry(folder);
|
||||
if (isSourceEntry)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
IMakeTarget [] targets = MakeCorePlugin.getDefault().getTargetManager().getTargets(folder);
|
||||
if(targets != null && targets.length > 0) {
|
||||
haveTargets[0] = true;
|
||||
|
@ -88,13 +99,30 @@ public class FilterEmtpyFoldersAction extends Action {
|
|||
return haveTargets[0];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean select(Viewer viewer, Object parentElement, Object element) {
|
||||
if (isChecked() && element instanceof IFolder) {
|
||||
try {
|
||||
return hasMakeTargets((IFolder)element);
|
||||
} catch(Exception ex) {
|
||||
return false;
|
||||
if (isChecked()) {
|
||||
IContainer container = null;
|
||||
if (element instanceof IContainer) {
|
||||
container = (IContainer)element;
|
||||
if (!(container instanceof IProject)) {
|
||||
// under subfolders do not show source roots second time (when filtered)
|
||||
if (CCorePlugin.showSourceRootsAtTopOfProject() && MakeContentProvider.isSourceEntry(container))
|
||||
return false;
|
||||
}
|
||||
} else if (element instanceof TargetSourceContainer) {
|
||||
container = ((TargetSourceContainer) element).getContainer();
|
||||
}
|
||||
|
||||
if (container!=null) {
|
||||
try {
|
||||
return hasMakeTargets(container);
|
||||
} catch(Exception ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -102,6 +130,9 @@ public class FilterEmtpyFoldersAction extends Action {
|
|||
});
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.action.Action#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
fViewer.refresh();
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.eclipse.cdt.make.internal.ui.dnd.TextTransferDropTargetListener;
|
|||
import org.eclipse.cdt.make.ui.IMakeHelpContextIds;
|
||||
import org.eclipse.cdt.make.ui.MakeContentProvider;
|
||||
import org.eclipse.cdt.make.ui.MakeLabelProvider;
|
||||
import org.eclipse.cdt.make.ui.TargetSourceContainer;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.jface.action.IMenuListener;
|
||||
|
@ -64,11 +65,12 @@ import org.eclipse.ui.part.DrillDownAdapter;
|
|||
import org.eclipse.ui.part.ViewPart;
|
||||
|
||||
/**
|
||||
* Implementation of Make Target View.
|
||||
*
|
||||
* @noextend This class is not intended to be subclassed by clients.
|
||||
* @noinstantiate This class is not intended to be instantiated by clients.
|
||||
*/
|
||||
public class MakeView extends ViewPart {
|
||||
|
||||
private static final String TARGET_BUILD_LAST_COMMAND = "org.eclipse.cdt.make.ui.targetBuildLastCommand"; //$NON-NLS-1$
|
||||
|
||||
private Clipboard clipboard;
|
||||
|
@ -129,13 +131,14 @@ public class MakeView extends ViewPart {
|
|||
});
|
||||
|
||||
fViewer.setSorter(new ViewerSorter() {
|
||||
|
||||
@Override
|
||||
public int category(Object element) {
|
||||
if (element instanceof IResource) {
|
||||
return 0;
|
||||
if (element instanceof TargetSourceContainer) {
|
||||
return 1;
|
||||
} else if (element instanceof IResource) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
return 3;
|
||||
}
|
||||
});
|
||||
fViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.eclipse.cdt.make.internal.ui.dnd.MakeTargetTransfer;
|
|||
import org.eclipse.cdt.make.internal.ui.dnd.MakeTargetTransferData;
|
||||
import org.eclipse.cdt.make.internal.ui.dnd.MakeTargetTransferDropTargetListener;
|
||||
import org.eclipse.cdt.make.internal.ui.dnd.TextTransferDropTargetListener;
|
||||
import org.eclipse.cdt.make.ui.TargetSourceContainer;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.swt.dnd.Clipboard;
|
||||
|
@ -146,6 +147,10 @@ public class PasteTargetAction extends SelectionListenerAction {
|
|||
return dropContainer;
|
||||
}
|
||||
|
||||
if (first instanceof TargetSourceContainer) {
|
||||
return ((TargetSourceContainer) first).getContainer();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue