use of org.rstudio.studio.client.common.GlobalProgressDelayer in project rstudio by rstudio.
the class RCompletionManager method goToFunctionDefinition.
public void goToFunctionDefinition() {
// check for a file-local definition (intra-file navigation -- using
// the active scope tree)
AceEditor editor = (AceEditor) docDisplay_;
if (editor != null) {
TokenCursor cursor = editor.getSession().getMode().getRCodeModel().getTokenCursor();
if (cursor.moveToPosition(editor.getCursorPosition(), true)) {
// token (obstensibly a funciton name)
if (cursor.isLeftBracket())
cursor.moveToPreviousToken();
// navigate (as this isn't the 'full' function name)
if (cursor.moveToPreviousToken()) {
if (cursor.isExtractionOperator())
return;
cursor.moveToNextToken();
}
// if this is a string, try resolving that string as a file name
if (cursor.hasType("string")) {
String tokenValue = cursor.currentValue();
String path = tokenValue.substring(1, tokenValue.length() - 1);
FileSystemItem filePath = FileSystemItem.createFile(path);
// This will show a dialog error if no such file exists; this
// seems the most appropriate action in such a case.
fileTypeRegistry_.editFile(filePath);
}
String functionName = cursor.currentValue();
JsArray<ScopeFunction> scopes = editor.getAllFunctionScopes();
for (int i = 0; i < scopes.length(); i++) {
ScopeFunction scope = scopes.get(i);
if (scope.getFunctionName().equals(functionName)) {
navigableSourceEditor_.navigateToPosition(SourcePosition.create(scope.getPreamble().getRow(), scope.getPreamble().getColumn()), true);
return;
}
}
}
}
// intra-file navigation failed -- hit the server and find a definition
// in the project index
// determine current line and cursor position
InputEditorLineWithCursorPosition lineWithPos = InputEditorUtil.getLineWithCursorPosition(input_);
// delayed progress indicator
final GlobalProgressDelayer progress = new GlobalProgressDelayer(globalDisplay_, 1000, "Searching for function definition...");
server_.getObjectDefinition(lineWithPos.getLine(), lineWithPos.getPosition(), new ServerRequestCallback<ObjectDefinition>() {
@Override
public void onResponseReceived(ObjectDefinition def) {
// dismiss progress
progress.dismiss();
// if we got a hit
if (def.getObjectName() != null) {
// search locally if a function navigator was provided
if (navigableSourceEditor_ != null) {
// try to search for the function locally
SourcePosition position = navigableSourceEditor_.findFunctionPositionFromCursor(def.getObjectName());
if (position != null) {
navigableSourceEditor_.navigateToPosition(position, true);
// we're done
return;
}
}
// navigate to the file/loc
if (def.getObjectType() == FileFunctionDefinition.OBJECT_TYPE) {
FileFunctionDefinition fileDef = def.getObjectData().cast();
fileTypeRegistry_.editFile(fileDef.getFile(), fileDef.getPosition());
} else // search path definition
if (def.getObjectType() == SearchPathFunctionDefinition.OBJECT_TYPE) {
SearchPathFunctionDefinition searchDef = def.getObjectData().cast();
eventBus_.fireEvent(new CodeBrowserNavigationEvent(searchDef));
} else // finally, check to see if it's a data frame
if (def.getObjectType() == DataDefinition.OBJECT_TYPE) {
eventBus_.fireEvent(new SendToConsoleEvent("View(" + def.getObjectName() + ")", true, false));
}
}
}
@Override
public void onError(ServerError error) {
progress.dismiss();
globalDisplay_.showErrorMessage("Error Searching for Function", error.getUserMessage());
}
});
}
use of org.rstudio.studio.client.common.GlobalProgressDelayer in project rstudio by rstudio.
the class Presentation method confirmClose.
public void confirmClose(Command onConfirmed) {
// don't allow close if this is a tutorial
if (currentState_.isTutorial()) {
globalDisplay_.showMessage(MessageDisplay.MSG_WARNING, "Unable to Close", "Tutorials cannot be closed");
return;
}
final ProgressIndicator progress = new GlobalProgressDelayer(globalDisplay_, 0, "Closing Presentation...").getIndicator();
server_.closePresentationPane(new ServerRequestCallback<Void>() {
@Override
public void onResponseReceived(Void resp) {
reloadWorkbench();
}
@Override
public void onError(ServerError error) {
progress.onError(error.getUserMessage());
}
});
}
use of org.rstudio.studio.client.common.GlobalProgressDelayer in project rstudio by rstudio.
the class Workbench method onVersionControlShowRsaKey.
@Handler
public void onVersionControlShowRsaKey() {
final ProgressIndicator indicator = new GlobalProgressDelayer(globalDisplay_, 500, "Reading RSA public key...").getIndicator();
// compute path to public key
String sshDir = session_.getSessionInfo().getDefaultSSHKeyDir();
final String keyPath = FileSystemItem.createDir(sshDir).completePath("id_rsa.pub");
// read it
server_.gitSshPublicKey(keyPath, new ServerRequestCallback<String>() {
@Override
public void onResponseReceived(String publicKeyContents) {
indicator.onCompleted();
new ShowPublicKeyDialog("RSA Public Key", publicKeyContents).showModal();
}
@Override
public void onError(ServerError error) {
String msg = "Error attempting to read key '" + keyPath + "' (" + error.getUserMessage() + ")";
indicator.onError(msg);
}
});
}
use of org.rstudio.studio.client.common.GlobalProgressDelayer in project rstudio by rstudio.
the class TextEditingTargetRMarkdownHelper method createDraftFromTemplate.
private void createDraftFromTemplate(final RmdChosenTemplate template, final String target) {
final ProgressIndicator progress = new GlobalProgressDelayer(globalDisplay_, 250, "Creating R Markdown Document...").getIndicator();
server_.createRmdFromTemplate(target, template.getTemplatePath(), template.createDir(), new ServerRequestCallback<RmdCreatedTemplate>() {
@Override
public void onResponseReceived(RmdCreatedTemplate created) {
// write a pref indicating this is the preferred template--
// we'll default to it the next time we load the template list
prefs_.rmdPreferredTemplatePath().setGlobalValue(template.getTemplatePath());
prefs_.writeUIPrefs();
FileSystemItem file = FileSystemItem.createFile(created.getPath());
eventBus_.fireEvent(new FileEditEvent(file));
progress.onCompleted();
}
@Override
public void onError(ServerError error) {
progress.onError("Couldn't create a template from " + template.getTemplatePath() + " at " + target + ".\n\n" + error.getMessage());
}
});
}
use of org.rstudio.studio.client.common.GlobalProgressDelayer in project rstudio by rstudio.
the class ProjectPopupMenu method getDynamicPopupMenu.
@Override
public void getDynamicPopupMenu(final DynamicPopupMenuCallback callback) {
ProjectMRUList.setOpenInNewWindow(false);
if (allowSharedProjects_) {
final GlobalProgressDelayer progress = new GlobalProgressDelayer(RStudioGinjector.INSTANCE.getGlobalDisplay(), 250, "Looking for projects...");
// if shared projects are on, check for them every time the user drops
// the menu; we request one more than the maximum we can display so
// we can let the user know whether there are more projects than those
// that can be displayed in the menu
server_.getSharedProjects(MAX_SHARED_PROJECTS + 1, new ServerRequestCallback<JsArray<SharedProjectDetails>>() {
@Override
public void onResponseReceived(JsArray<SharedProjectDetails> result) {
rebuildMenu(result, callback);
progress.dismiss();
}
@Override
public void onError(ServerError error) {
// if we can't get the shared projects, we can at least show
// the menu without them
rebuildMenu(null, callback);
progress.dismiss();
}
});
} else {
rebuildMenu(null, callback);
}
}
Aggregations