1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

fixes for 139667 and 139797

This commit is contained in:
Chris Recoskie 2006-05-03 10:50:06 +00:00
parent f8bfa05b18
commit 033966ab4c
4 changed files with 151 additions and 74 deletions

View file

@ -38,8 +38,8 @@ BuildConfigContextAction.label=Active Bui&ld Configuration
BuildConfigAction.tooltip=Change active build configuration for the current project
# Build/clean selected files actions
BuildSelectedFiles.label=Build F&ile(s)
CleanSelectedFiles.label=Cl&ean File(s)
BuildSelectedFiles.label=Build Selected &File(s)
CleanSelectedFiles.label=C&lean Selected File(s)
BuildSelectedFilesActionSet.label=Build/Clean Selected File(s)
BuildSelectedFiles.tooltip=Rebuilds the selected file(s) including all dependencies
BuildSelectedFiles.tooltip=Rebuilds the selected file(s)
CleanSelectedFiles.tooltip=Cleans the output file(s) for the selected file(s)

View file

@ -158,7 +158,8 @@
label="%BuildSelectedFiles.label"
menubarPath="project/build"
style="push"
tooltip="%buildSelectedFiles.tooltip"/>
tooltip="%buildSelectedFiles.tooltip">
</action>
<action
class="org.eclipse.cdt.managedbuilder.ui.actions.CleanFilesAction"
enablesFor="+"
@ -166,7 +167,8 @@
label="%CleanSelectedFiles.label"
menubarPath="project/build"
style="push"
tooltip="%cleanFilesAction.tooltip"/>
tooltip="%cleanFilesAction.tooltip">
</action>
</actionSet>
</extension>
<extension
@ -188,9 +190,9 @@
value="org.eclipse.cdt.managedbuilder.core.managedBuildNature"/>
</objectContribution>
<objectContribution
adaptable="false"
adaptable="true"
id="org.eclipse.cdt.managedbuilder.ui.objectContribution1"
objectClass="org.eclipse.cdt.core.model.ITranslationUnit">
objectClass="org.eclipse.core.resources.IResource">
<action
class="org.eclipse.cdt.managedbuilder.ui.actions.BuildFilesAction"
enablesFor="+"

View file

