1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Always pop the dialog and should work for multiple selection.

This commit is contained in:
Alain Magloire 2003-10-22 00:15:39 +00:00
parent dfdfecab15
commit 5805d0cfee

View file

@ -10,6 +10,7 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.make.internal.ui.editor; package org.eclipse.cdt.make.internal.ui.editor;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.make.core.IMakeTarget; import org.eclipse.cdt.make.core.IMakeTarget;
@ -31,6 +32,7 @@ import org.eclipse.ui.IFileEditorInput;
public class AddBuildTargetAction extends Action { public class AddBuildTargetAction extends Action {
MakefileContentOutlinePage fOutliner; MakefileContentOutlinePage fOutliner;
static final ITargetRule[] EMPTY_TARGET_RULES = {};
public AddBuildTargetAction(MakefileContentOutlinePage outliner) { public AddBuildTargetAction(MakefileContentOutlinePage outliner) {
super("Add To Build Target"); super("Add To Build Target");
@ -45,11 +47,42 @@ public class AddBuildTargetAction extends Action {
public void run() { public void run() {
IMakeTargetManager manager = MakeCorePlugin.getDefault().getTargetManager(); IMakeTargetManager manager = MakeCorePlugin.getDefault().getTargetManager();
IFile file = getFile(); IFile file = getFile();
ITargetRule rule = getTargetRule(fOutliner.getSelection());
Shell shell = fOutliner.getControl().getShell(); Shell shell = fOutliner.getControl().getShell();
if (file != null && rule != null && shell != null) { ITargetRule[] rules = getTargetRules(fOutliner.getSelection());
String name = rule.getTarget().toString().trim(); if (file != null && rules.length > 0 && shell != null) {
IMakeTarget target = manager.findTarget(file.getParent(), name); StringBuffer sbBuildName = new StringBuffer();
StringBuffer sbMakefileTarget = new StringBuffer();
for (int i = 0; i < rules.length; i++) {
String name = rules[i].getTarget().toString().trim();
if (sbBuildName.length() == 0) {
sbBuildName.append(name);
} else {
sbBuildName.append('_').append(name);
}
if (sbMakefileTarget.length() == 0) {
sbMakefileTarget.append(name);
} else {
sbMakefileTarget.append(' ').append(name);
}
}
String buildName = sbBuildName.toString();
String makefileTarget = sbMakefileTarget.toString();
IMakeTarget target = manager.findTarget(file.getParent(), buildName);
if (target == null) {
try {
String[] ids = manager.getTargetBuilders(file.getProject());
if (ids.length > 0) {
target = manager.createTarget(file.getProject(), buildName, ids[0]);
target.setBuildTarget(makefileTarget);
manager.addTarget(file.getParent(), target);
}
} catch (CoreException e) {
MakeUIPlugin.errorDialog(shell, "Internal Error", "", e);
target = null;
}
}
// Always popup the dialog.
if (target != null) { if (target != null) {
MakeTargetDialog dialog; MakeTargetDialog dialog;
try { try {
@ -58,30 +91,21 @@ public class AddBuildTargetAction extends Action {
} catch (CoreException e) { } catch (CoreException e) {
MakeUIPlugin.errorDialog(shell, "Internal Error", "", e); MakeUIPlugin.errorDialog(shell, "Internal Error", "", e);
} }
} else {
try {
String[] ids = manager.getTargetBuilders(file.getProject());
if (ids.length > 0) {
target = manager.createTarget(file.getProject(), name, ids[0]);
target.setBuildTarget(name);
manager.addTarget(file.getParent(), target);
}
} catch (CoreException e) {
MakeUIPlugin.errorDialog(shell, "Internal Error", "", e);
}
} }
} }
} }
public boolean canActionBeAdded(ISelection selection) { public boolean canActionBeAdded(ISelection selection) {
ITargetRule rule = getTargetRule(selection); ITargetRule[] rules = getTargetRules(selection);
if (rule != null) { boolean ok = false;
for (int i = 0; i < rules.length; i++) {
IFile file = getFile(); IFile file = getFile();
if (file != null) { if (file == null)
return MakeCorePlugin.getDefault().getTargetManager().hasTargetBuilder(file.getProject()); return false;
} if (! MakeCorePlugin.getDefault().getTargetManager().hasTargetBuilder(file.getProject()))
return false;
} }
return false; return true;
} }
@ -93,17 +117,21 @@ public class AddBuildTargetAction extends Action {
return null; return null;
} }
private ITargetRule getTargetRule(ISelection sel) { private ITargetRule[] getTargetRules(ISelection sel) {
if (!sel.isEmpty() && sel instanceof IStructuredSelection) { if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
List list= ((IStructuredSelection)sel).toList(); List list= ((IStructuredSelection)sel).toList();
if (list.size() == 1) { if (list.size() > 0) {
Object element= list.get(0); List targets = new ArrayList(list.size());
if (element instanceof ITargetRule) { Object[] elements = list.toArray();
return (ITargetRule)element; for (int i = 0; i < elements.length; i++) {
if (elements[i] instanceof ITargetRule) {
targets.add(elements[i]);
}
} }
return (ITargetRule[])list.toArray(EMPTY_TARGET_RULES);
} }
} }
return null; return EMPTY_TARGET_RULES;
} }
} }