Skip to content

Commit

Permalink
Change R editor commands and menu contributions
Browse files Browse the repository at this point in the history
so that R code is "parsed"
  • Loading branch information
Valentin Georgiev committed Apr 27, 2012
1 parent 10d52a4 commit e011213
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 21 deletions.
46 changes: 32 additions & 14 deletions plugins/net.bioclipse.r.ui/plugin.xml
Expand Up @@ -43,22 +43,27 @@

<extension point="org.eclipse.ui.commands">
<command
id="net.bioclipse.r.ui.runRSnippet"
defaultHandler="net.bioclipse.r.ui.handlers.RunRSnippetHandler"
name="Run R snippet"/>
id="net.bioclipse.r.ui.SourceRSnippet"
defaultHandler="net.bioclipse.r.ui.handlers.SourceRSnippetHandler"
name="Source selected R snippet"/>
<command
id="net.bioclipse.r.ui.runRAll"
defaultHandler="net.bioclipse.r.ui.handlers.RunRAllHandler"
name="Run editor content in R"/>
defaultHandler="net.bioclipse.r.ui.handlers.SourceRAllHandler"
name="Source editor content in R"/>
<command
id="net.bioclipse.r.ui.runRScript"
defaultHandler="net.bioclipse.r.ui.handlers.RunRScriptHandler"
name="Run R Script"/>
id="net.bioclipse.r.ui.SourceRScript"
defaultHandler="net.bioclipse.r.ui.handlers.SourceRScriptHandler"
name="Source R Script"/>
<command
defaultHandler="net.bioclipse.r.ui.handlers.saveRSessionHandler"
id="net.bioclipse.r.ui.saveRSession"
defaultHandler="net.bioclipse.r.ui.handlers.SaveRSessionHandler"
id="net.bioclipse.r.ui.SaveRSession"
name="Save R session">
</command>
<command
defaultHandler="net.bioclipse.r.ui.handlers.RunLinesCodeHandler"
id="net.bioclipse.r.ui.RunLinesCode"
name="Run current line/selected lines in R">
</command>
</extension>

<extension
Expand All @@ -67,8 +72,8 @@
<menuContribution
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command
commandId="net.bioclipse.r.ui.runRSnippet"
label="Run current line/selected R snippet">
commandId="net.bioclipse.r.ui.SourceRSnippet"
label="Source selected R snippet">
<visibleWhen>
<iterate operator="and" ifEmpty="false">
<adapt type="org.eclipse.jface.text.ITextSelection" />
Expand All @@ -82,7 +87,7 @@
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command
commandId="net.bioclipse.r.ui.runRAll"
label="Run editor content in R">
label="Source editor content in R">
<visibleWhen>
<iterate operator="and" ifEmpty="false">
<adapt type="org.eclipse.jface.text.ITextSelection" />
Expand All @@ -91,12 +96,25 @@
</visibleWhen>
</command>
</menuContribution>
<menuContribution
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command
commandId="net.bioclipse.r.ui.RunLinesCode"
label="Run current line/selected lines in R">
<visibleWhen>
<iterate operator="and" ifEmpty="false">
<adapt type="org.eclipse.jface.text.ITextSelection" />
<reference definitionId="net.bioclipse.r.ui.editors.REditor.active" />
</iterate>
</visibleWhen>
</command>
</menuContribution>

<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar id="net.bioclipse.r.ui.toolbar">
<command
commandId="net.bioclipse.r.ui.runRScript"
commandId="net.bioclipse.r.ui.SourceRScript"
label="Source R Script"
icon="icons/r_icon.gif">
<visibleWhen>
Expand Down
@@ -0,0 +1,37 @@
package net.bioclipse.r.ui.handlers;

import net.bioclipse.r.ui.util.RunUtil;
import net.bioclipse.r.ui.views.RConsoleView;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.PlatformUI;

/**
* Handler to execute a Text Selection in R
*
* @authors ola, valyo
*
*/
public class RunLinesCodeHandler extends AbstractHandler implements IHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
String code = RunUtil.getSelectedCode(event);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("net.bioclipse.r.ui.views.RConsoleView");
RConsoleView rView = (RConsoleView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.bioclipse.r.ui.views.RConsoleView");
String[] codeStr = RunUtil.breakCommand(code);
for (String cs : codeStr) {
rView.execEditorInput(cs);
}
} catch (CoreException e) {
e.printStackTrace();
}
return null;
}

}
Expand Up @@ -16,7 +16,7 @@
* @authors ola, valyo
*
*/
public class RunRAllHandler extends AbstractHandler implements IHandler {
public class SourceRAllHandler extends AbstractHandler implements IHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Expand Down
Expand Up @@ -16,9 +16,8 @@
* @authors ola, valyo
*
*/
public class RunRScriptHandler extends AbstractHandler implements IHandler {
public class SourceRScriptHandler extends AbstractHandler implements IHandler {

public static String NEWLINE = System.getProperty("line.separator");
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

Expand Down
Expand Up @@ -11,19 +11,19 @@
import org.eclipse.ui.PlatformUI;

/**
* Handler to execute a Text Selection in R
* Handler to source a Text Selection or current line in R
*
* @authors ola, valyo
*
*/
public class RunRSnippetHandler extends AbstractHandler implements IHandler {
public class SourceRSnippetHandler extends AbstractHandler implements IHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
String code = RunUtil.getSelectedCode(event);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("net.bioclipse.r.ui.views.RConsoleView");
RConsoleView rView = (RConsoleView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.bioclipse.r.ui.views.RConsoleView");
String code = RunUtil.getSelectedCode(event);
rView.execEditorInput(code);
} catch (CoreException e) {
e.printStackTrace();
Expand Down
Expand Up @@ -89,7 +89,7 @@ public static String getFilePath() {
System.out.println("File path is: " + filepath);

//Get the file path with correct file separator
filepath = RunUtil.fixFilepath(filepath);
filepath = fixFilepath(filepath);
return filepath;
}

Expand Down

0 comments on commit e011213

Please sign in to comment.