From dd0baea2ea51c6d951c020db9c6c8f548ad2e608 Mon Sep 17 00:00:00 2001 From: David Inglis Date: Tue, 20 Apr 2004 19:31:05 +0000 Subject: [PATCH] update cpath ui --- core/org.eclipse.cdt.ui/ChangeLog | 13 +++- .../ui/dialogs/cpaths/CPListElement.java | 26 ++++++- .../ui/dialogs/cpaths/CPathBasePage.java | 2 +- .../cpaths/CPathEntryMessages.properties | 6 +- .../dialogs/cpaths/CPathIncludeEntryPage.java | 62 +++++++++++++++++ .../dialogs/cpaths/CPathSymbolEntryPage.java | 32 +++++++-- .../dialogs/cpaths/ExtendedCPathBasePage.java | 68 ++++++++++--------- 7 files changed, 168 insertions(+), 41 deletions(-) diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 24ee09a2577..bfeb2486f58 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,7 +1,18 @@ +2004-04-20 David Inglis + + Work in progress CPath UI changes + + * src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListElement.java + * src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathBasePage.java + * src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.properties + * src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathIncludeEntryPage.java + * src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSymbolEntryPage.java + * src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java + 2004-04-20 Alain Magloire Fix NPE in CDocumentProvider * src/org/eclipse/cdt/internalu/ui/editor/CDocumentProvider.java - + 2004-04-20 David Inglis More of the model throws CModeLException. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListElement.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListElement.java index af7aba845fa..9563a2b5b31 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListElement.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListElement.java @@ -35,6 +35,7 @@ public class CPListElement { public static final String MACRO_NAME = "macroname"; //$NON-NLS-1$ public static final String MACRO_VALUE = "macrovalue"; //$NON-NLS-1$ public static final String BASE_REF = "baseref"; //$NON-NLS-1$ + public static final String BASE = "base"; //$NON-NLS-1$ private ICProject fProject; @@ -77,12 +78,14 @@ public class CPListElement { createAttributeElement(EXCLUSION, new Path[0]); createAttributeElement(SYSTEM_INCLUDE, Boolean.valueOf(false)); createAttributeElement(BASE_REF, new Path("")); //$NON-NLS-1$ + createAttributeElement(BASE, new Path("")); //$NON-NLS-1$ break; case IPathEntry.CDT_MACRO: createAttributeElement(MACRO_NAME, ""); //$NON-NLS-1$ createAttributeElement(MACRO_VALUE, ""); //$NON-NLS-1$ createAttributeElement(EXCLUSION, new Path[0]); createAttributeElement(BASE_REF, new Path("")); //$NON-NLS-1$ + createAttributeElement(BASE, new Path("")); //$NON-NLS-1$ break; case IPathEntry.CDT_CONTAINER: try { @@ -131,7 +134,7 @@ public class CPListElement { ((Boolean) getAttribute(SYSTEM_INCLUDE)).booleanValue(), exclusionPattern); case IPathEntry.CDT_MACRO: exclusionPattern = (IPath[]) getAttribute(EXCLUSION); - return CoreModel.newMacroEntry(fPath, (String) getAttribute(MACRO_NAME), (String) getAttribute(MACRO_NAME)); + return CoreModel.newMacroEntry(fPath, (String) getAttribute(MACRO_NAME), (String) getAttribute(MACRO_NAME), exclusionPattern); default: return null; } @@ -261,7 +264,20 @@ public class CPListElement { public boolean equals(Object other) { if (other != null && other.getClass().equals(getClass())) { CPListElement elem = (CPListElement) other; - return elem.fEntryKind == fEntryKind && elem.fPath.equals(fPath); + if ( elem.fEntryKind != fEntryKind || !elem.fPath.equals(fPath)) { + return false; + } + switch (fEntryKind) { + case IPathEntry.CDT_INCLUDE: + return (getAttribute(INCLUDE).equals(elem.getAttribute(INCLUDE)) && + getAttribute(BASE_REF).equals(elem.getAttribute(BASE_REF)) && + getAttribute(BASE).equals(elem.getAttribute(BASE))); + case IPathEntry.CDT_MACRO: + return (getAttribute(MACRO_NAME).equals(elem.getAttribute(MACRO_NAME)) && + getAttribute(BASE_REF).equals(elem.getAttribute(BASE_REF)) && + getAttribute(BASE).equals(elem.getAttribute(BASE))); + } + return true; } return false; } @@ -337,6 +353,7 @@ public class CPListElement { String macroValue = null; boolean sysInclude = false; IPath baseRef = null; + IPath base = null; // get the resource IResource res = null; @@ -398,6 +415,8 @@ public class CPListElement { exclusion = ((IIncludeEntry) curr).getExclusionPatterns(); sysInclude = ((IIncludeEntry) curr).isSystemInclude(); baseRef = ((IIncludeEntry) curr).getBasePath(); + base = new Path(""); +// base = ((IIncludeEntry) curr).getBasePath(); include = ((IIncludeEntry) curr).getIncludePath(); break; case IPathEntry.CDT_MACRO: @@ -413,6 +432,8 @@ public class CPListElement { macroName = ((IMacroEntry) curr).getMacroName(); macroValue = ((IMacroEntry) curr).getMacroValue(); baseRef = ((IMacroEntry) curr).getBasePath(); + base = new Path(""); +// base = ((IIncludeEntry) curr).getBasePath(); break; case IPathEntry.CDT_PROJECT: res = root.findMember(path); @@ -427,6 +448,7 @@ public class CPListElement { elem.setAttribute(MACRO_VALUE, macroValue); elem.setAttribute(SYSTEM_INCLUDE, Boolean.valueOf(sysInclude)); elem.setAttribute(BASE_REF, baseRef); + elem.setAttribute(BASE, base); elem.setExported(curr.isExported()); if (project.exists()) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathBasePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathBasePage.java index f7291f0ef38..26eea3f9570 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathBasePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathBasePage.java @@ -43,7 +43,7 @@ public abstract class CPathBasePage extends AbstractCOptionPage { IPath currPath = curr.getPath(); if (currPath.isPrefixOf(entryPath) && !currPath.equals(entryPath)) { IPath[] exclusionFilters = (IPath[]) curr.getAttribute(CPListElement.EXCLUSION); - if (!CoreModelUtil.isExcludedPath(entryPath, exclusionFilters)) { + if (!CoreModelUtil.isExcludedPath(entryPath.removeFirstSegments(1), exclusionFilters)) { IPath pathToExclude = entryPath.removeFirstSegments(currPath.segmentCount()).addTrailingSeparator(); IPath[] newExclusionFilters = new IPath[exclusionFilters.length + 1]; System.arraycopy(exclusionFilters, 0, newExclusionFilters, 0, exclusionFilters.length); 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 2cdcde29484..ad977995fa2 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 @@ -29,6 +29,8 @@ SymbolEntryPage.remove=Remove SymbolEntryPage.listName=Defines: SymbolEntryPage.editSourcePaths=Edit Source Paths... SymbolEntryPage.sourcePaths=Source Paths: +IncludeEntryPage.addExternal.title=Add User Symbol +IncludeEntryPage.addExternal.message=Symbol definition: # ------- IncludeEntryPage ---------- IncludeEntryPage.title=Include Paths @@ -39,7 +41,9 @@ IncludeEntryPage.remove=Remove IncludeEntryPage.listName=Include Paths: IncludeEntryPage.editSourcePaths=Edit Source Paths... IncludeEntryPage.sourcePaths=Source Paths: - +IncludeEntryPage.addExternal.button.browse=Browse... +IncludeEntryPage.addExternal.title=Add External Include Path +IncludeEntryPage.addExternal.message=Include path: # ------- BuildPathsBlock ------- CPathsBlock.path.up.button=&Up CPathsBlock.path.down.button=&Down 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 22aaf437701..362889c2834 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 @@ -9,8 +9,23 @@ ******************************************************************************/ package org.eclipse.cdt.internal.ui.dialogs.cpaths; +import java.util.List; + +import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.dialogs.IInputValidator; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Shell; public class CPathIncludeEntryPage extends ExtendedCPathBasePage { @@ -23,6 +38,53 @@ public class CPathIncludeEntryPage extends ExtendedCPathBasePage { } protected void addPath() { + InputDialog dialog = new SelectPathInputDialog(getShell(), + CPathEntryMessages.getString("IncludeEntryPage.addExternal.title"), //$NON-NLS-1$ + CPathEntryMessages.getString("IncludeEntryPage.addExternal.message"), null, null); //$NON-NLS-1$ + String newItem = null; + if (dialog.open() == Window.OK) { + newItem = dialog.getValue(); + if (newItem != null && !newItem.equals("")) { //$NON-NLS-1$ + List cplist = fPathList.getElements(); + + CPListElement newPath = newCPElement(((ICElement) getSelection().get(0)).getResource()); + newPath.setAttribute(CPListElement.INCLUDE, new Path(newItem)); + if (!cplist.contains(newPath)) { + fPathList.addElement(newPath); + fCPathList.add(newPath); + fPathList.postSetSelection(new StructuredSelection(newPath)); + } + } + } + } + + private class SelectPathInputDialog extends InputDialog { + + public SelectPathInputDialog(Shell parentShell, String dialogTitle, String dialogMessage, String initialValue, + IInputValidator validator) { + super(parentShell, dialogTitle, dialogMessage, initialValue, validator); + } + + protected void createButtonsForButtonBar(Composite parent) { + super.createButtonsForButtonBar(parent); + Button browse = createButton(parent, 3, CPathEntryMessages.getString("IncludeEntryPage.addExternal.button.browse"), //$NON-NLS-1$ + true); //$NON-NLS-1$ + browse.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent ev) { + DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.OPEN); + String currentName = getText().getText(); + if (currentName != null && currentName.trim().length() != 0) { + dialog.setFilterPath(currentName); + } + String dirname = dialog.open(); + if (dirname != null) { + getText().setText(dirname); + } + } + }); + } } + } \ 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 7a28722099b..ff6294e79fe 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 @@ -1,16 +1,22 @@ /******************************************************************************* * Copyright (c) 2002, 2003, 2004 QNX Software Systems Ltd. and others. All * rights reserved. This program and the accompanying materials are made - * available under the terms of the Common Public License v1.0 which - * accompanies this distribution, and is available at + * available under the terms of the Common Public License v1.0 which accompanies + * this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: QNX Software Systems - Initial API and implementation ******************************************************************************/ package org.eclipse.cdt.internal.ui.dialogs.cpaths; +import java.util.List; + +import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.window.Window; public class CPathSymbolEntryPage extends ExtendedCPathBasePage { @@ -21,8 +27,26 @@ public class CPathSymbolEntryPage extends ExtendedCPathBasePage { protected int getEntryKind() { return IPathEntry.CDT_MACRO; } - - protected void addPath() { + protected void addPath() { + // Popup an entry dialog + InputDialog dialog = new InputDialog(getShell(), CPathEntryMessages.getString("SymbolEntryPage.addExternal.title"), //$NON-NLS-1$ + CPathEntryMessages.getString("SymbolEntryPage.addExternal.message"), "", //$NON-NLS-1$ //$NON-NLS-2$ + null); + String symbol = null; + if (dialog.open() == Window.OK) { + symbol = dialog.getValue(); + if (symbol != null && symbol.length() > 0) { + List cplist = fPathList.getElements(); + + CPListElement newPath = newCPElement(((ICElement) getSelection().get(0)).getResource()); + newPath.setAttribute(CPListElement.MACRO_NAME, symbol); + if (!cplist.contains(newPath)) { + fPathList.addElement(newPath); + fCPathList.add(newPath); + fPathList.postSetSelection(new StructuredSelection(newPath)); + } + } + } } } \ 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 320f87cec66..b8a5658325d 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 @@ -73,16 +73,16 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage { public void customButtonPressed(ListDialogField field, int index) { switch (index) { - case IDX_ADD : + case IDX_ADD: addPath(); break; - case IDX_ADD_WORKSPACE : + case IDX_ADD_WORKSPACE: addFromWorkspace(); break; - case IDX_ADD_CONTRIBUTED : + case IDX_ADD_CONTRIBUTED: addContributed(); break; - case IDX_REMOVE : + case IDX_REMOVE: if (canRemove(field.getSelectedElements())) { removePath((CPListElement) field.getSelectedElements().get(0)); } @@ -127,7 +127,7 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage { fPrefix = prefix; IncludeListAdapter includeListAdaper = new IncludeListAdapter(); - String[] buttonLabel = new String[]{ /* 0 */CPathEntryMessages.getString(prefix + ".add"), //$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$ @@ -139,7 +139,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() { @@ -156,7 +156,7 @@ 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); @@ -164,15 +164,15 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage { fPathList.enableButton(IDX_REMOVE, false); } - + public boolean isEntryKind(int kind) { return kind == getEntryKind(); } - + abstract protected void addPath(); abstract int getEntryKind(); - + protected boolean canRemove(List selected) { return !selected.isEmpty(); } @@ -180,8 +180,7 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage { protected void removePath(CPListElement element) { ICElement celem = (ICElement) getSelection().get(0); if (!celem.getPath().equals(element.getPath())) { - IPath exclude = celem.getPath(); - + IPath exclude = element.getPath().removeFirstSegments(element.getPath().segmentCount()).addTrailingSeparator(); IPath[] exclusions = (IPath[]) element.getAttribute(CPListElement.EXCLUSION); IPath[] newExlusions = new IPath[exclusions.length + 1]; System.arraycopy(exclusions, 0, newExlusions, 0, exclusions.length); @@ -256,7 +255,9 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage { while (iter.hasNext()) { CPListElement element = (CPListElement) iter.next(); if (element.getPath().isPrefixOf(resPath) - && !CoreModelUtil.isExcludedPath(resPath, (IPath[]) element.getAttribute(CPListElement.EXCLUSION))) { //$NON-NLS-1$ + && (element.getPath().equals(resPath) + || !CoreModelUtil.isExcludedPath(resPath.removeFirstSegments(1), + (IPath[]) element.getAttribute(CPListElement.EXCLUSION)))) { newList.add(element); } } @@ -294,7 +295,7 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage { return null; } - private CPListElement newCPElement(IResource resource) { + protected CPListElement newCPElement(IResource resource) { return new CPListElement(fCurrCProject, getEntryKind(), resource.getFullPath(), resource); } @@ -364,9 +365,10 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage { } protected CPListElement[] openWorkspacePathEntryDialog(CPListElement existing) { - Class[] acceptedClasses = new Class[]{CPListElement.class}; + Class[] acceptedClasses = new Class[] { CPListElement.class}; TypedElementSelectionValidator validator = new TypedElementSelectionValidator(acceptedClasses, existing == null); - ViewerFilter filter = new CPListElementFilter((CPListElement[]) fPathList.getElements().toArray(new CPListElement[0]), getEntryKind(), true); + ViewerFilter filter = new CPListElementFilter((CPListElement[]) fPathList.getElements().toArray(new CPListElement[0]), + getEntryKind(), true); ILabelProvider lp = new WorkbenchCPathLabelProvider(); ITreeContentProvider cp = new WorkbenchCPathContentProvider(); @@ -403,19 +405,20 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage { protected void addContributed() { CPListElement[] includes = openContainerSelectionDialog(null); if (includes != null) { - int nElementsChosen= includes.length; + int nElementsChosen = includes.length; // remove duplicates - List cplist= fPathList.getElements(); - List elementsToAdd= new ArrayList(nElementsChosen); - - for (int i= 0; i < nElementsChosen; i++) { - CPListElement curr= includes[i]; + List cplist = fPathList.getElements(); + List elementsToAdd = new ArrayList(nElementsChosen); + + for (int i = 0; i < nElementsChosen; i++) { + CPListElement curr = includes[i]; if (!cplist.contains(curr) && !elementsToAdd.contains(curr)) { elementsToAdd.add(curr); } } - + fPathList.addElements(elementsToAdd); + fCPathList.addAll(elementsToAdd); fPathList.postSetSelection(new StructuredSelection(includes)); } } @@ -423,22 +426,23 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage { protected void addFromWorkspace() { CPListElement[] includes = openWorkspacePathEntryDialog(null); if (includes != null) { - int nElementsChosen= includes.length; + int nElementsChosen = includes.length; // remove duplicates - List cplist= fPathList.getElements(); - List elementsToAdd= new ArrayList(nElementsChosen); - - for (int i= 0; i < nElementsChosen; i++) { - CPListElement curr= includes[i]; + List cplist = fPathList.getElements(); + List elementsToAdd = new ArrayList(nElementsChosen); + + for (int i = 0; i < nElementsChosen; i++) { + CPListElement curr = includes[i]; if (!cplist.contains(curr) && !elementsToAdd.contains(curr)) { elementsToAdd.add(curr); } } - + fPathList.addElements(elementsToAdd); - fPathList.postSetSelection(new StructuredSelection(includes)); + fCPathList.addAll(elementsToAdd); + fPathList.postSetSelection(new StructuredSelection(elementsToAdd)); } - + } // private IPathEntry[] getUsedPathFiles(CPListElement existing) {