From ed9b414f4dab4c00a47cd5b109ccdd124c922377 Mon Sep 17 00:00:00 2001 From: Oleg Krasilnikov Date: Thu, 28 Feb 2008 14:00:31 +0000 Subject: [PATCH] Bug #220003 : CProject Source location preference tab does not allow to add project root as source folder --- .../NewSourceFolderWizardPage.java | 29 +++-- .../eclipse/cdt/ui/newui/CLocationTab.java | 111 ++++++++++++++++-- .../cdt/ui/newui/PluginResources.properties | 1 + 3 files changed, 117 insertions(+), 24 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/folderwizard/NewSourceFolderWizardPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/folderwizard/NewSourceFolderWizardPage.java index 73991531031..6e4752d054b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/folderwizard/NewSourceFolderWizardPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/folderwizard/NewSourceFolderWizardPage.java @@ -127,8 +127,6 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage { fExcludeInOthersFields.setDialogFieldListener(adapter); fExcludeInOthersFields.setLabelText(NewFolderWizardMessages.getString("NewSourceFolderWizardPage.exclude.label")); //$NON-NLS-1$ -//TODO fExcludeInOthersFields.setEnabled(CoreModel.ENABLED.equals(CoreModel.getOption(CoreModel.CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS))); - fRootStatus= new StatusInfo(); fProjectStatus= new StatusInfo(); } @@ -214,6 +212,9 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage { LayoutUtil.setHorizontalGrabbing(fProjectField.getTextControl(null)); LayoutUtil.setWidthHint(fRootDialogField.getTextControl(null), maxFieldWidth); + // Bug #220003 : consistency between New Source Folder dialog and Source Location Property tab. + fExcludeInOthersFields.setSelection(true); + setControl(composite); Dialog.applyDialogFont(composite); PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, ICHelpContextIds.NEW_SRCFLDER_WIZARD_PAGE); @@ -333,7 +334,7 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage { return; } } - ArrayList newEntries= new ArrayList(fEntries.length + 1); + ArrayList newEntries= new ArrayList(fEntries.length + 1); int projectEntryIndex= -1; for (int i= 0; i < fEntries.length; i++) { @@ -352,7 +353,7 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage { IPathEntry newEntry= CoreModel.newSourceEntry(path); - Set modified= new HashSet(); + Set modified= new HashSet(); if (fExcludeInOthersFields.isSelected()) { addExclusionPatterns(newEntry, newEntries, modified); newEntries.add(CoreModel.newSourceEntry(path)); @@ -365,7 +366,7 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage { } } - fNewEntries= (IPathEntry[]) newEntries.toArray(new IPathEntry[newEntries.size()]); + fNewEntries= newEntries.toArray(new IPathEntry[newEntries.size()]); ICModelStatus status= PathEntryManager.getDefault().validatePathEntry(fCurrCProject, fNewEntries); if (!status.isOK()) { @@ -387,10 +388,10 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage { } } - private void addExclusionPatterns(IPathEntry newEntry, List existing, Set modifiedEntries) { + private void addExclusionPatterns(IPathEntry newEntry, List existing, Set modifiedEntries) { IPath entryPath= newEntry.getPath(); for (int i= 0; i < existing.size(); i++) { - IPathEntry curr= (IPathEntry) existing.get(i); + IPathEntry curr= existing.get(i); IPath currPath= curr.getPath(); if (curr.getEntryKind() == IPathEntry.CDT_SOURCE && currPath.isPrefixOf(entryPath)) { IPath[] exclusionFilters= ((ISourceEntry)curr).getExclusionPatterns(); @@ -452,8 +453,7 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage { private void addEntryToAllCfgs(ICProjectDescription des, ICSourceEntry entry, boolean removeProj) throws WriteAccessException, CoreException{ ICConfigurationDescription cfgs[] = des.getConfigurations(); - for(int i = 0; i < cfgs.length; i++){ - ICConfigurationDescription cfg = cfgs[i]; + for(ICConfigurationDescription cfg : cfgs){ ICSourceEntry[] entries = cfg.getSourceEntries(); entries = addEntry(entries, entry, removeProj); cfg.setSourceEntries(entries); @@ -461,15 +461,14 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage { } private ICSourceEntry[] addEntry(ICSourceEntry[] entries, ICSourceEntry entry, boolean removeProj){ - Set set = new HashSet(); - for(int i = 0; i < entries.length; i++){ - if(removeProj && new Path(entries[i].getValue()).segmentCount() == 1) + Set set = new HashSet(); + for(ICSourceEntry se : entries){ + if(removeProj && new Path(se.getValue()).segmentCount() == 1) continue; - - set.add(entries[i]); + set.add(se); } set.add(entry); - return (ICSourceEntry[])set.toArray(new ICSourceEntry[set.size()]); + return set.toArray(new ICSourceEntry[set.size()]); } // ------------- choose dialogs diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/CLocationTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/CLocationTab.java index 40d228fddad..df95c271941 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/CLocationTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/CLocationTab.java @@ -11,10 +11,13 @@ package org.eclipse.cdt.ui.newui; import java.util.ArrayList; +import java.util.HashSet; import java.util.Iterator; +import java.util.Set; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IAdaptable; @@ -174,7 +177,7 @@ public abstract class CLocationTab extends AbstractCPropertyTab { switch (x) { // add case 0: - String[] ss = getProjectDialog(shell, EMPTY_STR); + String[] ss = getProjectDialog(shell); if (ss != null) { for (int i=0; i set = new HashSet(src.size()); + for (_Entry e : src) + set.add(e.getPath()); + + LocDialog dialog = new LocDialog(shell, set); dialog.setInput(page.getProject()); IResource container = null; @@ -300,20 +307,106 @@ public abstract class CLocationTab extends AbstractCPropertyTab { if (resources != null) { String[] ss = new String[resources.length]; for (int i=0; i existing; + + public LocDialog(Shell parent, Set ex) { + super(parent, + + new WorkbenchLabelProvider() { + protected String decorateText(String input, Object element) { + if (element instanceof Holder && + ((Holder)element).isRoot()) + return UIMessages.getString("CLocationTab.8"); //$NON-NLS-1$ + return super.decorateText(input, element); + } + }, + + new WorkbenchContentProvider() { + public Object[] getChildren(Object element) { + if (element instanceof IProject) { + Object[] ob1 = super.getChildren(element); + Object[] ob2 = new Object[ob1.length + 1]; + int cnt = 0; + ob2[cnt++] = new Holder((IProject)element); + for (Object ob: ob1) { + if (ob instanceof IFolder) + ob2[cnt++] = new Holder((IFolder)ob); + } + ob1 = new Object[cnt]; + System.arraycopy(ob2, 0, ob1, 0, cnt); + return ob1; + } else if (element instanceof Holder) { + Holder h = (Holder)element; + if (h.isRoot()) + return new Object[0]; + Object[] ob1 = super.getChildren(h.getFolder()); + Object[] ob2 = new Object[ob1.length]; + int cnt = 0; + for (Object ob: ob1) { + if (ob instanceof IFolder) + ob2[cnt++] = new Holder((IFolder)ob); + } + ob1 = new Object[cnt]; + System.arraycopy(ob2, 0, ob1, 0, cnt); + return ob1; + } else + return super.getChildren(element); + } + }); + addFilter(new ViewerFilter () { public boolean select(Viewer viewer, Object parentElement, Object element) { - return element instanceof IFolder; + if (! (element instanceof Holder)) + return false; + if (existing == null || existing.size() == 0) + return true; + Holder h = (Holder)element; + return (! existing.contains(h.getPath())); }}); - } + + existing = ex; + } } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/PluginResources.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/PluginResources.properties index 23717df6c37..48b03a3354e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/PluginResources.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/PluginResources.properties @@ -437,6 +437,7 @@ CLocationTab.4=Add Folder... CLocationTab.5=Link Folder... CLocationTab.6=Edit Filter... CLocationTab.7=Delete +CLocationTab.8= CLocationSourceTab.0=Source folders on build path: CLocationOutputTab.0=Output folders on build path: EnvDialog.0=Name: