Permalink
Browse files

plugin.xml: Add 'Run coala' button to toolbar

  • Loading branch information...
arafsheikh committed Jul 15, 2016
1 parent ae8d98e commit fbdede59344bbdc2d2b97d4b236f90d8c09f1a6e
Showing with 40 additions and 47 deletions.
  1. +9 −29 com.coala.core/plugin.xml
  2. +31 −18 com.coala.core/src/com/coala/core/handlers/RuncoafileHandler.java
@@ -59,47 +59,27 @@
<menu
icon="icons/coala-analyzer.gif"
id="com.coala.core.menus.popupMenu"
label="coala"
label="Run coala with"
mnemonic="o">
<command
label = "Analyze using coala"
commandId="com.coala.core.commands.runcoalaCommand"
mnemonic="A"
id="com.coala.core.menus.sampleCommand">
</command>
<command
label = "Clear coala violations"
commandId="com.coala.core.commands.removeMarkersCommand"
mnemonic="C"
id="com.coala.core.menus.removeMarkersCommand">
</command>
<separator
name="com.coala.core.separator1"
visible="true">
</separator>
<menu
label="Run coala with">
<dynamic
<dynamic
class="com.coala.core.menu.BearMenu"
id="com.coala.core.menu.bearListValues">
</dynamic>
</menu>
</dynamic>
</menu>
</menuContribution>
<!--
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="com.coala.core.toolbars.sampleToolbar">
id="com.coala.core.toolbar">
<command
commandId="com.coala.core.commands.sampleCommand"
icon="icons/sample.gif"
tooltip="Say hello world"
id="com.coala.core.toolbars.sampleCommand">
commandId="com.coala.core.commands.runcoalaCommand"
icon="icons/coala-analyzer.gif"
label="coala"
mode="FORCE_TEXT"
tooltip="Run coala on Project">
</command>
</toolbar>
</menuContribution>
-->
</extension>
<extension id="coolmarker" point="org.eclipse.core.resources.markers"/>
@@ -5,15 +5,21 @@
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* The PluginHandler extends AbstractHandler, an IHandler base class.
@@ -39,30 +45,37 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
String folder = null;
IProject project = null;
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
IStructuredSelection selection = (IStructuredSelection) window.getSelectionService()
.getSelection();
Object firstElement = selection.getFirstElement();
if (firstElement instanceof IAdaptable) {
project = (IProject) ((IAdaptable) firstElement).getAdapter(IProject.class);
if (project == null) {
System.out.println("Project returned null.");
} else {
IPath path = project.getLocation();
folder = path.toOSString();
}
}
IFile openFile = (IFile) window.getActivePage().getActivePart().getSite().getPage()
.getActiveEditor().getEditorInput().getAdapter(IFile.class);
project = openFile.getProject();
if (project != null) {
IPath path = project.getLocation();
folder = path.toOSString();
}
new RemoveMarkers().execute(event);
try {
if (folder != null && project != null) {
if (folder != null && project.getFile(".coafile").exists()) {
ExternalUtils.runcoafile(folder, project);
} else {
MessageDialog.openError(null, "coafile not found",
"This coafile couldn't be found in this directory. Please create one.");
boolean ret = MessageDialog.openQuestion(null, "coafile was not found in this project",
"coala requires a configuration file to run the analysis.\nDo you want to create one?");
if (ret) {
IFile coafile = project.getFile(".coafile");
String data = "# Learn about writing coafile at http://coala.readthedocs.io/en/latest/Users/coafile.html";
byte[] bytes = data.getBytes();
InputStream source = new ByteArrayInputStream(bytes);
coafile.create(source, IResource.NONE, null);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage();
IDE.openEditor(page, coafile, true);
}
}
} catch (IOException ex) {
ex.printStackTrace();
} catch (PartInitException ex) {
ex.printStackTrace();
} catch (CoreException ex) {
ex.printStackTrace();
}
return null;
}

0 comments on commit fbdede5

Please sign in to comment.