1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 17:35:35 +02:00

bug 333113: Rebuild last target: option to use build location of active build configuration

Patch from Axel Mueller
This commit is contained in:
Andrew Gvozdev 2011-02-14 17:53:43 +00:00
parent 60080b30c7
commit 289d4bbf35
10 changed files with 148 additions and 59 deletions

View file

@ -113,6 +113,7 @@
point="org.eclipse.ui.commands">
<command
name="%CommandTargetBuild.name"
defaultHandler="org.eclipse.cdt.make.ui.actions.BuildTargetHandler"
description="%CommandTargetBuild.description"
categoryId="org.eclipse.ui.category.project"
id="org.eclipse.cdt.make.ui.targetBuildCommand">
@ -303,7 +304,6 @@
</groupMarker>
</menu>
<action
definitionId="org.eclipse.cdt.make.ui.targetBuildLastCommand"
label="%LastTargetBuild.name"
class="org.eclipse.cdt.make.ui.actions.BuildLastTargetAction"
menubarPath="project/org.eclipse.cdt.make.ui.prjmenu/gm1"
@ -330,7 +330,6 @@
</enablement>
</action>
<action
definitionId="org.eclipse.cdt.make.ui.targetBuildCommand"
label="%ActionMakeBuildTarget.label"
class="org.eclipse.cdt.make.ui.actions.BuildTargetAction"
menubarPath="project/org.eclipse.cdt.make.ui.prjmenu/gm1"

View file

@ -218,8 +218,9 @@ MakeUIPlugin.update_project_message=Older \'make\' projects have been detected i
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.project=From selected &project
MakeTargetPreferencePage.buildLastTarget.resource=From selected &folder
MakeTargetPreferencePage.buildLastTarget.project=From &project root
MakeTargetPreferencePage.buildLastTarget.projectRoot=From project &root
#Property Page
MakeProjectPropertyPage.closedproject=Project Closed

View file

@ -29,10 +29,12 @@ public class MakePreferencePage extends FieldEditorPreferencePage implements IWo
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$
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_PROJECTROOT = "MakeTargetPrefs.buildLastTarget.projectRoot"; //$NON-NLS-1$
private static final String BUILD_LAST_PROJECTROOT = "MakeTargetPreferencePage.buildLastTarget.projectRoot"; //$NON-NLS-1$
public MakePreferencePage() {
super(GRID);
@ -61,8 +63,9 @@ public class MakePreferencePage extends FieldEditorPreferencePage implements IWo
PREF_BUILD_LAST_TARGET,
MakeUIPlugin.getResourceString(BUILD_LAST_TARGET), 1,
new String[][] {
{MakeUIPlugin.getResourceString(BUILD_LAST_PROJECT), PREF_BUILD_LAST_PROJECT},
{MakeUIPlugin.getResourceString(BUILD_LAST_RESOURCE), PREF_BUILD_LAST_RESOURCE},
{MakeUIPlugin.getResourceString(BUILD_LAST_PROJECT), PREF_BUILD_LAST_PROJECT} },
{MakeUIPlugin.getResourceString(BUILD_LAST_PROJECTROOT), PREF_BUILD_LAST_PROJECTROOT} },
parent,
true);
addField(edit);
@ -79,9 +82,18 @@ public class MakePreferencePage extends FieldEditorPreferencePage implements IWo
/**
* preference to rebuild last target
*
* @return {@code true} if from selected project else from selected resource
* @return {@code true} if from root folder of selected project
*/
public static boolean useProjectForLastMakeTarget() {
public static boolean useProjectRootForLastMakeTarget() {
return MakeUIPlugin.getDefault().getPreferenceStore().getString(PREF_BUILD_LAST_TARGET).equals(PREF_BUILD_LAST_PROJECTROOT);
}
/**
* preference to rebuild last target
*
* @return {@code true} if from selected project irrespective in which container
*/
public static boolean useProjectLastMakeTarget() {
return MakeUIPlugin.getDefault().getPreferenceStore().getString(PREF_BUILD_LAST_TARGET).equals(PREF_BUILD_LAST_PROJECT);
}
/**
@ -89,7 +101,7 @@ public class MakePreferencePage extends FieldEditorPreferencePage implements IWo
*/
public static void initDefaults(IPreferenceStore prefs) {
prefs.setDefault(PREF_BUILD_TARGET_IN_BACKGROUND, true);
prefs.setDefault(PREF_BUILD_LAST_TARGET, PREF_BUILD_LAST_RESOURCE);
prefs.setDefault(PREF_BUILD_LAST_TARGET, PREF_BUILD_LAST_PROJECT);
}
public void init(IWorkbench workbench) {

View file

@ -45,7 +45,10 @@ import org.eclipse.ui.progress.IProgressService;
* @noinstantiate This class is not intended to be instantiated by clients.
*/
public class TargetBuild {
/** @since 7.1 */
public static final String LAST_TARGET = "lastTarget"; //$NON-NLS-1$
/** @since 7.1 */
public static final String LAST_TARGET_CONTAINER = "lastTargetContainer"; //$NON-NLS-1$
/**
* Causes all editors to save any modified resources depending on the user's preference.
*/

View file

@ -41,23 +41,45 @@ public class BuildLastTargetAction extends AbstractTargetAction {
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) {
if (MakePreferencePage.useProjectLastMakeTarget()) {
try {
name = (String) container.getProject().getSessionProperty(
new QualifiedName(MakeUIPlugin.getUniqueIdentifier(),
TargetBuild.LAST_TARGET_CONTAINER));
if (name != null) {
IContainer lastTargetContainer;
if ( name.isEmpty() )
lastTargetContainer = container.getProject();
else
lastTargetContainer = container.getProject().getFolder(new Path(name));
if ( lastTargetContainer.exists() )
container = lastTargetContainer;
name = (String) container.getSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(),
TargetBuild.LAST_TARGET));
}
} catch (CoreException e) {
}
} else {
if (MakePreferencePage.useProjectRootForLastMakeTarget()) {
container = container.getProject();
}
try {
name = (String) container.getSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(),
TargetBuild.LAST_TARGET));
} 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;
}
IMakeTarget target = MakeCorePlugin.getDefault().getTargetManager().findTarget(container, name);
if (target != null) {
TargetBuild.buildTargets(getShell(), new IMakeTarget[] { target });
showDialog = false;
IPath path = container.getProjectRelativePath();
container.getProject().setSessionProperty(
new QualifiedName(MakeUIPlugin.getUniqueIdentifier(),
TargetBuild.LAST_TARGET_CONTAINER), path.toString());
}
}
@ -67,12 +89,13 @@ public class BuildLastTargetAction extends AbstractTargetAction {
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());
container.setSessionProperty(new QualifiedName(
MakeUIPlugin.getUniqueIdentifier(), TargetBuild.LAST_TARGET),
target.getName());
IPath path = target.getContainer().getProjectRelativePath();
container.getProject().setSessionProperty(
new QualifiedName(MakeUIPlugin.getUniqueIdentifier(),
TargetBuild.LAST_TARGET_CONTAINER), path.toString());
}
}
}

