From 480a3b86d7e5c004cae638024f337163b7259061 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 2 Feb 2010 14:04:18 +0000 Subject: [PATCH] bug 69922: [Help Wanted] Introduce a "run last make target" key binding Patch from Axel Mueller --- .../org.eclipse.cdt.make.ui/plugin.properties | 6 +- build/org.eclipse.cdt.make.ui/plugin.xml | 59 ++++++++++++- .../make/internal/ui/MakeResources.properties | 9 +- .../ui/preferences/MakePreferencePage.java | 32 ++++++- .../cdt/make/ui/TargetListViewerPart.java | 19 +++-- .../make/ui/actions/AbstractTargetAction.java | 35 ++++++-- .../ui/actions/BuildLastTargetAction.java | 83 +++++++++++++++++++ .../ui/actions/BuildLastTargetHandler.java | 38 +++++++++ .../make/ui/actions/BuildTargetAction.java | 56 ++++++++++++- .../make/ui/dialogs/BuildTargetDialog.java | 6 +- .../cdt/make/ui/dialogs/MakeTargetDialog.java | 18 +++- .../cdt/make/ui/views/BuildTargetAction.java | 16 +++- .../cdt/make/ui/views/DeleteTargetAction.java | 20 ++++- .../eclipse/cdt/make/ui/views/MakeView.java | 12 ++- .../ui/views/RebuildLastTargetAction.java | 40 +++++++++ 15 files changed, 418 insertions(+), 31 deletions(-) create mode 100644 build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/BuildLastTargetAction.java create mode 100644 build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/BuildLastTargetHandler.java create mode 100644 build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/views/RebuildLastTargetAction.java diff --git a/build/org.eclipse.cdt.make.ui/plugin.properties b/build/org.eclipse.cdt.make.ui/plugin.properties index 47e69fcd6a0..a4f95fbf113 100644 --- a/build/org.eclipse.cdt.make.ui/plugin.properties +++ b/build/org.eclipse.cdt.make.ui/plugin.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2003, 2009 QNX Software Systems and others. +# Copyright (c) 2003, 2010 QNX Software Systems and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -25,7 +25,6 @@ WizardConvertMakeProject.description=Convert to a C/C++ Project Make.Target.label=Make Target ActionMakeCreateTarget.label=Create... -ActionMakeBuildTarget.label=Build... ActionMakeUpdate.label=Update Old Make Project... ActionMakeUpdate.tooltip=Update Old Make Project @@ -34,6 +33,8 @@ CommandTargetBuild.name=Make Target Build CommandTargetBuild.description=Invoke a make target build for the selected container. CommandTargetCreate.name=Create Make Target CommandTargetCreate.description=Create a new make build target for the selected container. +LastTargetBuild.name=Rebuild Last Target +LastTargetBuild.description=Rebuild the last make target for the selected container or project. # Build Settings Preference page PreferenceBuildSettings.name=Build Settings @@ -48,7 +49,6 @@ PreferenceMakefileSettings.name= Settings PropertyMakeProject.name= C/C++ Make Project ViewCatagoryMake.name=Make -ViewMake.name=Make Targets ActionSetMake.label=Make Actions ActionSetUpdateMake.label=Update Make Projects diff --git a/build/org.eclipse.cdt.make.ui/plugin.xml b/build/org.eclipse.cdt.make.ui/plugin.xml index e7cd5111b79..922143d68be 100644 --- a/build/org.eclipse.cdt.make.ui/plugin.xml +++ b/build/org.eclipse.cdt.make.ui/plugin.xml @@ -53,6 +53,14 @@ objectClass="org.eclipse.core.resources.IResource" adaptable="true" id="org.eclipse.cdt.make.ui.popupMenu.NavigatorContribution"> + + + + @@ -143,6 +161,13 @@ categoryId="org.eclipse.ui.category.project" id="org.eclipse.cdt.make.ui.targetBuildCommand"> + + - + + + + + + + + + + + + + + + + + + + diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeResources.properties b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeResources.properties index a824528e250..14f1d8f3b58 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeResources.properties +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeResources.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2003, 2009 QNX Software Systems and others. +# Copyright (c) 2003, 2010 QNX Software Systems and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -184,6 +184,10 @@ DeleteTargetAction.exception.errorDeletingBuildTarget=Error deleting Make target BuildTargetAction.label=Build &Target BuildTargetAction.tooltip=Build Make Target +BuildLastTargetAction.label=Rebuild &Last Target +BuildLastTargetAction.tooltip=Rebuild the last make target for the selected container or project. + +ActionMakeBuildTarget.label=Build... EditTargetAction.label=&Edit... EditTargetAction.tooltip=Edit Make Target @@ -213,6 +217,9 @@ MakeUIPlugin.update_project_message=Older \'make\' projects have been detected i # Prefernece Page MakePreferencePage.description=Specify the settings used as defaults by the New Standard Make Project creation wizard. MakeTargetPreferencePage.buildTargetInBackground.label=Build Make target in the background. +MakeTargetPreferencePage.buildLastTarget.title=Rebuild Last Target +MakeTargetPreferencePage.buildLastTarget.resource=From selected &folder +MakeTargetPreferencePage.buildLastTarget.project=From &project root #Property Page MakeProjectPropertyPage.closedproject=Project Closed diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/MakePreferencePage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/MakePreferencePage.java index ea11baaae62..e99a50e292e 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/MakePreferencePage.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/preferences/MakePreferencePage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Axel Mueller - Rebuild last target *******************************************************************************/ package org.eclipse.cdt.make.internal.ui.preferences; @@ -14,6 +15,7 @@ import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; import org.eclipse.jface.preference.BooleanFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.RadioGroupFieldEditor; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; @@ -22,6 +24,13 @@ public class MakePreferencePage extends FieldEditorPreferencePage implements IWo private static final String PREF_BUILD_TARGET_IN_BACKGROUND = "MakeTargetPrefs.buildTargetInBackground"; //$NON-NLS-1$ private static final String TARGET_BUILDS_IN_BACKGROUND = "MakeTargetPreferencePage.buildTargetInBackground.label"; //$NON-NLS-1$ + + private static final String PREF_BUILD_LAST_TARGET = "MakeTargetPrefs.buildLastTarget"; //$NON-NLS-1$ + private static final String BUILD_LAST_TARGET = "MakeTargetPreferencePage.buildLastTarget.title"; //$NON-NLS-1$ + private static final String PREF_BUILD_LAST_RESOURCE = "MakeTargetPrefs.buildLastTarget.resource"; //$NON-NLS-1$ + private static final String BUILD_LAST_RESOURCE = "MakeTargetPreferencePage.buildLastTarget.resource"; //$NON-NLS-1$ + private static final String PREF_BUILD_LAST_PROJECT = "MakeTargetPrefs.buildLastTarget.project"; //$NON-NLS-1$ + private static final String BUILD_LAST_PROJECT = "MakeTargetPreferencePage.buildLastTarget.project"; //$NON-NLS-1$ public MakePreferencePage() { super(GRID); @@ -31,12 +40,24 @@ public class MakePreferencePage extends FieldEditorPreferencePage implements IWo /** * @see FieldEditorPreferencePage#createControl(Composite) */ + @Override protected void createFieldEditors() { Composite parent = getFieldEditorParent(); BooleanFieldEditor tagetBackgroundEditor = new BooleanFieldEditor(PREF_BUILD_TARGET_IN_BACKGROUND, MakeUIPlugin.getResourceString(TARGET_BUILDS_IN_BACKGROUND), parent); addField(tagetBackgroundEditor); + + // make last target for selected resource or project + RadioGroupFieldEditor edit = new RadioGroupFieldEditor( + PREF_BUILD_LAST_TARGET, + MakeUIPlugin.getResourceString(BUILD_LAST_TARGET), 1, + new String[][] { + {MakeUIPlugin.getResourceString(BUILD_LAST_RESOURCE), PREF_BUILD_LAST_RESOURCE}, + {MakeUIPlugin.getResourceString(BUILD_LAST_PROJECT), PREF_BUILD_LAST_PROJECT} }, + parent, + true); + addField(edit); } public static boolean isBuildTargetInBackground() { @@ -47,11 +68,20 @@ public class MakePreferencePage extends FieldEditorPreferencePage implements IWo MakeUIPlugin.getDefault().getPreferenceStore().setValue(PREF_BUILD_TARGET_IN_BACKGROUND, enable); } + /** + * preference to rebuild last target + * + * @return {@code true} if from selected project else from selected resource + */ + public static boolean useProjectForLastMakeTarget() { + return MakeUIPlugin.getDefault().getPreferenceStore().getString(PREF_BUILD_LAST_TARGET).equals(PREF_BUILD_LAST_PROJECT); + } /** * Initializes the default values of this page in the preference bundle. */ public static void initDefaults(IPreferenceStore prefs) { prefs.setDefault(PREF_BUILD_TARGET_IN_BACKGROUND, true); + prefs.setDefault(PREF_BUILD_LAST_TARGET, PREF_BUILD_LAST_RESOURCE); } public void init(IWorkbench workbench) { diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/TargetListViewerPart.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/TargetListViewerPart.java index 4a4c89d5ae7..872ad62f8ac 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/TargetListViewerPart.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/TargetListViewerPart.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 QNX Software Systems and others. + * Copyright (c) 2000, 2010 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -42,14 +42,19 @@ public class TargetListViewerPart extends StructuredViewerPart { private final int REMOVE_TARGET = 1; private final int EDIT_TARGET = 2; private IContainer fContainer; - - public TargetListViewerPart(IContainer container) { + private boolean recursive; + + /** + * @param container + * @param recursive {@code true} if to search recursively for target + */ + public TargetListViewerPart(IContainer container, boolean recursive) { super(new String[] { MakeUIPlugin.getResourceString("TargetListViewer.button.add"), //$NON-NLS-1$ - MakeUIPlugin - .getResourceString("TargetListViewer.button.remove"), //$NON-NLS-1$ + MakeUIPlugin.getResourceString("TargetListViewer.button.remove"), //$NON-NLS-1$ MakeUIPlugin.getResourceString("TargetListViewer.button.edit")}); //$NON-NLS-1$ - fContainer = container; + this.fContainer = container; + this.recursive = recursive; } @Override @@ -79,7 +84,7 @@ public class TargetListViewerPart extends StructuredViewerPart { .getSelection()); } }); - tableViewer.setContentProvider(new MakeContentProvider(true)); + tableViewer.setContentProvider(new MakeContentProvider(recursive)); tableViewer.addFilter(new ViewerFilter() { @Override diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/AbstractTargetAction.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/AbstractTargetAction.java index d2f4e5f5515..97c3be4cee8 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/AbstractTargetAction.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/AbstractTargetAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 QNX Software Systems and others. + * Copyright (c) 2000, 2010 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,17 +7,21 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Axel Mueller - Rebuild last target *******************************************************************************/ package org.eclipse.cdt.make.ui.actions; 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.make.core.IMakeTarget; import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.widgets.Shell; @@ -26,13 +30,16 @@ import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.actions.ActionDelegate; +import org.eclipse.ui.editors.text.TextEditor; +import org.eclipse.ui.part.EditorPart; public abstract class AbstractTargetAction extends ActionDelegate implements IObjectActionDelegate, IWorkbenchWindowActionDelegate { private IWorkbenchPart fPart; private IWorkbenchWindow fWindow; - private IContainer fContainer; + private boolean isEnabled; + protected IContainer fContainer; protected Shell getShell() { if (fPart != null) { @@ -55,8 +62,9 @@ public abstract class AbstractTargetAction fWindow = window; } + @Override public void selectionChanged(IAction action, ISelection selection) { - boolean enabled = false; + isEnabled = false; if (selection instanceof IStructuredSelection) { IStructuredSelection sel = (IStructuredSelection) selection; Object obj = sel.getFirstElement(); @@ -75,14 +83,29 @@ public abstract class AbstractTargetAction } else { fContainer = ((IResource)obj).getParent(); } + } else if (obj instanceof IMakeTarget) { + fContainer = ((IMakeTarget)obj).getContainer(); } else { fContainer = null; } - if (fContainer != null && MakeCorePlugin.getDefault().getTargetManager().hasTargetBuilder(fContainer.getProject())) { - enabled = true; + } else if (selection instanceof ITextSelection) + { // key binding pressed inside active text editor + IWorkbenchPart part = fPart != null ? fPart : fWindow.getActivePage().getActivePart(); + if ( part instanceof TextEditor ) { + IFile file = org.eclipse.ui.ide.ResourceUtil.getFile(((EditorPart) part).getEditorInput()); + fContainer = file.getParent(); + } else { + fContainer = null; } } - action.setEnabled(enabled); + if (fContainer != null && MakeCorePlugin.getDefault().getTargetManager().hasTargetBuilder(fContainer.getProject())) { + isEnabled = true; + } + if ( action != null ) + action.setEnabled(isEnabled); } + public boolean isEnabled() { + return isEnabled; + } } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/BuildLastTargetAction.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/BuildLastTargetAction.java new file mode 100644 index 00000000000..8843ca3519e --- /dev/null +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/BuildLastTargetAction.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2010 Axel Mueller and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Axel Mueller - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.make.ui.actions; + +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.TargetBuild; +import org.eclipse.cdt.make.ui.dialogs.BuildTargetDialog; +import org.eclipse.cdt.make.internal.ui.preferences.MakePreferencePage; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.window.Window; + +/** + * Rebuild last target of selected resource or project. + * Search is done non-recursively. + * If no valid last target is found, show the build target dialog. + */ +public class BuildLastTargetAction extends AbstractTargetAction { + + @Override + public void run(IAction action) { + IContainer container = getSelectedContainer(); + if (container != null) { + String name = null; + if (MakePreferencePage.useProjectForLastMakeTarget()) { + container = container.getProject(); + } + try { + name = (String)container.getSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(), "lastTarget")); //$NON-NLS-1$ + } catch (CoreException e) { + } + try { + boolean showDialog = true; + if (name != null) { + IPath path = new Path(name); + if (path.segmentCount() <= 1) {// do not look recursively for last target + IMakeTarget target = MakeCorePlugin.getDefault().getTargetManager().findTarget(container, name); + if (target != null) { + TargetBuild.buildTargets(getShell(), new IMakeTarget[] { target }); + showDialog = false; + } + } + } + + // no last target found, let the user decide + if (showDialog) { + BuildTargetDialog dialog = new BuildTargetDialog(getShell(), container, false/*Recursive*/); + if (dialog.open() == Window.OK) { + IMakeTarget target = dialog.getTarget(); + if (target != null) { + IPath path = + target.getContainer().getProjectRelativePath().removeFirstSegments( + container.getProjectRelativePath().segmentCount()); + path = path.append(target.getName()); + container.setSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(), "lastTarget"), //$NON-NLS-1$ + path.toString()); + } + } + } + } catch (CoreException e) { + } + } + } + + @Override + public boolean isEnabled() { + return super.isEnabled(); + } +} diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/BuildLastTargetHandler.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/BuildLastTargetHandler.java new file mode 100644 index 00000000000..0a556d4ab9d --- /dev/null +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/BuildLastTargetHandler.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2010 Axel Mueller and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Axel Mueller - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.make.ui.actions; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * Handler for {@link org.eclipse.cdt.make.ui.actions.BuildLastTargetAction} + */ +public class BuildLastTargetHandler extends AbstractHandler { + + public Object execute(ExecutionEvent event) throws ExecutionException { + final BuildLastTargetAction buildAction= new BuildLastTargetAction(); + ISelection selection = HandlerUtil.getCurrentSelection( event ); + IWorkbenchPart part = HandlerUtil.getActivePart( event ); + buildAction.setActivePart(null, part); + buildAction.selectionChanged(null, selection); + + if (buildAction.isEnabled()) { + buildAction.run(null); + } + return null; + } + +} diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/BuildTargetAction.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/BuildTargetAction.java index 182e071feca..4a1be37768e 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/BuildTargetAction.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/BuildTargetAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 QNX Software Systems and others. + * Copyright (c) 2000, 2010 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Axel Mueller - Rebuild last target *******************************************************************************/ package org.eclipse.cdt.make.ui.actions; @@ -20,14 +21,40 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.QualifiedName; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.bindings.BindingManagerEvent; +import org.eclipse.jface.bindings.IBindingManagerListener; import org.eclipse.jface.window.Window; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.keys.IBindingService; public class BuildTargetAction extends AbstractTargetAction { - + + private static final String TARGET_BUILD_COMMAND = "org.eclipse.cdt.make.ui.targetBuildCommand"; //$NON-NLS-1$ + private IBindingService bindingService; + private IAction InitAction; + + public BuildTargetAction(){ + bindingService = null; + InitAction = null; + } + + @Override + public void init(IAction action) { + bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class); + if (bindingService != null) { + bindingService.addBindingManagerListener(bindingManagerListener); + String keyBinding = bindingService.getBestActiveBindingFormattedFor(TARGET_BUILD_COMMAND); + if (keyBinding != null) + action.setText(MakeUIPlugin.getResourceString("ActionMakeBuildTarget.label")+"\t"+ keyBinding); //$NON-NLS-1$ //$NON-NLS-2$ + } + InitAction = action; + } + + @Override public void run(IAction action) { IContainer container = getSelectedContainer(); if (container != null) { - BuildTargetDialog dialog = new BuildTargetDialog(getShell(), container); + BuildTargetDialog dialog = new BuildTargetDialog(getShell(), container, true); String name = null; try { name = (String)container.getSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(), "lastTarget")); //$NON-NLS-1$ @@ -63,5 +90,28 @@ public class BuildTargetAction extends AbstractTargetAction { } } } + + @Override + public void dispose() { + if (bindingService != null) { + bindingService.removeBindingManagerListener(bindingManagerListener); + bindingService = null; + } + + super.dispose(); + } + + private IBindingManagerListener bindingManagerListener = new IBindingManagerListener() { + + public void bindingManagerChanged(BindingManagerEvent event) { + + if (event.isActiveBindingsChanged()) { + String keyBinding = bindingService.getBestActiveBindingFormattedFor(TARGET_BUILD_COMMAND); + if (keyBinding != null) InitAction.setText( + MakeUIPlugin.getResourceString("ActionMakeBuildTarget.label")+"\t"+ keyBinding); //$NON-NLS-1$ //$NON-NLS-2$ + + } + } + }; } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/BuildTargetDialog.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/BuildTargetDialog.java index 8d6cf88e656..8045d53413f 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/BuildTargetDialog.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/BuildTargetDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 QNX Software Systems and others. + * Copyright (c) 2000, 2010 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -34,11 +34,11 @@ public class BuildTargetDialog extends Dialog { private final TargetListViewerPart targetPart; private final IContainer fContainer; - public BuildTargetDialog(Shell parent, IContainer container) { + public BuildTargetDialog(Shell parent, IContainer container, boolean recursive) { super(parent); setShellStyle(getShellStyle() | SWT.RESIZE); fContainer = container; - targetPart = new TargetListViewerPart(fContainer); + targetPart = new TargetListViewerPart(fContainer, recursive); } public void setTarget(IMakeTarget target) { diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/MakeTargetDialog.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/MakeTargetDialog.java index 37b80ad0067..2e75bf3ed0e 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/MakeTargetDialog.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/MakeTargetDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 QNX Software Systems and others. + * Copyright (c) 2000, 2010 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -22,6 +22,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; @@ -476,6 +477,21 @@ public class MakeTargetDialog extends Dialog { target = fTargetManager.createTarget(fContainer.getProject(), targetName, targetBuildID); } else { if (!target.getName().equals(targetName)) { + // if necessary rename last target property, too + String lastTargetName = null; + IContainer container = target.getContainer(); + try { + lastTargetName = (String)container.getSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(), "lastTarget")); //$NON-NLS-1$ + } catch (CoreException e) { + } + if (lastTargetName != null && lastTargetName.equals(target.getName())) { + IPath path = container.getProjectRelativePath().removeFirstSegments( + container.getProjectRelativePath().segmentCount()); + path = path.append(targetName); + container.setSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(), "lastTarget"), //$NON-NLS-1$ + path.toString()); + } + fTargetManager.renameTarget(target, targetName); } } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/views/BuildTargetAction.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/views/BuildTargetAction.java index 55f8eeb85ce..9904c548790 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/views/BuildTargetAction.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/views/BuildTargetAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 QNX Software Systems and others. + * Copyright (c) 2000, 2010 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -17,6 +17,10 @@ import org.eclipse.cdt.make.core.IMakeTarget; import org.eclipse.cdt.make.internal.ui.MakeUIImages; import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; import org.eclipse.cdt.make.ui.TargetBuild; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.QualifiedName; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.actions.SelectionListenerAction; @@ -38,6 +42,16 @@ public class BuildTargetAction extends SelectionListenerAction { if (canBuild()) { IMakeTarget[] targets = getSelectedElements().toArray(new IMakeTarget[0]); TargetBuild.buildTargets(shell, targets); + // set last target property for last element + IContainer container = targets[targets.length-1].getContainer(); + IPath path = container.getProjectRelativePath().removeFirstSegments( + container.getProjectRelativePath().segmentCount()); + path = path.append(targets[targets.length-1].getName()); + try { + container.setSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(),"lastTarget"), //$NON-NLS-1$ + path.toString()); + } catch (CoreException e) { + } } } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/views/DeleteTargetAction.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/views/DeleteTargetAction.java index 68fcc98ec8c..c72688b7235 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/views/DeleteTargetAction.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/views/DeleteTargetAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 QNX Software Systems and others. + * Copyright (c) 2000, 2010 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -17,7 +17,9 @@ import org.eclipse.cdt.make.core.IMakeTarget; import org.eclipse.cdt.make.core.IMakeTargetManager; import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; +import org.eclipse.core.resources.IContainer; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.QualifiedName; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.widgets.Shell; @@ -73,7 +75,21 @@ public class DeleteTargetAction extends SelectionListenerAction { try { for (Object target : getSelectedElements()) { if (target instanceof IMakeTarget) { - manager.removeTarget((IMakeTarget) target); + manager.removeTarget((IMakeTarget) target); + // if necessary remove last target property + String lastTargetName = null; + IContainer container = ((IMakeTarget) target).getContainer(); + try { + lastTargetName = (String)container.getSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(), "lastTarget")); //$NON-NLS-1$ + } catch (CoreException e) { + } + if (lastTargetName != null && lastTargetName.equals(((IMakeTarget) target).getName())) { + try { + container.setSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(), + "lastTarget"), null); //$NON-NLS-1$ + } catch (CoreException e) { + } + } } } } catch (CoreException e) { diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/views/MakeView.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/views/MakeView.java index 1445d3b2479..b148d57b7f0 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/views/MakeView.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/views/MakeView.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 QNX Software Systems and others. + * Copyright (c) 2000, 2010 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -77,9 +77,12 @@ import org.eclipse.ui.part.ViewPart; public class MakeView extends ViewPart { + private static final String TARGET_BUILD_LAST_COMMAND = "org.eclipse.cdt.make.ui.targetBuildLastCommand"; //$NON-NLS-1$ + private Clipboard clipboard; private BuildTargetAction buildTargetAction; + private RebuildLastTargetAction buildLastTargetAction; private EditTargetAction editTargetAction; private DeleteTargetAction deleteTargetAction; private AddTargetAction newTargetAction; @@ -287,6 +290,7 @@ public class MakeView extends ViewPart { clipboard = new Clipboard(shell.getDisplay()); buildTargetAction = new BuildTargetAction(shell); + buildLastTargetAction = new RebuildLastTargetAction(); newTargetAction = new AddTargetAction(shell); copyTargetAction = new CopyTargetAction(shell, clipboard, pasteTargetAction); pasteTargetAction = new PasteTargetAction(shell, clipboard); @@ -345,6 +349,7 @@ public class MakeView extends ViewPart { manager.add(deleteTargetAction); manager.add(new Separator()); manager.add(buildTargetAction); + manager.add(buildLastTargetAction); // Other plug-ins can contribute there actions here // manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); @@ -362,6 +367,7 @@ public class MakeView extends ViewPart { void updateActions(IStructuredSelection sel) { newTargetAction.selectionChanged(sel); buildTargetAction.selectionChanged(sel); + buildLastTargetAction.selectionChanged(sel); deleteTargetAction.selectionChanged(sel); editTargetAction.selectionChanged(sel); copyTargetAction.selectionChanged(sel); @@ -406,6 +412,10 @@ public class MakeView extends ViewPart { keyBinding = bindingService.getBestActiveBindingFormattedFor(IWorkbenchCommandConstants.EDIT_DELETE); if (keyBinding != null) deleteTargetAction.setText( MakeUIPlugin.getResourceString("DeleteTargetAction.label")+"\t"+ keyBinding); //$NON-NLS-1$ //$NON-NLS-2$ + + keyBinding = bindingService.getBestActiveBindingFormattedFor(TARGET_BUILD_LAST_COMMAND); + if (keyBinding != null) buildLastTargetAction.setText( + MakeUIPlugin.getResourceString("BuildLastTargetAction.label")+"\t"+ keyBinding); //$NON-NLS-1$ //$NON-NLS-2$ } } }; diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/views/RebuildLastTargetAction.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/views/RebuildLastTargetAction.java new file mode 100644 index 00000000000..f702f24b51b --- /dev/null +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/views/RebuildLastTargetAction.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2010 Axel Mueller and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Axel Mueller - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.make.ui.views; + + + +import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; +import org.eclipse.cdt.make.ui.actions.BuildLastTargetAction; +import org.eclipse.ui.actions.SelectionListenerAction; + +/** + * Rebuild last target of selected resource or project. + */ +public class RebuildLastTargetAction extends SelectionListenerAction { + + public RebuildLastTargetAction() { + super(MakeUIPlugin.getResourceString("BuildLastTargetAction.label")); //$NON-NLS-1$ + + setToolTipText(MakeUIPlugin.getResourceString("BuildLastTargetAction.tooltip")); //$NON-NLS-1$ + setEnabled(false); + } + + @Override + public void run() { + final BuildLastTargetAction buildAction= new BuildLastTargetAction(); + buildAction.selectionChanged(null, this.getStructuredSelection()); + + if (buildAction.isEnabled()) { + buildAction.run(null); + } + } +}