use of org.rstudio.core.client.command.Handler in project rstudio by rstudio.
the class Source method onNewRPresentationDoc.
@Handler
public void onNewRPresentationDoc() {
dependencyManager_.withRMarkdown("Authoring R Presentations", new Command() {
@Override
public void execute() {
fileDialogs_.saveFile("New R Presentation", fileContext_, workbenchContext_.getDefaultFileDialogDir(), ".Rpres", true, new ProgressOperationWithInput<FileSystemItem>() {
@Override
public void execute(final FileSystemItem input, final ProgressIndicator indicator) {
if (input == null) {
indicator.onCompleted();
return;
}
indicator.onProgress("Creating Presentation...");
server_.createNewPresentation(input.getPath(), new VoidServerRequestCallback(indicator) {
@Override
public void onSuccess() {
openFile(input, FileTypeRegistry.RPRESENTATION, new CommandWithArg<EditingTarget>() {
@Override
public void execute(EditingTarget arg) {
server_.showPresentationPane(input.getPath(), new VoidServerRequestCallback());
}
});
}
});
}
});
}
});
}
use of org.rstudio.core.client.command.Handler in project rstudio by rstudio.
the class Source method onFindInFiles.
@Handler
public void onFindInFiles() {
String searchPattern = "";
if (activeEditor_ != null && activeEditor_ instanceof TextEditingTarget) {
TextEditingTarget textEditor = (TextEditingTarget) activeEditor_;
String selection = textEditor.getSelectedText();
boolean multiLineSelection = selection.indexOf('\n') != -1;
if ((selection.length() != 0) && !multiLineSelection)
searchPattern = selection;
}
events_.fireEvent(new FindInFilesEvent(searchPattern));
}
use of org.rstudio.core.client.command.Handler in project rstudio by rstudio.
the class CodeSearchLauncher method onGoToFileFunction.
@Handler
public void onGoToFileFunction() {
if (dialog_ != null)
dialog_.closeDialog();
dialog_ = new CodeSearchDialog(pCodeSearch_);
dialog_.showModal();
}
use of org.rstudio.core.client.command.Handler in project rstudio by rstudio.
the class TextEditingTarget method onExtractLocalVariable.
@Handler
void onExtractLocalVariable() {
if (!isCursorInRMode()) {
showRModeWarning("Extract Variable");
return;
}
docDisplay_.focus();
String initialSelection = docDisplay_.getSelectionValue();
final String refactoringName = "Extract local variable";
final String pleaseSelectCodeMessage = "Please select the code to " + "extract into a variable.";
if (checkSelectionAndAlert(refactoringName, pleaseSelectCodeMessage, initialSelection))
return;
docDisplay_.fitSelectionToLines(false);
final String code = docDisplay_.getSelectionValue();
if (checkSelectionAndAlert(refactoringName, pleaseSelectCodeMessage, code))
return;
// get the first line of the selection and calculate it's indentation
String firstLine = docDisplay_.getLine(docDisplay_.getSelectionStart().getRow());
final String indentation = extractIndentation(firstLine);
// used to parse the code
server_.detectFreeVars(code, new RefactorServerRequestCallback(refactoringName) {
@Override
void doExtract(JsArrayString response) {
globalDisplay_.promptForText(refactoringName, "Variable Name", "", new OperationWithInput<String>() {
public void execute(String input) {
final String extractedCode = indentation + input.trim() + " <- " + code + "\n";
InputEditorPosition insertPosition = docDisplay_.getSelection().extendToLineStart().getStart();
docDisplay_.replaceSelection(input.trim());
docDisplay_.insertCode(insertPosition, extractedCode);
}
});
}
});
}
use of org.rstudio.core.client.command.Handler in project rstudio by rstudio.
the class TextEditingTarget method onExtractFunction.
@Handler
void onExtractFunction() {
if (!isCursorInRMode()) {
showRModeWarning("Extract Function");
return;
}
docDisplay_.focus();
String initialSelection = docDisplay_.getSelectionValue();
final String refactoringName = "Extract Function";
final String pleaseSelectCodeMessage = "Please select the code to " + "extract into a function.";
if (checkSelectionAndAlert(refactoringName, pleaseSelectCodeMessage, initialSelection))
return;
docDisplay_.fitSelectionToLines(false);
final String code = docDisplay_.getSelectionValue();
if (checkSelectionAndAlert(refactoringName, pleaseSelectCodeMessage, code))
return;
final String indentation = extractIndentation(code);
server_.detectFreeVars(code, new RefactorServerRequestCallback(refactoringName) {
@Override
void doExtract(final JsArrayString response) {
globalDisplay_.promptForText(refactoringName, "Function Name", "", new OperationWithInput<String>() {
public void execute(String input) {
String prefix;
if (docDisplay_.getSelectionOffset(true) == 0)
prefix = "";
else
prefix = "\n";
String args = response != null ? response.join(", ") : "";
docDisplay_.replaceSelection(prefix + indentation + input.trim() + " <- " + "function(" + args + ") {\n" + StringUtil.indent(code, " ") + "\n" + indentation + "}");
}
});
}
});
}
Aggregations