From a8dceb1039f19c1e25ac0e86646da0aac1dc2942 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Wed, 13 Aug 2014 15:33:13 -0400 Subject: RPM: Edit targets of "Build RPM" commands. -The "Build RPM" toolbar button now only targets the currently active .spec file editor rather than the active selection. -Prevent RPM Builds from being possible for projects without an RPM nature. -Prevent RPM popup menu options from appearing when the active selection contains more than one element. Change-Id: I31aa2c5827b2fa4acf692f764a64dbd7b4fc25d9 Signed-off-by: Andrew Ferrazzutti Reviewed-on: https://git.eclipse.org/r/31564 Reviewed-by: Alexander Kurtakov Tested-by: Alexander Kurtakov --- rpm/org.eclipse.linuxtools.rpm.core/plugin.xml | 43 +++++++++++-------- rpm/org.eclipse.linuxtools.rpm.ui/plugin.xml | 21 +++++++++ .../ui/handlers/SpecfileEditorRPMBuildHandler.java | 50 ++++++++++++++-------- 3 files changed, 77 insertions(+), 37 deletions(-) (limited to 'rpm') diff --git a/rpm/org.eclipse.linuxtools.rpm.core/plugin.xml b/rpm/org.eclipse.linuxtools.rpm.core/plugin.xml index d4d8fbeb97..8fca7b0b70 100644 --- a/rpm/org.eclipse.linuxtools.rpm.core/plugin.xml +++ b/rpm/org.eclipse.linuxtools.rpm.core/plugin.xml @@ -27,25 +27,30 @@ point="org.eclipse.core.expressions.definitions"> - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/rpm/org.eclipse.linuxtools.rpm.ui/plugin.xml b/rpm/org.eclipse.linuxtools.rpm.ui/plugin.xml index 661fd9e3f7..4be0a6113c 100644 --- a/rpm/org.eclipse.linuxtools.rpm.ui/plugin.xml +++ b/rpm/org.eclipse.linuxtools.rpm.ui/plugin.xml @@ -224,6 +224,11 @@ name="buildType" optional="false"> + + + + @@ -280,6 +289,10 @@ name="buildType" value="SOURCE"> + + + + + + diff --git a/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/handlers/SpecfileEditorRPMBuildHandler.java b/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/handlers/SpecfileEditorRPMBuildHandler.java index 0a09076d51..db2bd85b96 100644 --- a/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/handlers/SpecfileEditorRPMBuildHandler.java +++ b/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/handlers/SpecfileEditorRPMBuildHandler.java @@ -29,6 +29,7 @@ import org.eclipse.linuxtools.rpm.core.RPMProject; import org.eclipse.linuxtools.rpm.core.RPMProjectLayout; import org.eclipse.linuxtools.rpm.ui.RPMExportOperation; import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchSite; @@ -42,16 +43,19 @@ import org.eclipse.ui.part.EditorPart; */ public class SpecfileEditorRPMBuildHandler extends AbstractHandler { + private static final String BUILD_TYPE = "buildType"; //$NON-NLS-1$ + private static final String ON_EDITOR = "actOnEditor"; //$NON-NLS-1$ protected RPMProject rpj; @Override public Object execute(ExecutionEvent event) throws ExecutionException { final IResource resource = getResource(event); - final String eventBuildType = event.getParameter("buildType"); //$NON-NLS-1$ rpj = getRPMProject(resource); - Job job = new RPMExportOperation(rpj, eventBuildType); - job.setUser(true); - job.schedule(); + if (rpj != null) { + Job job = new RPMExportOperation(rpj, event.getParameter(BUILD_TYPE)); + job.setUser(true); + job.schedule(); + } return null; } @@ -61,6 +65,17 @@ public class SpecfileEditorRPMBuildHandler extends AbstractHandler { * @return The resource that was selected. */ private static IResource getResource(ExecutionEvent event) { + final boolean actOnEditor = Boolean.valueOf(event.getParameter(ON_EDITOR)); + if (actOnEditor) { + IEditorPart epart = HandlerUtil.getActiveEditor(event); + if (epart != null) { + IEditorInput input = epart.getEditorInput(); + if (input instanceof IFileEditorInput) { + return ((IFileEditorInput) input).getFile(); + } + } + return null; + } IWorkbenchPart part = HandlerUtil.getActivePart(event); if (part == null) { return null; @@ -102,23 +117,22 @@ public class SpecfileEditorRPMBuildHandler extends AbstractHandler { * @return The RPMProject of the resource passed in. */ private static RPMProject getRPMProject(IResource resource) { - RPMProject rc = null; - try { - IProject parentProject = resource.getProject(); + if (resource != null) { + try { + IProject parentProject = resource.getProject(); - // determine if project selected is an RPMProject - if (parentProject.hasNature(IRPMConstants.RPM_NATURE_ID)) { - if (parentProject.getPersistentProperty(new QualifiedName(IRPMConstants.RPM_CORE_ID, IRPMConstants.SPECS_FOLDER)) != null){ - rc = new RPMProject(parentProject, RPMProjectLayout.RPMBUILD); - } else { - rc = new RPMProject(parentProject, RPMProjectLayout.FLAT); + // determine if project selected is an RPMProject + if (parentProject.hasNature(IRPMConstants.RPM_NATURE_ID)) { + if (parentProject.getPersistentProperty(new QualifiedName(IRPMConstants.RPM_CORE_ID, IRPMConstants.SPECS_FOLDER)) != null){ + return new RPMProject(parentProject, RPMProjectLayout.RPMBUILD); + } else { + return new RPMProject(parentProject, RPMProjectLayout.FLAT); + } } - } else { - rc = new RPMProject(parentProject, RPMProjectLayout.FLAT); + } catch (CoreException e) { + Activator.logError(Messages.getString("SpecfileEditorRPMBuildHandler.logRPMProjectError"), e); //$NON-NLS-1$ } - } catch (CoreException e) { - Activator.logError(Messages.getString("SpecfileEditorRPMBuildHandler.logRPMProjectError"), e); //$NON-NLS-1$ } - return rc; + return null; } } -- cgit v1.2.3