use of com.google.gwt.user.client.Command in project rstudio by rstudio.
the class DocsMenu method setDocs.
public void setDocs(ImageResource[] icons, String[] names, String[] paths) {
clearItems();
names_.clear();
menuItems_.clear();
// de-duplicate names
names = deduplicate(names, paths);
assert icons.length == names.length && names.length == paths.length;
if (icons.length == 0) {
addItem(new DisabledMenuItem("(No documents)"));
}
for (int i = 0; i < icons.length; i++) {
String label = AppCommand.formatMenuLabel(icons[i], names[i] + " ", null);
final int tabIndex = i;
MenuItem item = addItem(label, true, new Command() {
public void execute() {
if (panel_ != null)
panel_.hide(false);
events_.fireEvent(new SwitchToDocEvent(tabIndex));
}
});
item.setTitle(paths[i]);
names_.add(names[i]);
menuItems_.add(item);
}
}
use of com.google.gwt.user.client.Command in project rstudio by rstudio.
the class Presentation method onPresentationFullscreen.
@Handler
void onPresentationFullscreen() {
// clear the internal iframe so there is no conflict over handling
// presentation events (we'll restore it on zoom close)
view_.clear();
// show the zoomed version of the presentation. after it closes
// restore the inline version
view_.zoom(session_.getSessionInfo().getPresentationName(), buildPresentationUrl("zoom"), new Command() {
@Override
public void execute() {
view_.load(buildPresentationUrl(), currentState_.getFilePath());
}
});
}
use of com.google.gwt.user.client.Command 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 com.google.gwt.user.client.Command in project rstudio by rstudio.
the class Source method closeAllLocalSourceDocs.
private void closeAllLocalSourceDocs(String caption, Command onCompleted, final boolean excludeActive) {
// save active editor for exclusion (it changes as we close tabs)
final EditingTarget activeEditor = activeEditor_;
// collect up a list of dirty documents
ArrayList<EditingTarget> dirtyTargets = new ArrayList<EditingTarget>();
for (EditingTarget target : editors_) {
if (excludeActive && target == activeEditor)
continue;
if (target.dirtyState().getValue())
dirtyTargets.add(target);
}
// create a command used to close all tabs
final Command closeAllTabsCommand = new Command() {
@Override
public void execute() {
cpsExecuteForEachEditor(editors_, new CPSEditingTargetCommand() {
@Override
public void execute(EditingTarget target, Command continuation) {
if (excludeActive && target == activeEditor) {
continuation.execute();
return;
} else {
view_.closeTab(target.asWidget(), false, continuation);
}
}
});
}
};
// save targets
saveEditingTargetsWithPrompt(caption, dirtyTargets, CommandUtil.join(closeAllTabsCommand, onCompleted), null);
}
use of com.google.gwt.user.client.Command in project rstudio by rstudio.
the class Source method openProjectDocs.
private void openProjectDocs(final Session session) {
JsArrayString openDocs = session.getSessionInfo().getProjectOpenDocs();
if (openDocs.length() > 0) {
// set new tab pending for the duration of the continuation
newTabPending_++;
// create a continuation for opening the source docs
SerializedCommandQueue openCommands = new SerializedCommandQueue();
for (int i = 0; i < openDocs.length(); i++) {
String doc = openDocs.get(i);
final FileSystemItem fsi = FileSystemItem.createFile(doc);
openCommands.addCommand(new SerializedCommand() {
@Override
public void onExecute(final Command continuation) {
openFile(fsi, fileTypeRegistry_.getTextTypeForFile(fsi), new CommandWithArg<EditingTarget>() {
@Override
public void execute(EditingTarget arg) {
continuation.execute();
}
});
}
});
}
// decrement newTabPending and select first tab when done
openCommands.addCommand(new SerializedCommand() {
@Override
public void onExecute(Command continuation) {
newTabPending_--;
onFirstTab();
continuation.execute();
}
});
// execute the continuation
openCommands.run();
}
}
Aggregations