mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-30 21:55:31 +02:00
Bug #220003 : CProject Source location preference tab does not allow to add project root as source folder
This commit is contained in:
parent
27c357c01a
commit
ed9b414f4d
3 changed files with 117 additions and 24 deletions
|
@ -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<IPathEntry> newEntries= new ArrayList<IPathEntry>(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<IPathEntry> modified= new HashSet<IPathEntry>();
|
||||
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<IPathEntry> existing, Set<IPathEntry> 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<ICSourceEntry> set = new HashSet<ICSourceEntry>();
|
||||
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
|
||||
|
|
|
@ -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<ss.length; i++)
|
||||
src.add(new _Entry(newEntry(new Path(ss[i]), new IPath[0], true)));
|
||||
|
@ -280,10 +283,14 @@ public abstract class CLocationTab extends AbstractCPropertyTab {
|
|||
return page.isForProject();
|
||||
}
|
||||
|
||||
private String[] getProjectDialog(Shell shell, String text) {
|
||||
IPath path = new Path(text);
|
||||
private String[] getProjectDialog(Shell shell) {
|
||||
IPath path = new Path(EMPTY_STR);
|
||||
|
||||
LocDialog dialog = new LocDialog(shell);
|
||||
Set<IPath> set = new HashSet<IPath>(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<resources.length; i++)
|
||||
ss[i] = ((IResource)resources[i]).getFullPath().toString();
|
||||
ss[i] = ((Holder)resources[i]).getPath().toString();
|
||||
return ss;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class should hold elements for source location tree
|
||||
*/
|
||||
class Holder implements IAdaptable {
|
||||
private IFolder f = null;
|
||||
private boolean isRoot = false;
|
||||
private IPath p = null;
|
||||
|
||||
Holder(IProject _p) {
|
||||
f = _p.getFolder(_p.getName());
|
||||
isRoot = true;
|
||||
p = _p.getFullPath();
|
||||
}
|
||||
|
||||
Holder(IFolder _f) {
|
||||
f = _f;
|
||||
isRoot = false;
|
||||
p = _f.getFullPath();
|
||||
}
|
||||
|
||||
public Object getAdapter(Class adapter) {
|
||||
return f.getAdapter(adapter);
|
||||
}
|
||||
public boolean isRoot() {
|
||||
return isRoot;
|
||||
}
|
||||
public IFolder getFolder() {
|
||||
return f;
|
||||
}
|
||||
public IPath getPath() {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
class LocDialog extends ElementTreeSelectionDialog {
|
||||
public LocDialog(Shell parent) {
|
||||
super(parent, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
|
||||
Set <IPath> existing;
|
||||
|
||||
public LocDialog(Shell parent, Set <IPath> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -437,6 +437,7 @@ CLocationTab.4=Add Folder...
|
|||
CLocationTab.5=Link Folder...
|
||||
CLocationTab.6=Edit Filter...
|
||||
CLocationTab.7=Delete
|
||||
CLocationTab.8=<root folder>
|
||||
CLocationSourceTab.0=Source folders on build path:
|
||||
CLocationOutputTab.0=Output folders on build path:
|
||||
EnvDialog.0=Name:
|
||||
|
|
Loading…
Add table
Reference in a new issue