From 88528b8277060e27383c9e66fbc395ee4878bf4c Mon Sep 17 00:00:00 2001 From: David Inglis Date: Tue, 13 Apr 2004 20:41:46 +0000 Subject: [PATCH] update - work in progress --- .../cpaths/AbstractPathOptionBlock.java | 2 - .../cpaths/CPathEntryMessages.properties | 2 +- .../dialogs/cpaths/CPathIncludeEntryPage.java | 15 +- .../dialogs/cpaths/CPathSymbolEntryPage.java | 17 ++- .../dialogs/cpaths/ExtendedCPathBasePage.java | 132 ++++++++++-------- .../cpaths/IncludesSymbolsTabBlock.java | 14 +- 6 files changed, 114 insertions(+), 68 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/AbstractPathOptionBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/AbstractPathOptionBlock.java index 0720998e200..fdb8654f042 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/AbstractPathOptionBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/AbstractPathOptionBlock.java @@ -103,10 +103,8 @@ abstract public class AbstractPathOptionBlock extends TabFolderOptionBlock imple */ public void init(ICElement element, IPathEntry[] cpathEntries) { setCProject(element.getCProject()); - boolean projectExists = false; List newCPath = null; - IProject project = getProject(); if (cpathEntries == null) { try { cpathEntries = getCProject().getRawPathEntries(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.properties index 2f2d8c18f44..06bc53ba94c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.properties @@ -28,7 +28,7 @@ SymbolEntryPage.addContributed=Add contributed... SymbolEntryPage.remove=Remove SymbolEntryPage.listName=Defines: SymbolEntryPage.editSourcePaths=Edit source paths... -SymbolEntryPage.sourcePath=Source Paths: +SymbolEntryPage.sourcePaths=Source Paths: # ------- IncludeEntryPage ---------- IncludeEntryPage.title=Include Paths diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java index 41ab47b5f7b..10419c2ee79 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java @@ -14,7 +14,6 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter; public class CPathIncludeEntryPage extends ExtendedCPathBasePage { - public CPathIncludeEntryPage(ITreeListAdapter adapter) { super(adapter, "IncludeEntryPage"); //$NON-NLS-1$ } @@ -22,4 +21,18 @@ public class CPathIncludeEntryPage extends ExtendedCPathBasePage { public boolean isEntryKind(int kind) { return kind == IPathEntry.CDT_INCLUDE; } + + protected void addContributed() { + // dinglis-TODO Auto-generated method stub + } + + protected void addFromWorkspace() { + // dinglis-TODO Auto-generated method stub + + } + + protected void addPath() { + // dinglis-TODO Auto-generated method stub + + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSymbolEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSymbolEntryPage.java index 7f2920284f6..23539115da1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSymbolEntryPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSymbolEntryPage.java @@ -21,4 +21,19 @@ public class CPathSymbolEntryPage extends ExtendedCPathBasePage { public boolean isEntryKind(int kind) { return kind == IPathEntry.CDT_MACRO; } -} + + protected void addContributed() { + // dinglis-TODO Auto-generated method stub + + } + + protected void addFromWorkspace() { + // dinglis-TODO Auto-generated method stub + + } + + protected void addPath() { + // dinglis-TODO Auto-generated method stub + + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java index 32ccb808cfb..7335cfd8738 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java @@ -13,10 +13,10 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModelUtil; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.ISourceRoot; import org.eclipse.cdt.internal.ui.util.PixelConverter; import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; @@ -26,13 +26,9 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil; import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField; import org.eclipse.cdt.internal.ui.wizards.dialogfields.TreeListDialogField; import org.eclipse.cdt.ui.CElementLabelProvider; -import org.eclipse.cdt.ui.CUIPlugin; -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.IProgressMonitor; -import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.IColorProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; @@ -41,14 +37,17 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.model.IWorkbenchAdapter; public abstract class ExtendedCPathBasePage extends CPathBasePage { - private ListDialogField fPathList; - private TreeListDialogField fSrcList; - private List fCPathList; + ListDialogField fPathList; + TreeListDialogField fSrcList; + List fCPathList; + + private static final int IDX_ADD = 0; + private static final int IDX_ADD_WORKSPACE = 1; + private static final int IDX_ADD_CONTRIBUTED = 2; + private static final int IDX_REMOVE = 4; private class IncludeListAdapter implements IListAdapter, IDialogFieldListener { @@ -56,51 +55,33 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage { } public void customButtonPressed(ListDialogField field, int index) { + switch (index) { + case IDX_ADD : + addPath(); + break; + case IDX_ADD_WORKSPACE : + addFromWorkspace(); + break; + case IDX_ADD_CONTRIBUTED : + addContributed(); + break; + case IDX_REMOVE : + if (canRemove(field.getSelectedElements())) { + removePath((CPListElement) field.getSelectedElements().get(0)); + } + break; + } } public void selectionChanged(ListDialogField field) { + List selected = fPathList.getSelectedElements(); + fPathList.enableButton(IDX_REMOVE, canRemove(selected)); } public void doubleClicked(ListDialogField field) { } } - private class GlobalElement implements IAdaptable, IWorkbenchAdapter { - - private final IProject fProject; - - public GlobalElement(IProject project) { - fProject = project; - } - - public IPath getPath() { - return fProject.getFullPath(); - } - - public Object getAdapter(Class adapter) { - if (adapter.equals(IWorkbenchAdapter.class)) { - return this; - } - return null; - } - - public Object[] getChildren(Object o) { - return new Object[0]; - } - - public ImageDescriptor getImageDescriptor(Object object) { - return CUIPlugin.getDefault().getWorkbench().getSharedImages().getImageDescriptor(IDE.SharedImages.IMG_OBJ_PROJECT); - } - - public String getLabel(Object o) { - return "Global Entries"; //$NON-NLS-1$ - } - - public Object getParent(Object o) { - return null; - } - } - private class ModifiedCPListLabelProvider extends CPListLabelProvider implements IColorProvider { private final Color inDirect = new Color(Display.getDefault(), new RGB(170, 170, 170)); @@ -128,10 +109,10 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage { super(CPathEntryMessages.getString(prefix + ".title")); //$NON-NLS-1$ IncludeListAdapter includeListAdaper = new IncludeListAdapter(); - String[] buttonLabel = new String[] { CPathEntryMessages.getString(prefix + ".add"), //$NON-NLS-1$ - CPathEntryMessages.getString(prefix + ".addFromWorkspace"), //$NON-NLS-1$ - CPathEntryMessages.getString(prefix + ".addContributed"), null, //$NON-NLS-1$ - CPathEntryMessages.getString(prefix + ".remove")}; //$NON-NLS-1$ + String[] buttonLabel = new String[]{ /* 0 */CPathEntryMessages.getString(prefix + ".add"), //$NON-NLS-1$ + /* 1 */CPathEntryMessages.getString(prefix + ".addFromWorkspace"), //$NON-NLS-1$ + /* 2 */CPathEntryMessages.getString(prefix + ".addContributed"), null, //$NON-NLS-1$ + /* 4 */CPathEntryMessages.getString(prefix + ".remove")}; //$NON-NLS-1$ fPathList = new ListDialogField(includeListAdaper, buttonLabel, new ModifiedCPListLabelProvider()) { protected int getListStyle() { @@ -140,7 +121,7 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage { }; fPathList.setDialogFieldListener(includeListAdaper); fPathList.setLabelText(CPathEntryMessages.getString(prefix + ".listName")); //$NON-NLS-1$ - fSrcList = new TreeListDialogField(adapter, new String[] { CPathEntryMessages.getString(prefix + ".editSourcePaths")}, //$NON-NLS-1$ + fSrcList = new TreeListDialogField(adapter, new String[]{CPathEntryMessages.getString(prefix + ".editSourcePaths")}, //$NON-NLS-1$ new CElementLabelProvider()) { protected int getTreeStyle() { @@ -157,19 +138,55 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage { setControl(composite); - LayoutUtil.doDefaultLayout(composite, new DialogField[] { fSrcList, fPathList}, true); + LayoutUtil.doDefaultLayout(composite, new DialogField[]{fSrcList, fPathList}, true); LayoutUtil.setHorizontalGrabbing(fPathList.getListControl(null)); int buttonBarWidth = converter.convertWidthInCharsToPixels(30); fPathList.setButtonsMinWidth(buttonBarWidth); + fPathList.enableButton(IDX_REMOVE, false); + + } + + abstract protected void addPath(); + abstract protected void addFromWorkspace(); + abstract protected void addContributed(); + + protected boolean canRemove(List selected) { + return !selected.isEmpty(); + } + + protected void removePath(CPListElement element) { + ICElement celem = (ICElement) getSelection().get(0); + if (!celem.getPath().equals(element.getPath())) { + IPath exclude = celem.getPath(); + + IPath[] exclusions = (IPath[]) element.getAttribute(CPListElement.EXCLUSION); + IPath[] newExlusions = new IPath[exclusions.length + 1]; + System.arraycopy(exclusions, 0, newExlusions, 0, exclusions.length); + newExlusions[exclusions.length] = exclude; + element.setAttribute(CPListElement.EXCLUSION, newExlusions); + selectionChanged(new StructuredSelection(getSelection())); + } else { + fCPathList.remove(element); + fPathList.removeElement(element); + } } public void init(ICProject project, List cPaths) { List list = new ArrayList(project.getChildrenOfType(ICElement.C_CCONTAINER)); - list.add(0, new GlobalElement(project.getProject())); + int i; + for (i = 0; i < list.size(); i++) { + if (((ISourceRoot) list.get(i)).getResource() == project.getProject()) { + break; + } + } + if (i == list.size()) { + list.add(0, project); + } fSrcList.setElements(list); fCPathList = filterList(cPaths); fPathList.setElements(fCPathList); + fSrcList.selectElements(new StructuredSelection(list.get(0))); } public List getCPaths() { @@ -194,16 +211,13 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage { } Object sel = selection.getFirstElement(); IPath resPath; - if (sel instanceof ICElement) { - resPath = ((ICElement) sel).getPath(); - } else { - resPath = ((GlobalElement) sel).getPath(); - } + resPath = ((ICElement) sel).getPath(); List newList = new ArrayList(list.size()); Iterator iter = list.iterator(); while (iter.hasNext()) { CPListElement element = (CPListElement) iter.next(); - if (element.getPath().isPrefixOf(resPath) && !CoreModelUtil.isExcludedPath(resPath, (IPath[]) element.getAttribute(CPListElement.EXCLUSION))) { //$NON-NLS-1$ + if (element.getPath().isPrefixOf(resPath) + && !CoreModelUtil.isExcludedPath(resPath, (IPath[]) element.getAttribute(CPListElement.EXCLUSION))) { //$NON-NLS-1$ newList.add(element); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsTabBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsTabBlock.java index 83454acec21..6cf42e3ec74 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsTabBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsTabBlock.java @@ -88,14 +88,20 @@ public class IncludesSymbolsTabBlock extends AbstractPathOptionBlock { public Control createContents(Composite parent) { Control control = super.createContents(parent); if (getCProject() != null) { - fIncludePage.init(getCProject(), getCPaths()); - fSymbolsPage.init(getCProject(), getCPaths()); + fIncludePage.init(getCProject(), fCPaths); + fSymbolsPage.init(getCProject(), fCPaths); } Dialog.applyDialogFont(control); return control; } protected List getCPaths() { + if (fIncludePage == null) { + return fCPaths; + } + fCPaths.clear(); + fCPaths.addAll(fIncludePage.getCPaths()); + fCPaths.addAll(fSymbolsPage.getCPaths()); return fCPaths; } @@ -106,8 +112,8 @@ public class IncludesSymbolsTabBlock extends AbstractPathOptionBlock { protected void initialize(ICElement element, List cPaths) { fCPaths = cPaths; if (fIncludePage != null) { - fIncludePage.init(getCProject(), getCPaths()); - fSymbolsPage.init(getCProject(), getCPaths()); + fIncludePage.init(getCProject(), fCPaths); + fSymbolsPage.init(getCProject(), fCPaths); } doStatusLineUpdate(); initializeTimeStamps();