mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug #182820: support for "canExclude()"
This commit is contained in:
parent
1aa3d8f62f
commit
1f69bd652c
1 changed files with 56 additions and 41 deletions
|
@ -33,17 +33,19 @@ import org.eclipse.ui.IWorkbenchWindow;
|
|||
import org.eclipse.ui.IWorkbenchWindowPulldownDelegate2;
|
||||
import org.eclipse.ui.dialogs.ListSelectionDialog;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICContainer;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
|
||||
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.newui.AbstractPage;
|
||||
import org.eclipse.cdt.ui.newui.UIMessages;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.actions.ActionMessages;
|
||||
|
||||
|
@ -82,16 +84,24 @@ implements IWorkbenchWindowPulldownDelegate2, IObjectActionDelegate {
|
|||
if (res != null) {
|
||||
ICConfigurationDescription[] cfgds = getCfgsRead(res);
|
||||
if (cfgds == null || cfgds.length == 0) continue;
|
||||
|
||||
if (objects == null) objects = new ArrayList();
|
||||
objects.add(res);
|
||||
if (cfgNames == null) {
|
||||
cfgNames = new ArrayList(cfgds.length);
|
||||
for (int j=0; j<cfgds.length; j++)
|
||||
for (int j=0; j<cfgds.length; j++) {
|
||||
if (!canExclude(res, cfgds[j])) {
|
||||
cfgNames = null;
|
||||
cfgsOK = false;
|
||||
break;
|
||||
}
|
||||
cfgNames.add(cfgds[j].getName());
|
||||
}
|
||||
} else {
|
||||
if (cfgNames.size() != cfgds.length) cfgsOK = false;
|
||||
else for (int j=0; j<cfgds.length; j++) {
|
||||
if (!cfgNames.contains(cfgds[j].getName())) {
|
||||
if (! canExclude(res, cfgds[j]) ||
|
||||
! cfgNames.contains(cfgds[j].getName())) {
|
||||
cfgsOK = false;
|
||||
break;
|
||||
}
|
||||
|
@ -104,6 +114,22 @@ implements IWorkbenchWindowPulldownDelegate2, IObjectActionDelegate {
|
|||
}
|
||||
action.setEnabled(cfgsOK && objects != null );
|
||||
}
|
||||
|
||||
private boolean canExclude(IResource res, ICConfigurationDescription cfg) {
|
||||
IPath p = res.getFullPath();
|
||||
ICSourceEntry[] ent = cfg.getSourceEntries();
|
||||
boolean state = CDataUtil.isExcluded(p, ent);
|
||||
return CDataUtil.canExclude(p, (res instanceof IFolder), !state, ent);
|
||||
}
|
||||
|
||||
private void setExclude(IResource res, ICConfigurationDescription cfg, boolean exclude) {
|
||||
try {
|
||||
ICSourceEntry[] newEntries = CDataUtil.setExcluded(res.getFullPath(), (res instanceof IFolder), exclude, cfg.getSourceEntries());
|
||||
cfg.setSourceEntries(newEntries);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void run(IAction action) {
|
||||
openDialog();
|
||||
|
@ -135,57 +161,46 @@ implements IWorkbenchWindowPulldownDelegate2, IObjectActionDelegate {
|
|||
while(it.hasNext()) {
|
||||
IResource res = (IResource)it.next();
|
||||
ICConfigurationDescription[] cfgds = getCfgsRead(res);
|
||||
IPath p = res.getProjectRelativePath();
|
||||
IPath p = res.getFullPath();
|
||||
for (int i=0; i<cfgds.length; i++) {
|
||||
ICResourceDescription out = cfgds[i].getResourceDescription(p, false);
|
||||
if (!out.isExcluded()) status[i] = true;
|
||||
boolean b = CDataUtil.isExcluded(p, cfgds[i].getSourceEntries());
|
||||
if (b) status[i] = true;
|
||||
}
|
||||
}
|
||||
ArrayList lst = new ArrayList();
|
||||
for (int i=0; i<status.length; i++)
|
||||
if (!status[i]) lst.add(cfgNames.get(i));
|
||||
if (status[i]) lst.add(cfgNames.get(i));
|
||||
if (lst.size() > 0)
|
||||
dialog.setInitialElementSelections(lst);
|
||||
|
||||
if (dialog.open() == Window.OK) {
|
||||
Object[] selected = dialog.getResult(); // may be empty
|
||||
Iterator it2 = objects.iterator();
|
||||
outer:
|
||||
while(it2.hasNext()) {
|
||||
IResource res = (IResource)it2.next();
|
||||
IProject p = res.getProject();
|
||||
if (!p.isOpen()) continue;
|
||||
// get writable description
|
||||
ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(p, true);
|
||||
if (prjd == null) continue;
|
||||
ICConfigurationDescription[] cfgds = prjd.getConfigurations();
|
||||
IPath p2 = res.getProjectRelativePath();
|
||||
for (int i=0; i<cfgds.length; i++) {
|
||||
ICResourceDescription out = cfgds[i].getResourceDescription(p2, false);
|
||||
if (! p2.equals(out.getPath()) ) {
|
||||
try {
|
||||
if (res instanceof IFolder)
|
||||
out = cfgds[i].createFolderDescription(p2, (ICFolderDescription)out);
|
||||
else
|
||||
out = cfgds[i].createFileDescription(p2, out);
|
||||
} catch (CoreException e) { continue outer; }
|
||||
}
|
||||
if (out != null) {
|
||||
boolean exclude = false;
|
||||
for (int j=0; j<selected.length; j++) {
|
||||
if (cfgds[i].getName().equals(selected[j])) {
|
||||
exclude = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
out.setExcluded(exclude);
|
||||
while(it2.hasNext()) {
|
||||
IResource res = (IResource)it2.next();
|
||||
IProject p = res.getProject();
|
||||
if (!p.isOpen()) continue;
|
||||
// get writable description
|
||||
ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(p, true);
|
||||
if (prjd == null) continue;
|
||||
ICConfigurationDescription[] cfgds = prjd.getConfigurations();
|
||||
for (int i=0; i<cfgds.length; i++) {
|
||||
boolean exclude = false;
|
||||
for (int j=0; j<selected.length; j++) {
|
||||
if (cfgds[i].getName().equals(selected[j])) {
|
||||
exclude = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
CoreModel.getDefault().setProjectDescription(p, prjd);
|
||||
} catch (CoreException e) {}
|
||||
AbstractPage.updateViews(res);
|
||||
setExclude(res, cfgds[i], exclude);
|
||||
}
|
||||
try {
|
||||
CoreModel.getDefault().setProjectDescription(p, prjd);
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().logErrorMessage(UIMessages.getString("AbstractPage.11") + e.getLocalizedMessage()); //$NON-NLS-1$
|
||||
}
|
||||
AbstractPage.updateViews(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue