Skip to content

Commit

Permalink
Fix Bug 3146
Browse files Browse the repository at this point in the history
Running R script from editor does not show the R-view
  • Loading branch information
Valentin Georgiev committed Mar 3, 2012
1 parent 2c2db93 commit e26fade
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
Expand Up @@ -7,23 +7,29 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

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

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

RConsoleView rView = (RConsoleView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.bioclipse.r.ui.views.RConsoleView");
String contents = RunUtil.getContent(event);
rView.execEditorInpit(contents);
//We are done
try {
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 contents = RunUtil.getContent(event);
rView.execEditorInpit(contents);
} catch (PartInitException e) {
e.printStackTrace();
}

return null;
}

Expand Down
Expand Up @@ -7,24 +7,30 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

/**
* Handler to source an R Script taken from active editor contents.
*
* @author ola
* @authors ola, valyo
*
*/
public class RunRScriptHandler extends AbstractHandler implements IHandler {

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

RConsoleView rView = (RConsoleView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.bioclipse.r.ui.views.RConsoleView");
String filepath = RunUtil.getFilePath();
//Pass the path to the R console method
rView.execEditorInpit("source(\"" + filepath + "\")");
//We are done
try {
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 filepath = RunUtil.getFilePath();
rView.execEditorInpit("source(\"" + filepath + "\")");
rView.printMessage(NEWLINE + RunUtil.getContent(event));
} catch (PartInitException e) {
e.printStackTrace();
}
return null;
}
}
Expand Up @@ -13,14 +13,15 @@
/**
* Handler to execute a Text Selection in R
*
* @author ola
* @authors ola, valyo
*
*/
public class RunRSnippetHandler extends AbstractHandler implements IHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
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.execEditorInpit(code);
Expand Down
@@ -1,10 +1,3 @@
/**
* Util methods for running code from the R editor
*
* @author valyo
*
*/

package net.bioclipse.r.ui.util;

import java.util.ArrayList;
Expand All @@ -26,13 +19,21 @@
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.texteditor.ITextEditor;

/**
* Util methods for running code from the R editor
*
* @author valyo
*
*/
public class RunUtil {

public static final String fileseparator = java.io.File.separator;
public static String cmdparser = "(;?\r?\n|;)";

public static String getSelectedCode(final ExecutionEvent event) throws CoreException {
try {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
editor.setFocus();
final ISelection selection = WorkbenchUIUtil.getCurrentSelection(event.getApplicationContext());
final IWorkbenchPart workbenchPart = HandlerUtil.getActivePart(event);
if (selection instanceof ITextSelection) {
Expand All @@ -47,7 +48,6 @@ public static String getSelectedCode(final ExecutionEvent event) throws CoreExce
else {
IDocument document = null;
if (workbenchPart instanceof ITextEditor) {
final ITextEditor editor = (ITextEditor) workbenchPart;
if (!(editor instanceof REditor))
return null;
REditor reditor = (REditor) editor;
Expand Down

0 comments on commit e26fade

Please sign in to comment.