1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

- moved build dialog to own package.

- modified actions 
       - proper behavior on selection
       - invoke build dialog in proper mode and selections.
This commit is contained in:
David Inglis 2003-08-21 19:46:04 +00:00
parent f1a4d0ae90
commit bf35ff6cac
7 changed files with 213 additions and 56 deletions

View file

@ -8,7 +8,14 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.make.ui.actions; package org.eclipse.cdt.make.ui.actions;
import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.make.core.IMakeTarget;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
import org.eclipse.cdt.make.ui.dialogs.BuildTargetDialog;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
@ -24,8 +31,25 @@ public class CreateBuildAction extends ActionDelegate implements IObjectActionDe
IContainer fContainer; IContainer fContainer;
public void run(IAction action) { public void run(IAction action) {
if ( fContainer != null ) {
BuildTargetDialog dialog = new BuildTargetDialog(fPart.getSite().getShell(), fContainer); BuildTargetDialog dialog = new BuildTargetDialog(fPart.getSite().getShell(), fContainer);
dialog.setOpenMode(BuildTargetDialog.OPEN_MODE_BUILD);
String name;
try {
name = (String) fContainer.getSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(), "lastTarget"));
IMakeTarget target = MakeCorePlugin.getDefault().getTargetManager().findTarget(fContainer, name);
dialog.setSelectedTarget(target);
} catch (CoreException e) {
}
dialog.open(); dialog.open();
IMakeTarget target = dialog.getSelectedTarget();
if ( target != null ) {
try {
fContainer.setSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(), "lastTarget"), target.getName());
} catch (CoreException e1) {
}
}
}
} }
public void setActivePart(IAction action, IWorkbenchPart targetPart) { public void setActivePart(IAction action, IWorkbenchPart targetPart) {
@ -37,8 +61,14 @@ public class CreateBuildAction extends ActionDelegate implements IObjectActionDe
public void selectionChanged(IAction action, ISelection selection) { public void selectionChanged(IAction action, ISelection selection) {
if ( selection instanceof IStructuredSelection ) { if ( selection instanceof IStructuredSelection ) {
fContainer = (IContainer)((IStructuredSelection)selection).getFirstElement(); IStructuredSelection sel = (IStructuredSelection)selection;
if ( sel.getFirstElement() instanceof ICContainer ) {
fContainer = (IContainer) ((ICContainer)sel.getFirstElement()).getUnderlyingResource();
} else if (sel.getFirstElement() instanceof IContainer ) {
fContainer = (IContainer)sel.getFirstElement();
} else {
fContainer = null;
}
} }
} }
} }

View file

@ -1,8 +1,9 @@
package org.eclipse.cdt.make.ui.actions; package org.eclipse.cdt.make.ui.dialogs;
import java.util.HashMap; import java.util.HashMap;
import org.eclipse.cdt.make.core.IMakeBuilderInfo; import org.eclipse.cdt.make.core.IMakeBuilderInfo;
import org.eclipse.cdt.make.core.IMakeTarget;
import org.eclipse.cdt.make.core.IMakeTargetManager; import org.eclipse.cdt.make.core.IMakeTargetManager;
import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
@ -26,6 +27,13 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
public class BuildTargetDialog extends TitleAreaDialog { public class BuildTargetDialog extends TitleAreaDialog {
private IMakeTarget fSelection;
public static int OPEN_MODE_BUILD = 1;
public static int OPEN_MODE_CREATE_NEW = 2;
public static int OPEN_MODE_RENAME = 2;
private int openMode;
private static final String PREFIX = "SettingsBlock"; //$NON-NLS-1$ private static final String PREFIX = "SettingsBlock"; //$NON-NLS-1$
private static final String MAKE_SETTING_GROUP = PREFIX + ".makeSetting.group_label"; //$NON-NLS-1$ private static final String MAKE_SETTING_GROUP = PREFIX + ".makeSetting.group_label"; //$NON-NLS-1$
@ -53,7 +61,7 @@ public class BuildTargetDialog extends TitleAreaDialog {
super(parentShell); super(parentShell);
fTargetManager = MakeCorePlugin.getDefault().getTargetManager(); fTargetManager = MakeCorePlugin.getDefault().getTargetManager();
String[] id = fTargetManager.getTargetBuilders(container.getProject()); String[] id = fTargetManager.getTargetBuilders(container.getProject());
if ( id != null) { if (id != null) {
fBuildInfo = MakeCorePlugin.createBuildInfo(new HashMap(), id[0]); fBuildInfo = MakeCorePlugin.createBuildInfo(new HashMap(), id[0]);
} }
} }
@ -137,4 +145,16 @@ public class BuildTargetDialog extends TitleAreaDialog {
defButton.setSelection(fBuildInfo.isDefaultBuildCmd()); defButton.setSelection(fBuildInfo.isDefaultBuildCmd());
} }
public void setOpenMode(int mode) {
openMode = mode;
}
public void setSelectedTarget(IMakeTarget target) {
fSelection = target;
}
public IMakeTarget getSelectedTarget() {
return null;
}
} }

