use of com.google.gwt.user.client.Command in project rstudio by rstudio.
the class ToolbarPopupMenuButton method addMenuItem.
public void addMenuItem(final MenuItem item, final String value) {
final ScheduledCommand cmd = item.getScheduledCommand();
item.setScheduledCommand(new Command() {
@Override
public void execute() {
setText(value);
if (cmd != null)
cmd.execute();
}
});
getMenu().addItem(item);
}
use of com.google.gwt.user.client.Command in project rstudio by rstudio.
the class Wizard method goBack.
private void goBack() {
final boolean isNavigationPage = activeParentNavigationPage_ != null;
// determine behavior based on whether we are going back to a
// navigation page or a selector page
final Widget toWidget = isNavigationPage ? activeParentNavigationPage_ : firstPage_;
final String pageCaptionLabel = isNavigationPage ? activeParentNavigationPage_.getPageCaption() : "";
final WizardPage<I, T> newActivePage = isNavigationPage ? activeParentNavigationPage_ : firstPage_;
final CanFocus focusWidget = (CanFocus) toWidget;
activeParentNavigationPage_ = null;
onPageDeactivated(activePage_);
activePage_.onDeactivate(new Operation() {
public void execute() {
animate(activePage_, toWidget, false, new Command() {
@Override
public void execute() {
// update active page
activePage_ = newActivePage;
// update header
subCaptionLabel_.setVisible(newActivePage == firstPage_);
pageCaptionLabel_.setVisible(newActivePage != firstPage_ && isNavigationPage);
pageCaptionLabel_.setText(pageCaptionLabel);
setNextButtonState(newActivePage);
backButton_.setVisible(newActivePage != firstPage_);
// make ok button invisible
setOkButtonVisible(false);
// call hook
onSelectorActivated();
// set focus
focusWidget.focus();
}
});
}
});
}
use of com.google.gwt.user.client.Command in project rstudio by rstudio.
the class TextEditingTarget method saveNewFileWithEncoding.
private void saveNewFileWithEncoding(String suggestedPath, final String encoding, final Command executeOnSuccess) {
view_.ensureVisible();
FileSystemItem fsi;
if (suggestedPath != null)
fsi = FileSystemItem.createFile(suggestedPath);
else
fsi = getSaveFileDefaultDir();
fileDialogs_.saveFile("Save File - " + getName().getValue(), fileContext_, fsi, fileType_.getDefaultExtension(), false, new ProgressOperationWithInput<FileSystemItem>() {
public void execute(final FileSystemItem saveItem, ProgressIndicator indicator) {
if (saveItem == null)
return;
try {
workbenchContext_.setDefaultFileDialogDir(saveItem.getParentPath());
final TextFileType fileType = fileTypeRegistry_.getTextTypeForFile(saveItem);
final Command saveCommand = new Command() {
@Override
public void execute() {
if (!getPath().equals(saveItem.getPath())) {
// breakpoints are file-specific, so when saving
// as a different file, clear the display of
// breakpoints from the old file name
docDisplay_.removeAllBreakpoints();
// update publish settings
syncPublishPath(saveItem.getPath());
}
fixupCodeBeforeSaving();
docUpdateSentinel_.save(saveItem.getPath(), fileType.getTypeId(), encoding, new SaveProgressIndicator(saveItem, fileType, executeOnSuccess));
events_.fireEvent(new SourceFileSavedEvent(getId(), saveItem.getPath()));
}
};
// to a non-R file type then confirm
if (fileType_.isR() && !fileType.isR()) {
globalDisplay_.showYesNoMessage(MessageDialog.WARNING, "Confirm Change File Type", "This file was created as an R script however " + "the file extension you specified will change " + "it into another file type that will no longer " + "open as an R script.\n\n" + "Are you sure you want to change the type of " + "the file so that it is no longer an R script?", new Operation() {
@Override
public void execute() {
saveCommand.execute();
}
}, false);
} else {
saveCommand.execute();
}
} catch (Exception e) {
indicator.onError(e.toString());
return;
}
indicator.onCompleted();
}
});
}
use of com.google.gwt.user.client.Command in project rstudio by rstudio.
the class TextEditingTarget method executeChunks.
public void executeChunks(final Position position, int which) {
if (docDisplay_.showChunkOutputInline()) {
executeChunksNotebookMode(position, which);
return;
}
// HACK: This is just to force the entire function tree to be built.
// It's the easiest way to make sure getCurrentScope() returns
// a Scope with an end.
docDisplay_.getScopeTree();
// execute the chunks
Scope[] previousScopes = scopeHelper_.getSweaveChunks(position, which);
StringBuilder builder = new StringBuilder();
for (Scope scope : previousScopes) {
if (isRChunk(scope) && isExecutableChunk(scope)) {
builder.append("# " + scope.getLabel() + "\n");
builder.append(scopeHelper_.getSweaveChunkText(scope));
builder.append("\n\n");
}
}
final String code = builder.toString().trim();
if (fileType_.isRmd()) {
docUpdateSentinel_.withSavedDoc(new Command() {
@Override
public void execute() {
rmarkdownHelper_.prepareForRmdChunkExecution(docUpdateSentinel_.getId(), docUpdateSentinel_.getContents(), new Command() {
@Override
public void execute() {
events_.fireEvent(new SendToConsoleEvent(code, true));
}
});
}
});
} else {
events_.fireEvent(new SendToConsoleEvent(code, true));
}
}
use of com.google.gwt.user.client.Command in project rstudio by rstudio.
the class TextEditingTarget method previewRpresentation.
void previewRpresentation() {
SessionInfo sessionInfo = session_.getSessionInfo();
if (!fileTypeCommands_.getHTMLCapabiliites().isRMarkdownSupported()) {
globalDisplay_.showMessage(MessageDisplay.MSG_WARNING, "Unable to Preview", "R Presentations require the knitr package " + "(version 1.2 or higher)");
return;
}
PresentationState state = sessionInfo.getPresentationState();
// if we are showing a tutorial then don't allow preview
if (state.isTutorial()) {
globalDisplay_.showMessage(MessageDisplay.MSG_WARNING, "Unable to Preview", "R Presentations cannot be previewed when a Tutorial " + "is active");
return;
}
// if this presentation is already showing then just activate
if (state.isActive() && state.getFilePath().equals(docUpdateSentinel_.getPath())) {
commands_.activatePresentation().execute();
save();
} else // otherwise reload
{
saveThenExecute(null, new Command() {
@Override
public void execute() {
server_.showPresentationPane(docUpdateSentinel_.getPath(), new VoidServerRequestCallback());
}
});
}
}
Aggregations