Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor - move some methods related to running code from R editor
…to net.bioclipse.r.ui.util package
  • Loading branch information
Valentin Georgiev committed Feb 29, 2012
1 parent fdf24ea commit 8eb1bf4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 40 deletions.
Expand Up @@ -467,11 +467,6 @@ public String[] parseCommand(String command) {
return cmd;
}

public String fixFilepath(String filepath) {
filepath = filepath.replace(fileseparator, "/");
return filepath;
}

public String ls() {
return eval("ls()");
}
Expand Down
@@ -1,18 +1,13 @@
package net.bioclipse.r.ui.handlers;

import net.bioclipse.r.business.Activator;
import net.bioclipse.r.business.IRBusinessManager;
import net.bioclipse.r.ui.editors.REditor;
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.jface.text.IDocument;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;

/**
* Handler to execute a Text Selection in R
Expand All @@ -25,16 +20,8 @@ public class RunRAllHandler extends AbstractHandler implements IHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof REditor)) return null;
REditor reditor = (REditor)editor;

IDocument doc = reditor.getDocumentProvider().getDocument(reditor.getEditorInput());
String contents = doc.get();

System.out.println("Editor content: \n" + contents);

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
return null;
Expand Down
@@ -1,15 +1,12 @@
package net.bioclipse.r.ui.handlers;

import net.bioclipse.r.business.Activator;
import net.bioclipse.r.business.IRBusinessManager;
import net.bioclipse.r.ui.editors.REditor;
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.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;

/**
Expand All @@ -23,25 +20,11 @@ public class RunRScriptHandler extends AbstractHandler implements IHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().getActiveEditor();
if (!(editor instanceof REditor)) return null;
REditor reditor = (REditor) editor;

//Check the editor state and get the file path
String filepath = reditor.getFilePath();
System.out.println("File path is: " + filepath);

//Get the file path with correct file separator
IRBusinessManager r = Activator.getDefault().getJavaRBusinessManager();
filepath = r.fixFilepath(filepath);

//Pass the path to the R console method
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
return null;
}

}

0 comments on commit 8eb1bf4

Please sign in to comment.