View file

@ -5,18 +5,22 @@ package org.eclipse.cdt.make.ui.views;
* All Rights Reserved. * All Rights Reserved.
*/ */
import java.util.List;
import org.eclipse.cdt.make.internal.ui.MakeUIImages; import org.eclipse.cdt.make.internal.ui.MakeUIImages;
import org.eclipse.cdt.make.ui.dialogs.BuildTargetDialog;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.actions.SelectionListenerAction; import org.eclipse.ui.actions.SelectionListenerAction;
public class AddTargetAction extends SelectionListenerAction { public class AddTargetAction extends SelectionListenerAction {
Shell shell; Shell shell;
IResource resource; IResource resource;
public AddTargetAction (Shell shell) { public AddTargetAction(Shell shell) {
super("Add Build Target"); super("Add Build Target");
this.shell = shell; this.shell = shell;
@ -25,6 +29,27 @@ public class AddTargetAction extends SelectionListenerAction {
} }
public void run() { public void run() {
if (canAdd()) {
BuildTargetDialog dialog = new BuildTargetDialog(shell, (IContainer) getStructuredSelection().getFirstElement());
dialog.setOpenMode(BuildTargetDialog.OPEN_MODE_CREATE_NEW);
dialog.open();
}
} }
protected boolean updateSelection(IStructuredSelection selection) {
return super.updateSelection(selection) && canAdd();
}
private boolean canAdd() {
List elements = getStructuredSelection().toList();
if (elements.size() > 1 || elements.size() < 1) {
return false;
}
if (elements.get(0) instanceof IContainer) {
return true;
}
return false;
}
} }

View file

@ -5,18 +5,24 @@ package org.eclipse.cdt.make.ui.views;
* All Rights Reserved. * All Rights Reserved.
*/ */
import java.text.MessageFormat;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.make.core.IMakeTarget;
import org.eclipse.cdt.make.internal.ui.MakeUIImages; import org.eclipse.cdt.make.internal.ui.MakeUIImages;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.actions.SelectionListenerAction; import org.eclipse.ui.actions.SelectionListenerAction;
public class DeleteTargetAction extends SelectionListenerAction { public class DeleteTargetAction extends SelectionListenerAction {
Shell shell; Shell shell;
IResource resource; IResource resource;
public DeleteTargetAction (Shell shell) { public DeleteTargetAction(Shell shell) {
super("Delete Build Target"); super("Delete Build Target");
this.shell = shell; this.shell = shell;
@ -24,7 +30,58 @@ public class DeleteTargetAction extends SelectionListenerAction {
MakeUIImages.setImageDescriptors(this, "tool16", MakeUIImages.IMG_TOOLS_MAKE_TARGET_DELETE); MakeUIImages.setImageDescriptors(this, "tool16", MakeUIImages.IMG_TOOLS_MAKE_TARGET_DELETE);
} }
public void run() { /**
* Asks the user to confirm a delete operation.
*
* @return <code>true</code> if the user says to go ahead, and <code>false</code>
* if the deletion should be abandoned
*/
boolean confirmDelete() {
List targets = getTargetsToDelete();
String title;
String msg;
if (targets.size() == 1) {
title = "Confirm Target Deletion";
IMakeTarget target = (IMakeTarget) targets.get(0);
msg = MessageFormat.format("Are you sure you want to delete ''{0}''?", new Object[] { target.getName()});
} else {
title = "Confirm Multiple Target Deletion";
msg = MessageFormat.format("Are you sure you want to delete these {0} targets?", new Object[] { new Integer(targets.size())});
} }
return MessageDialog.openQuestion(shell, title, msg);
}
public void run() {
if (canDelete() && confirmDelete() == false)
return;
}
protected boolean updateSelection(IStructuredSelection selection) {
return super.updateSelection(selection) && canDelete();
}
/**
* @return
*/
private List getTargetsToDelete() {
return getStructuredSelection().toList();
}
/**
* @return
*/
private boolean canDelete() {
List elements = getStructuredSelection().toList();
if (elements.size() > 0) {
Iterator iterator = elements.iterator();
while (iterator.hasNext()) {
if (!(iterator.next() instanceof IMakeTarget)) {
return false;
}
}
return true;
}
return false;
}
} }

View file

@ -0,0 +1,55 @@
package org.eclipse.cdt.make.ui.views;
/*
* (c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*/
import java.util.List;
import org.eclipse.cdt.make.core.IMakeTarget;
import org.eclipse.cdt.make.internal.ui.MakeUIImages;
import org.eclipse.cdt.make.ui.dialogs.BuildTargetDialog;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.actions.SelectionListenerAction;
public class EditTargetAction extends SelectionListenerAction {
Shell shell;
IResource resource;
public EditTargetAction(Shell shell) {
super("Edit Build Target");
this.shell = shell;
setToolTipText("Edit Build Target");
MakeUIImages.setImageDescriptors(this, "tool16", MakeUIImages.IMG_TOOLS_MAKE_TARGET_EDIT);
}
public void run() {
if (canRename()) {
BuildTargetDialog dialog = new BuildTargetDialog(shell, (IContainer) getStructuredSelection().getFirstElement());
dialog.setOpenMode(BuildTargetDialog.OPEN_MODE_CREATE_NEW);
dialog.setSelectedTarget((IMakeTarget) getStructuredSelection().getFirstElement());
dialog.open();
}
}
protected boolean updateSelection(IStructuredSelection selection) {
return super.updateSelection(selection) && canRename();
}
private boolean canRename() {
List elements = getStructuredSelection().toList();
if (elements.size() > 1 || elements.size() < 1) {
return false;
}
if (elements.get(0) instanceof IMakeTarget) {
return true;
}
return false;
}
}

View file

@ -30,7 +30,7 @@ import org.eclipse.ui.part.ViewPart;
public class MakeView extends ViewPart { public class MakeView extends ViewPart {
private BuildTargetAction buildTargetAction; private BuildTargetAction buildTargetAction;
private RenameTargetAction renameTargetAction; private EditTargetAction editTargetAction;
private DeleteTargetAction deleteTargetAction; private DeleteTargetAction deleteTargetAction;
AddTargetAction addTargetAction; AddTargetAction addTargetAction;
TreeViewer viewer; TreeViewer viewer;
@ -90,7 +90,7 @@ public class MakeView extends ViewPart {
buildTargetAction = new BuildTargetAction(viewer.getControl().getShell()); buildTargetAction = new BuildTargetAction(viewer.getControl().getShell());
addTargetAction = new AddTargetAction(viewer.getControl().getShell()); addTargetAction = new AddTargetAction(viewer.getControl().getShell());
deleteTargetAction = new DeleteTargetAction(viewer.getControl().getShell()); deleteTargetAction = new DeleteTargetAction(viewer.getControl().getShell());
renameTargetAction = new RenameTargetAction(viewer.getControl().getShell()); editTargetAction = new EditTargetAction(viewer.getControl().getShell());
} }
private void contributeToActionBars() { private void contributeToActionBars() {
IActionBars bars = getViewSite().getActionBars(); IActionBars bars = getViewSite().getActionBars();
@ -126,7 +126,7 @@ public class MakeView extends ViewPart {
manager.add(buildTargetAction); manager.add(buildTargetAction);
manager.add(addTargetAction); manager.add(addTargetAction);
manager.add(deleteTargetAction); manager.add(deleteTargetAction);
manager.add(renameTargetAction); manager.add(editTargetAction);
manager.add(new Separator()); manager.add(new Separator());
drillDownAdapter.addNavigationActions(manager); drillDownAdapter.addNavigationActions(manager);
@ -150,6 +150,6 @@ public class MakeView extends ViewPart {
void updateActions(IStructuredSelection sel) { void updateActions(IStructuredSelection sel) {
buildTargetAction.selectionChanged(sel); buildTargetAction.selectionChanged(sel);
deleteTargetAction.selectionChanged(sel); deleteTargetAction.selectionChanged(sel);
renameTargetAction.selectionChanged(sel); editTargetAction.selectionChanged(sel);
} }
} }

View file

@ -1,30 +0,0 @@
package org.eclipse.cdt.make.ui.views;
/*
* (c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*/
import org.eclipse.cdt.make.internal.ui.MakeUIImages;
import org.eclipse.core.resources.IResource;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.actions.SelectionListenerAction;
public class RenameTargetAction extends SelectionListenerAction {
Shell shell;
IResource resource;
public RenameTargetAction (Shell shell) {
super("Rename Build Target");
this.shell = shell;
setToolTipText("Rename Build Target");
MakeUIImages.setImageDescriptors(this, "tool16", MakeUIImages.IMG_TOOLS_MAKE_TARGET_RENAME);
}
public void run() {
}
}