@ -15,6 +15,7 @@ import java.util.LinkedList;
import java.util.List;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.Action;
@ -28,27 +29,32 @@ import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.internal.core.GeneratedMakefileBuilder;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedMakeMessages;
import org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.actions.ActionDelegate;
/**
* @author crecoskie
*
*/
public class BuildFilesAction extends Action implements IWorkbenchWindowActionDelegate {
public class BuildFilesAction extends ActionDelegate implements IWorkbenchWindowActionDelegate {
/**
* The workbench window; or <code>null</code> if this action has been
* <code>dispose</code>d.
*/
private IWorkbenchWindow workbenchWindow;
private IWorkbenchWindow workbenchWindow = null;
private IAction action = null;
/**
*
*/
@ -60,39 +66,10 @@ public class BuildFilesAction extends Action implements IWorkbenchWindowActionDe
* Creates an instance of this action, for use in the given window.
*/
public BuildFilesAction(IWorkbenchWindow window) {
super(ManagedMakeMessages.getResourceString("BuildFilesAction.buildFiles")); //$NON-NLS-1$
if (window == null) {
throw new IllegalArgumentException();
}
this.workbenchWindow = window;
setToolTipText(ManagedMakeMessages.getResourceString("BuildFilesAction.buildSelectedFile")); //$NON-NLS-1$
setActionDefinitionId("org.eclipse.cdt.managedbuilder.ui.BuildFilesAction"); //$NON-NLS-1$
}
/**
* @param text
*/
public BuildFilesAction(String text) {
super(text);
// TODO Auto-generated constructor stub
}
/**
* @param text
* @param image
*/
public BuildFilesAction(String text, ImageDescriptor image) {
super(text, image);
// TODO Auto-generated constructor stub
}
/**
* @param text
* @param style
*/
public BuildFilesAction(String text, int style) {
super(text, style);
// TODO Auto-generated constructor stub
}
/*
@ -105,6 +82,15 @@ public class BuildFilesAction extends Action implements IWorkbenchWindowActionDe
}
/* (non-Javadoc)
* @see org.eclipse.ui.actions.ActionDelegate#init(org.eclipse.jface.action.IAction)
*/
public void init(IAction action) {
this.action = action;
update();
}
/*
* (non-Javadoc)
*
@ -182,7 +168,7 @@ public class BuildFilesAction extends Action implements IWorkbenchWindowActionDe
IManagedBuildInfo buildInfo = ManagedBuildManager
.getBuildInfo(file.getProject());
if (buildInfo.buildsFileType(file.getFileExtension())) {
if (buildInfo != null && buildInfo.buildsFileType(file.getFileExtension())) {
files.add(file);
}
}
@ -260,6 +246,7 @@ public class BuildFilesAction extends Action implements IWorkbenchWindowActionDe
}
/*
* (non-Javadoc)
*
@ -275,6 +262,65 @@ public class BuildFilesAction extends Action implements IWorkbenchWindowActionDe
}
private boolean shouldBeEnabled() {
ISelectionService selectionService = workbenchWindow
.getSelectionService();
ISelection selection = selectionService.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
for (Iterator elements = structuredSelection.iterator(); elements
.hasNext();) {
IFile file = convertToIFile(elements.next());
if (file != null) {
// we only add files that we can actually build
if(!ManagedBuildManager.manages(file.getProject()))
{
return false;
}
IManagedBuildInfo buildInfo = ManagedBuildManager
.getBuildInfo(file.getProject());
if(buildInfo == null)
return false;
IManagedBuilderMakefileGenerator buildfileGenerator = ManagedBuildManager
.getBuildfileGenerator(buildInfo
.getDefaultConfiguration());
if(buildfileGenerator == null)
return false;
// make sure build file generator is initialized
buildfileGenerator.initialize(file.getProject(), buildInfo, new NullProgressMonitor());
// if we have no build info or we can't build the file, then
// disable the action
if (!buildInfo.buildsFileType(file.getFileExtension())
|| buildfileGenerator.isGeneratedResource(file) ) {
return false;
}
}
}
}
return true;
}
/*
* Updates the enablement state for the action based upon the selection. If
* the selection corresponds to files buildable by MBS, then the action will
* be enabled.
*/
private void update() {
if(action != null)
action.setEnabled(shouldBeEnabled());
}
/*
* (non-Javadoc)
*
@ -282,8 +328,8 @@ public class BuildFilesAction extends Action implements IWorkbenchWindowActionDe
* org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged(IAction action, ISelection selection) {
// TODO Auto-generated method stub
// update state
update();
}

View file

@ -48,17 +48,20 @@ import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionDelegate;
/**
* @author crecoskie
*
*/
public class CleanFilesAction extends Action implements IWorkbenchWindowActionDelegate {
public class CleanFilesAction extends ActionDelegate implements IWorkbenchWindowActionDelegate {
/**
* The workbench window; or <code>null</code> if this action has been
* <code>dispose</code>d.
*/
private IWorkbenchWindow workbenchWindow;
private IWorkbenchWindow workbenchWindow = null;
private IAction action = null;
/**
*
@ -71,39 +74,10 @@ public class CleanFilesAction extends Action implements IWorkbenchWindowActionDe
* Creates an instance of this action, for use in the given window.
*/
public CleanFilesAction(IWorkbenchWindow window) {
super(ManagedMakeMessages.getResourceString("CleanFilesAction.cleanFiles")); //$NON-NLS-1$
if (window == null) {
throw new IllegalArgumentException();
}
this.workbenchWindow = window;
setToolTipText(ManagedMakeMessages.getResourceString("CleanFilesAction.cleanSelectedFiles")); //$NON-NLS-1$
setActionDefinitionId("org.eclipse.cdt.managedbuilder.ui.CleanFilesAction"); //$NON-NLS-1$
}
/**
* @param text
*/
public CleanFilesAction(String text) {
super(text);
// TODO Auto-generated constructor stub
}
/**
* @param text
* @param image
*/
public CleanFilesAction(String text, ImageDescriptor image) {
super(text, image);
// TODO Auto-generated constructor stub
}
/**
* @param text
* @param style
*/
public CleanFilesAction(String text, int style) {
super(text, style);
// TODO Auto-generated constructor stub
}
/*
@ -116,6 +90,15 @@ public class CleanFilesAction extends Action implements IWorkbenchWindowActionDe
}
/* (non-Javadoc)
* @see org.eclipse.ui.actions.ActionDelegate#init(org.eclipse.jface.action.IAction)
*/
public void init(IAction action) {
this.action = action;
update();
}
/*
* (non-Javadoc)
*
@ -287,6 +270,53 @@ public class CleanFilesAction extends Action implements IWorkbenchWindowActionDe
job.schedule();
}
private boolean shouldBeEnabled() {
ISelectionService selectionService = workbenchWindow
.getSelectionService();
ISelection selection = selectionService.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
for (Iterator elements = structuredSelection.iterator(); elements
.hasNext();) {
IFile file = convertToIFile(elements.next());
if (file != null) {
// we only add files that we can actually build
if(!ManagedBuildManager.manages(file.getProject()))
{
return false;
}
IManagedBuildInfo buildInfo = ManagedBuildManager
.getBuildInfo(file.getProject());
// if we have no build info or we can't build the file, then
// disable the action
if (buildInfo == null
|| !buildInfo.buildsFileType(file.getFileExtension()) ) {
return false;
}
}
}
}
return true;
}
/*
* Updates the enablement state for the action based upon the selection. If
* the selection corresponds to files buildable by MBS, then the action will
* be enabled.
*/
private void update() {
if(action != null)
action.setEnabled(shouldBeEnabled());
}
/*
* (non-Javadoc)
*
@ -294,8 +324,7 @@ public class CleanFilesAction extends Action implements IWorkbenchWindowActionDe
* org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged(IAction action, ISelection selection) {
// TODO Auto-generated method stub
update();
}
}