Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed functioning of the button "Source R script"
added sourse(filepath) method to RBusinessManager
  • Loading branch information
Valentin Georgiev committed Aug 30, 2011
1 parent 3e90b7d commit e8711d3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Expand Up @@ -53,4 +53,10 @@ public interface IRBusinessManager extends IBioclipseManager {
methodSummary = "Passes the selection to eval"
)
public String evalSnippet(String seltext);

@Recorded
@PublishedMethod(
methodSummary = "Passes source(filepath) to eval"
)
public String source(String filepath);
}
Expand Up @@ -410,6 +410,11 @@ public String evalSnippet(String seltext) {
return retVal;

}
public String source(String filepath) {

eval("source(\"" + filepath + "\")");
return "";
}

public String ls() {
return eval("ls()");
Expand Down
Expand Up @@ -9,11 +9,13 @@
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.handlers.HandlerUtil;

/**
* Handler to execute an R Script taken from active editor contents.
* Handler to source an R Script taken from active editor contents.
*
* @author ola
*
Expand All @@ -27,18 +29,15 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
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 contents: " + contents);
//Get the file path from editor
IEditorInput einput = reditor.getEditorInput();
if (!(einput instanceof IFileEditorInput)) return null;
IFileEditorInput finput = (IFileEditorInput) einput;
String filepath = finput.getFile().getRawLocation().toOSString();
System.out.println("File path is: " + filepath);

IRBusinessManager r = Activator.getDefault().getJavaRBusinessManager();

String[] scrlines = contents.split("\n");
for (String rcmd: scrlines)
r.eval(rcmd);
// r.evalScript(contents);
//TODO: Implement
r.source(filepath);

//We are done
return null;
Expand Down

0 comments on commit e8711d3

Please sign in to comment.