use of org.rstudio.studio.client.rsconnect.ui.RSConnectPublishButton in project rstudio by rstudio.
the class HTMLPreviewPanel method createToolbar.
private Toolbar createToolbar(Commands commands) {
Toolbar toolbar = new Toolbar();
toolbar.addLeftWidget(new ToolbarLabel("Preview: "));
fileLabel_ = new ToolbarLabel();
fileLabel_.addStyleName(ThemeStyles.INSTANCE.subtitle());
fileLabel_.getElement().getStyle().setMarginRight(7, Unit.PX);
toolbar.addLeftWidget(fileLabel_);
toolbar.addLeftSeparator();
toolbar.addLeftWidget(commands.openHtmlExternal().createToolbarButton());
showLogButtonSeparator_ = toolbar.addLeftSeparator();
showLogButton_ = commands.showHtmlPreviewLog().createToolbarButton();
toolbar.addLeftWidget(showLogButton_);
saveHtmlPreviewAsSeparator_ = toolbar.addLeftSeparator();
if (Desktop.isDesktop()) {
saveHtmlPreviewAs_ = commands.saveHtmlPreviewAs().createToolbarButton();
toolbar.addLeftWidget(saveHtmlPreviewAs_);
} else {
ToolbarPopupMenu menu = new ToolbarPopupMenu();
menu.addItem(commands.saveHtmlPreviewAs().createMenuItem(false));
menu.addItem(commands.saveHtmlPreviewAsLocalFile().createMenuItem(false));
saveHtmlPreviewAs_ = toolbar.addLeftWidget(new ToolbarButton("Save As", commands.saveSourceDoc().getImageResource(), menu));
}
publishButtonSeparator_ = toolbar.addLeftSeparator();
toolbar.addLeftWidget(publishButton_ = new RSConnectPublishButton(RSConnect.CONTENT_TYPE_DOCUMENT, true, null));
findTextBox_ = new FindTextBox("Find");
findTextBox_.setIconVisible(true);
findTextBox_.setOverrideWidth(120);
findTextBox_.getElement().getStyle().setMarginRight(6, Unit.PX);
toolbar.addRightWidget(findTextBox_);
findTextBox_.addKeyDownHandler(new KeyDownHandler() {
@Override
public void onKeyDown(KeyDownEvent event) {
// enter key triggers a find
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
event.preventDefault();
event.stopPropagation();
findInTopic(findTextBox_.getValue().trim(), findTextBox_);
findTextBox_.focus();
} else if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) {
findTextBox_.setValue("");
}
}
private void findInTopic(String term, CanFocus findInputSource) {
// get content window
WindowEx contentWindow = previewFrame_.getWindow();
if (contentWindow == null)
return;
if (!contentWindow.find(term, false, false, true, false)) {
RStudioGinjector.INSTANCE.getGlobalDisplay().showMessage(MessageDialog.INFO, "Find in Page", "No occurences found", findInputSource);
}
}
});
refreshButtonSeparator_ = toolbar.addRightSeparator();
refreshButton_ = toolbar.addRightWidget(commands.refreshHtmlPreview().createToolbarButton());
return toolbar;
}
use of org.rstudio.studio.client.rsconnect.ui.RSConnectPublishButton 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;
}
use of org.rstudio.studio.client.rsconnect.ui.RSConnectPublishButton in project rstudio by rstudio.
the class ViewerPane method createMainToolbar.
@Override
protected Toolbar createMainToolbar() {
toolbar_ = new Toolbar();
// add html widget buttons
toolbar_.addLeftWidget(commands_.viewerBack().createToolbarButton());
toolbar_.addLeftWidget(commands_.viewerForward().createToolbarButton());
toolbar_.addLeftSeparator();
toolbar_.addLeftWidget(commands_.viewerZoom().createToolbarButton());
// export commands
exportButtonSeparator_ = toolbar_.addLeftSeparator();
ToolbarPopupMenu exportMenu = new ToolbarPopupMenu();
exportMenu.addItem(commands_.viewerSaveAsImage().createMenuItem(false));
exportMenu.addItem(commands_.viewerCopyToClipboard().createMenuItem(false));
exportMenu.addSeparator();
exportMenu.addItem(commands_.viewerSaveAsWebPage().createMenuItem(false));
exportButton_ = new ToolbarButton("Export", new ImageResource2x(StandardIcons.INSTANCE.export_menu2x()), exportMenu);
toolbar_.addLeftWidget(exportButton_);
exportButton_.setVisible(false);
exportButtonSeparator_.setVisible(false);
toolbar_.addLeftSeparator();
toolbar_.addLeftWidget(commands_.viewerClear().createToolbarButton());
toolbar_.addLeftSeparator();
toolbar_.addLeftWidget(commands_.viewerClearAll().createToolbarButton());
toolbar_.addLeftSeparator();
toolbar_.addLeftWidget(commands_.viewerPopout().createToolbarButton());
toolbar_.addLeftSeparator();
toolbar_.addLeftWidget(commands_.viewerStop().createToolbarButton());
// add publish button
publishButton_ = new RSConnectPublishButton(RSConnect.CONTENT_TYPE_DOCUMENT, true, null);
toolbar_.addRightWidget(publishButton_);
toolbar_.addRightSeparator();
toolbar_.addRightWidget(commands_.viewerRefresh().createToolbarButton());
// create an HTML generator
publishButton_.setPublishHtmlSource(new PublishHtmlSource() {
@Override
public void generatePublishHtml(final CommandWithArg<String> onCompleted) {
server_.viewerCreateRPubsHtml(getTitle(), "", new ServerRequestCallback<String>() {
@Override
public void onResponseReceived(String htmlFile) {
onCompleted.execute(htmlFile);
}
@Override
public void onError(ServerError error) {
globalDisplay_.showErrorMessage("Could Not Publish", error.getMessage());
}
});
}
@Override
public String getTitle() {
String title = frame_.getTitle();
if (StringUtil.isNullOrEmpty(title))
title = "Viewer Content";
return title;
}
});
return toolbar_;
}
Aggregations