From 5d85dce38ee350a0f287182fd8353e8fb0061e14 Mon Sep 17 00:00:00 2001 From: Mikhail Sennikovsky Date: Fri, 23 Mar 2007 15:33:28 +0000 Subject: [PATCH] Fix for [Bug 178960] New source folder wizard dont updates / overwrites source locations and [Bug 178970] new source folder wizard creates extra includes paths --- .../NewSourceFolderWizardPage.java | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) 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 d0ff5b49aff..46928da131a 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 @@ -45,6 +45,7 @@ import org.eclipse.ui.model.WorkbenchLabelProvider; import org.eclipse.ui.views.navigator.ResourceComparator; import org.eclipse.cdt.core.CCProjectNature; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; @@ -55,6 +56,11 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.core.model.ISourceEntry; import org.eclipse.cdt.core.model.ISourceRoot; +import org.eclipse.cdt.core.settings.model.CSourceEntry; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.core.settings.model.ICSourceEntry; +import org.eclipse.cdt.core.settings.model.WriteAccessException; import org.eclipse.cdt.ui.CElementLabelProvider; import org.eclipse.cdt.ui.CUIPlugin; @@ -429,7 +435,14 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage { throw new InterruptedException(); } - fCurrCProject.setRawPathEntries(fNewEntries, new SubProgressMonitor(monitor, 2)); + if(CCorePlugin.getDefault().isNewStyleProject(fCurrCProject.getProject())){ + ICSourceEntry newEntry = new CSourceEntry(folder, null, 0); + ICProjectDescription des = CCorePlugin.getDefault().getProjectDescription(fCurrCProject.getProject(), true); + addEntryToAllCfgs(des, newEntry, fIsProjectAsSourceFolder); + CCorePlugin.getDefault().setProjectDescription(fCurrCProject.getProject(), des, false, new SubProgressMonitor(monitor, 2)); + } else { + fCurrCProject.setRawPathEntries(fNewEntries, new SubProgressMonitor(monitor, 2)); + } fCreatedRoot= fCurrCProject.findSourceRoot(folder); } finally { @@ -437,6 +450,28 @@ 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]; + ICSourceEntry[] entries = cfg.getSourceEntries(); + entries = addEntry(entries, entry, removeProj); + cfg.setSourceEntries(entries); + } + } + + 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() == 0) + continue; + + set.add(entries[i]); + } + set.add(entry); + return (ICSourceEntry[])set.toArray(new ICSourceEntry[set.size()]); + } + // ------------- choose dialogs private IFolder chooseFolder(String title, String message, IPath initialPath) {