View file

@ -14,6 +14,7 @@ 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.core.resources.IContainer;
import org.eclipse.core.runtime.CoreException;
@ -61,33 +62,25 @@ public class BuildTargetAction extends AbstractTargetAction {
BuildTargetDialog dialog = new BuildTargetDialog(getShell(), container, true);
String name = null;
try {
name = (String)container.getSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(), "lastTarget")); //$NON-NLS-1$
name = (String) container.getSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(),
TargetBuild.LAST_TARGET));
} catch (CoreException e) {
}
try {
if (name != null) {
IPath path = new Path(name);
name = path.segment(path.segmentCount() - 1);
IContainer targetContainer;
if (path.segmentCount() > 1) {
path = path.removeLastSegments(1);
targetContainer = (IContainer)container.findMember(path);
} else {
targetContainer = container;
}
IMakeTarget target = MakeCorePlugin.getDefault().getTargetManager().findTarget(targetContainer, name);
IMakeTarget target = MakeCorePlugin.getDefault().getTargetManager().findTarget(container, name);
if (target != null)
dialog.setTarget(target);
}
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());
container.setSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(),
TargetBuild.LAST_TARGET), target.getName());
IPath path = target.getContainer().getProjectRelativePath();
container.getProject().setSessionProperty(
new QualifiedName(MakeUIPlugin.getUniqueIdentifier(),
TargetBuild.LAST_TARGET_CONTAINER), path.toString());
}
}
} catch (CoreException e) {

View file

@ -0,0 +1,43 @@
/*******************************************************************************
* Copyright (c) 2011 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.BuildTargetAction}
*
* @since 7.1
*
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
*/
public class BuildTargetHandler extends AbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
final BuildTargetAction buildAction= new BuildTargetAction();
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;
}
}

View file

@ -18,6 +18,7 @@ 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.cdt.make.internal.ui.MessageLine;
import org.eclipse.cdt.make.ui.TargetBuild;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.CoreException;
@ -493,15 +494,17 @@ public class MakeTargetDialog extends Dialog {
String lastTargetName = null;
IContainer container = target.getContainer();
try {
lastTargetName = (String)container.getSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(), "lastTarget")); //$NON-NLS-1$
lastTargetName = (String) container.getSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(),
TargetBuild.LAST_TARGET));
} 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());
container.setSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(),
TargetBuild.LAST_TARGET), targetName);
IPath path = target.getContainer().getProjectRelativePath();
container.getProject().setSessionProperty(
new QualifiedName(MakeUIPlugin.getUniqueIdentifier(),
TargetBuild.LAST_TARGET_CONTAINER), path.toString());
}
fTargetManager.renameTarget(target, targetName);

View file

@ -48,12 +48,17 @@ public class BuildTargetAction extends SelectionListenerAction {
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());
container.setSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(),
TargetBuild.LAST_TARGET), targets[targets.length - 1].getName());
} catch (CoreException e) {
}
// store container of last target, too
try {
IPath path = container.getProjectRelativePath();
container.getProject().setSessionProperty(
new QualifiedName(MakeUIPlugin.getUniqueIdentifier(),
TargetBuild.LAST_TARGET_CONTAINER), path.toString());
} catch (CoreException e) {
}
}

View file

@ -17,6 +17,7 @@ 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.cdt.make.ui.TargetBuild;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.QualifiedName;
@ -84,13 +85,19 @@ public class DeleteTargetAction extends SelectionListenerAction {
String lastTargetName = null;
IContainer container = ((IMakeTarget) target).getContainer();
try {
lastTargetName = (String)container.getSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(), "lastTarget")); //$NON-NLS-1$
lastTargetName = (String) container.getSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(),
TargetBuild.LAST_TARGET));
} catch (CoreException e) {
}
if (lastTargetName != null && lastTargetName.equals(((IMakeTarget) target).getName())) {
try {
container.setSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(),
"lastTarget"), null); //$NON-NLS-1$
TargetBuild.LAST_TARGET), null);
} catch (CoreException e) {
}
try {
container.getProject().setSessionProperty(new QualifiedName(MakeUIPlugin.getUniqueIdentifier(),
TargetBuild.LAST_TARGET_CONTAINER), null);
} catch (CoreException e) {
}
}