Search in sources :

Example 16 with WindowEx

use of org.rstudio.core.client.dom.WindowEx in project rstudio by rstudio.

the class RmdOutput method displayHTMLRenderResult.

private void displayHTMLRenderResult(RmdRenderResult result) {
    // find the last known position for this file
    int scrollPosition = 0;
    String anchor = "";
    if (scrollPositions_.containsKey(keyFromResult(result))) {
        scrollPosition = scrollPositions_.get(keyFromResult(result));
    }
    if (anchors_.containsKey(keyFromResult(result))) {
        anchor = anchors_.get(keyFromResult(result));
    }
    final RmdPreviewParams params = RmdPreviewParams.create(result, scrollPosition, anchor);
    // get the default viewer type from prefs
    int viewerType = prefs_.rmdViewerType().getValue();
    // apply override from result, if any
    if (result.getViewerType() == RmdEditorOptions.PREVIEW_IN_VIEWER)
        viewerType = RMD_VIEWER_TYPE_PANE;
    else if (result.getViewerType() == RmdEditorOptions.PREVIEW_IN_WINDOW)
        viewerType = RMD_VIEWER_TYPE_WINDOW;
    else if (result.getViewerType() == RmdEditorOptions.PREVIEW_IN_NONE)
        viewerType = RMD_VIEWER_TYPE_NONE;
    // slides well without help
    if (result.isHtmlPresentation() && viewerType == RMD_VIEWER_TYPE_PANE)
        viewerType = RMD_VIEWER_TYPE_WINDOW;
    final int newViewerType = viewerType;
    // we don't disturb the publish flow with a window popping up
    if (newViewerType == RMD_VIEWER_TYPE_WINDOW && RSConnectPublishButton.isAnyRmdRenderPending()) {
        return;
    }
    // get the window object if available
    WindowEx win = null;
    boolean needsReopen = false;
    if (outputFrame_ != null) {
        win = outputFrame_.getWindowObject();
        if (outputFrame_.getViewerType() != newViewerType)
            needsReopen = true;
    }
    // close it so that we can create a new one better suited to this doc type
    if (needsReopen || (win != null && result_ != null && !result_.getFormatName().equals(result.getFormatName()))) {
        outputFrame_.closeOutputFrame(false);
        outputFrame_ = null;
        win = null;
        // let window finish closing before continuing
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {

            @Override
            public void execute() {
                displayRenderResult(null, newViewerType, params);
            }
        });
    } else {
        displayRenderResult(win, newViewerType, params);
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) WindowEx(org.rstudio.core.client.dom.WindowEx) RmdPreviewParams(org.rstudio.studio.client.rmarkdown.model.RmdPreviewParams)

Example 17 with WindowEx

use of org.rstudio.core.client.dom.WindowEx in project rstudio by rstudio.

the class RmdOutputFrameSatellite method showRmdPreview.

@Override
public void showRmdPreview(RmdPreviewParams params, boolean activate) {
    super.showRmdPreview(params);
    WindowEx win = getWindowObject();
    if (activate && win != null && !Desktop.isDesktop() && BrowseCap.isChrome()) {
        satelliteManager_.forceReopenSatellite(RmdOutputSatellite.NAME, params, activate);
    } else {
        satelliteManager_.openSatellite(RmdOutputSatellite.NAME, params, params.getPreferredSize(), activate);
    }
}
Also used : WindowEx(org.rstudio.core.client.dom.WindowEx)

Example 18 with WindowEx

use of org.rstudio.core.client.dom.WindowEx in project rstudio by rstudio.

the class RmdOutputPanel method initToolbar.

