use of com.google.gwt.animation.client.Animation in project rstudio by rstudio.
the class TextEditingTargetWidget method createToolbar.
private Toolbar createToolbar(TextFileType fileType) {
Toolbar toolbar = new EditingTargetToolbar(commands_, true);
toolbar.addLeftWidget(commands_.saveSourceDoc().createToolbarButton());
sourceOnSave_.getElement().getStyle().setMarginRight(0, Unit.PX);
toolbar.addLeftWidget(sourceOnSave_);
srcOnSaveLabel_.getElement().getStyle().setMarginRight(9, Unit.PX);
toolbar.addLeftWidget(srcOnSaveLabel_);
toolbar.addLeftSeparator();
toolbar.addLeftWidget(commands_.checkSpelling().createToolbarButton());
toolbar.addLeftWidget(findReplace_.createFindReplaceButton());
toolbar.addLeftWidget(createCodeTransformMenuButton());
notebookSeparatorWidget_ = toolbar.addLeftSeparator();
toolbar.addLeftWidget(notebookToolbarButton_ = commands_.compileNotebook().createToolbarButton());
int mod = BrowseCap.hasMetaKey() ? KeyboardShortcut.META : KeyboardShortcut.CTRL;
String cmdText = new KeyboardShortcut(mod + KeyboardShortcut.SHIFT, 'K').toString(true);
cmdText = DomUtils.htmlToText(cmdText);
notebookToolbarButton_.setTitle("Compile Report (" + cmdText + ")");
texSeparatorWidget_ = toolbar.addLeftSeparator();
toolbar.addLeftWidget(texToolbarButton_ = createLatexFormatButton());
toolbar.addLeftSeparator();
toolbar.addLeftWidget(previewHTMLButton_ = commands_.previewHTML().createToolbarButton());
knitDocumentButton_ = commands_.knitDocument().createToolbarButton(false);
knitDocumentButton_.getElement().getStyle().setMarginRight(0, Unit.PX);
toolbar.addLeftWidget(knitDocumentButton_);
toolbar.addLeftWidget(compilePdfButton_ = commands_.compilePDF().createToolbarButton());
rmdFormatButton_ = new ToolbarPopupMenuButton(false, true);
rmdFormatButton_.getMenu().setAutoOpen(true);
toolbar.addLeftWidget(rmdFormatButton_);
runDocumentMenuButton_ = new ToolbarPopupMenuButton(false, true);
addClearKnitrCacheMenu(runDocumentMenuButton_);
runDocumentMenuButton_.addSeparator();
runDocumentMenuButton_.addMenuItem(commands_.clearPrerenderedOutput().createMenuItem(false), "");
toolbar.addLeftWidget(runDocumentMenuButton_);
runDocumentMenuButton_.setVisible(false);
ToolbarPopupMenu rmdOptionsMenu = new ToolbarPopupMenu();
rmdOptionsMenu.addItem(commands_.editRmdFormatOptions().createMenuItem(false));
rmdOptionsButton_ = new ToolbarButton(null, new ImageResource2x(StandardIcons.INSTANCE.options2x()), rmdOptionsMenu, false);
toolbar.addLeftWidget(rmdOptionsButton_);
toolbar.addLeftSeparator();
toolbar.addLeftWidget(commands_.synctexSearch().createToolbarButton());
// create menu of chunk skeletons based on common engine types
ToolbarPopupMenu insertChunksMenu = new ToolbarPopupMenu();
insertChunksMenu.addItem(commands_.insertChunkR().createMenuItem(false));
insertChunksMenu.addSeparator();
if (!BrowseCap.isWindowsDesktop()) {
insertChunksMenu.addItem(commands_.insertChunkBash().createMenuItem(false));
}
insertChunksMenu.addItem(commands_.insertChunkPython().createMenuItem(false));
insertChunksMenu.addItem(commands_.insertChunkRCPP().createMenuItem(false));
insertChunksMenu.addItem(commands_.insertChunkSQL().createMenuItem(false));
insertChunksMenu.addItem(commands_.insertChunkStan().createMenuItem(false));
insertChunkMenu_ = new ToolbarButton("Insert", commands_.insertChunk().getImageResource(), insertChunksMenu, true);
toolbar.addRightWidget(insertChunkMenu_);
// create button that just runs default chunk insertion
insertChunkButton_ = commands_.insertChunk().createToolbarButton(false);
toolbar.addRightWidget(insertChunkButton_);
toolbar.addRightWidget(runButton_ = commands_.executeCode().createToolbarButton(false));
toolbar.addRightSeparator();
toolbar.addRightWidget(runLastButton_ = commands_.executeLastCode().createToolbarButton(false));
toolbar.addRightWidget(goToPrevButton_ = commands_.goToPrevSection().createToolbarButton(false));
toolbar.addRightWidget(goToNextButton_ = commands_.goToNextSection().createToolbarButton(false));
toolbar.addRightSeparator();
final String SOURCE_BUTTON_TITLE = "Source the active document";
sourceButton_ = new ToolbarButton("Source", commands_.sourceActiveDocument().getImageResource(), new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (uiPrefs_.sourceWithEcho().getValue())
commands_.sourceActiveDocumentWithEcho().execute();
else
commands_.sourceActiveDocument().execute();
}
});
sourceButton_.setTitle(SOURCE_BUTTON_TITLE);
toolbar.addRightWidget(sourceButton_);
uiPrefs_.sourceWithEcho().addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
if (event.getValue())
sourceButton_.setTitle(SOURCE_BUTTON_TITLE + " (with echo)");
else
sourceButton_.setTitle(SOURCE_BUTTON_TITLE);
}
});
ToolbarPopupMenu sourceMenu = new ToolbarPopupMenu();
sourceMenu.addItem(commands_.sourceActiveDocument().createMenuItem(false));
sourceMenu.addItem(commands_.sourceActiveDocumentWithEcho().createMenuItem(false));
sourceMenuButton_ = new ToolbarButton(sourceMenu, true);
toolbar.addRightWidget(sourceMenuButton_);
//toolbar.addRightSeparator();
ToolbarPopupMenu chunksMenu = new ToolbarPopupMenu();
chunksMenu.addItem(commands_.executeCode().createMenuItem(false));
chunksMenu.addSeparator();
chunksMenu.addItem(commands_.executeCurrentChunk().createMenuItem(false));
chunksMenu.addItem(commands_.executeNextChunk().createMenuItem(false));
chunksMenu.addSeparator();
chunksMenu.addItem(commands_.executeSetupChunk().createMenuItem(false));
chunksMenu.addItem(runSetupChunkOptionMenu_ = new UIPrefMenuItem<Boolean>(uiPrefs_.autoRunSetupChunk(), true, "Run Setup Chunk Automatically", uiPrefs_));
chunksMenu.addSeparator();
chunksMenu.addItem(commands_.executePreviousChunks().createMenuItem(false));
chunksMenu.addItem(commands_.executeSubsequentChunks().createMenuItem(false));
if (uiPrefs_.showRmdChunkOutputInline().getValue()) {
chunksMenu.addSeparator();
chunksMenu.addItem(commands_.restartRRunAllChunks().createMenuItem(false));
chunksMenu.addItem(commands_.restartRClearOutput().createMenuItem(false));
}
chunksMenu.addSeparator();
chunksMenu.addItem(commands_.executeAllCode().createMenuItem(false));
chunksButton_ = new ToolbarButton("Run", commands_.executeCode().getImageResource(), chunksMenu, true);
toolbar.addRightWidget(chunksButton_);
ToolbarPopupMenu shinyLaunchMenu = shinyViewerMenu_;
shinyLaunchButton_ = new ToolbarButton(shinyLaunchMenu, true);
shinyLaunchButton_.setVisible(false);
toolbar.addRightWidget(shinyLaunchButton_);
if (SessionUtils.showPublishUi(session_, uiPrefs_)) {
toolbar.addRightSeparator();
publishButton_ = new RSConnectPublishButton(RSConnect.CONTENT_TYPE_APP, false, null);
toolbar.addRightWidget(publishButton_);
}
toggleDocOutlineButton_ = new LatchingToolbarButton("", new ImageResource2x(StandardIcons.INSTANCE.outline2x()), new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final double initialSize = editorPanel_.getWidgetSize(docOutlineWidget_);
// Clicking the icon toggles the outline widget's visibility. The
// 'destination' below is the width we would like to set -- we
// animate to that position for a slightly nicer visual treatment.
final double destination = docOutlineWidget_.getOffsetWidth() > 5 ? 0 : Math.min(editorPanel_.getOffsetWidth(), target_.getPreferredOutlineWidgetSize());
// Update tooltip ('Show'/'Hide' depending on current visibility)
String title = toggleDocOutlineButton_.getTitle();
if (destination != 0)
title = title.replace("Show ", "Hide ");
else
title = title.replace("Hide ", "Show ");
toggleDocOutlineButton_.setTitle(title);
toggleDocOutlineButton_.setLatched(destination != 0);
new Animation() {
@Override
protected void onUpdate(double progress) {
double size = destination * progress + initialSize * (1 - progress);
editorPanel_.setWidgetSize(docOutlineWidget_, size);
editor_.onResize();
}
@Override
protected void onComplete() {
target_.setPreferredOutlineWidgetVisibility(destination != 0);
}
}.run(500);
}
});
// Time-out setting the latch just to ensure the document outline
// has actually been appropriately rendered.
new Timer() {
@Override
public void run() {
String title = commands_.toggleDocumentOutline().getTooltip();
title = editorPanel_.getWidgetSize(docOutlineWidget_) > 0 ? title.replace("Show ", "Hide ") : title.replace("Hide ", "Show ");
toggleDocOutlineButton_.setTitle(title);
toggleDocOutlineButton_.setLatched(docOutlineWidget_.getOffsetWidth() > 0);
}
}.schedule(100);
toolbar.addRightSeparator();
toolbar.addRightWidget(toggleDocOutlineButton_);
return toolbar;
}
Aggregations