@Override
protected void initToolbar(Toolbar toolbar, Commands commands) {
    slideNavigationMenu_ = new SlideNavigationToolbarMenu(toolbar, 400, 100, true);
    fileLabel_ = new ToolbarLabel();
    fileLabel_.addStyleName(ThemeStyles.INSTANCE.subtitle());
    fileLabel_.getElement().getStyle().setMarginRight(7, Unit.PX);
    toolbar.addLeftWidget(fileLabel_);
    fileLabelSeparator_ = toolbar.addLeftSeparator();
    ToolbarButton popoutButton = commands.viewerPopout().createToolbarButton();
    popoutButton.setText("Open in Browser");
    toolbar.addLeftWidget(popoutButton);
    findTextBox_ = new FindTextBox("Find");
    findTextBox_.setIconVisible(true);
    findTextBox_.setOverrideWidth(120);
    findTextBox_.getElement().getStyle().setMarginRight(6, Unit.PX);
    findSeparator_ = toolbar.addLeftSeparator();
    toolbar.addLeftWidget(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 = getFrame().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);
            }
        }
    });
    toolbar.addLeftSeparator();
    publishButton_ = new RSConnectPublishButton(RSConnect.CONTENT_TYPE_DOCUMENT, true, null);
    toolbar.addRightWidget(publishButton_);
    toolbar.addRightSeparator();
    toolbar.addRightWidget(commands.viewerRefresh().createToolbarButton());
}
Also used : ToolbarButton(org.rstudio.core.client.widget.ToolbarButton) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) ToolbarLabel(org.rstudio.core.client.widget.ToolbarLabel) KeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler) CanFocus(org.rstudio.core.client.widget.CanFocus) RSConnectPublishButton(org.rstudio.studio.client.rsconnect.ui.RSConnectPublishButton) SlideNavigationToolbarMenu(org.rstudio.studio.client.common.presentation.SlideNavigationToolbarMenu) WindowEx(org.rstudio.core.client.dom.WindowEx) FindTextBox(org.rstudio.core.client.widget.FindTextBox)

Example 19 with WindowEx

use of org.rstudio.core.client.dom.WindowEx in project rstudio by rstudio.

the class HTMLPreviewPanel method print.

@Override
public void print() {
    WindowEx window = previewFrame_.getWindow();
    window.focus();
    window.print();
}
Also used : WindowEx(org.rstudio.core.client.dom.WindowEx)

Example 20 with WindowEx

use of org.rstudio.core.client.dom.WindowEx 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;
}
Also used : ToolbarButton(org.rstudio.core.client.widget.ToolbarButton) ToolbarPopupMenu(org.rstudio.core.client.widget.ToolbarPopupMenu) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) ToolbarLabel(org.rstudio.core.client.widget.ToolbarLabel) RSConnectPublishButton(org.rstudio.studio.client.rsconnect.ui.RSConnectPublishButton) KeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler) CanFocus(org.rstudio.core.client.widget.CanFocus) WindowEx(org.rstudio.core.client.dom.WindowEx) FindTextBox(org.rstudio.core.client.widget.FindTextBox) Toolbar(org.rstudio.core.client.widget.Toolbar)

Aggregations

WindowEx (org.rstudio.core.client.dom.WindowEx)34 JsArrayString (com.google.gwt.core.client.JsArrayString)5 Size (org.rstudio.core.client.Size)5 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)3 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)3 Document (com.google.gwt.dom.client.Document)3 KeyDownEvent (com.google.gwt.event.dom.client.KeyDownEvent)3 KeyDownHandler (com.google.gwt.event.dom.client.KeyDownHandler)3 ArrayList (java.util.ArrayList)3 Point (org.rstudio.core.client.Point)3 FindTextBox (org.rstudio.core.client.widget.FindTextBox)3 NewWindowOptions (org.rstudio.studio.client.common.GlobalDisplay.NewWindowOptions)3 Command (com.google.gwt.user.client.Command)2 ElementEx (org.rstudio.core.client.dom.ElementEx)2 JsObject (org.rstudio.core.client.js.JsObject)2 CanFocus (org.rstudio.core.client.widget.CanFocus)2 Operation (org.rstudio.core.client.widget.Operation)2 ToolbarButton (org.rstudio.core.client.widget.ToolbarButton)2 ToolbarLabel (org.rstudio.core.client.widget.ToolbarLabel)2 SatelliteWindowGeometry (org.rstudio.studio.client.common.satellite.model.SatelliteWindowGeometry)2