Search in sources :

Example 21 with WindowEx

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

the class PDFViewer method openPdfUrl.

// Private methods ---------------------------------------------------------
private void openPdfUrl(final String url, final boolean synctex, boolean restorePosition) {
    int width = 1070;
    int height = 1200;
    Point pos = null;
    // if there's a window open, restore the position when we're done
    if (restorePosition && url.equals(lastSuccessfulPdfUrl_)) {
        // the window closed
        if (haveActivePdfJsWindow())
            locationHash_ = pdfJsWindow_.getLocationHash();
        executeOnPdfLoad_ = createRestorePositionOperation();
    }
    // create the operation to load the PDF--we'll call this when the window
    // is finished opening, or immediately if there's already a window open
    Operation loadPdf = new Operation() {

        @Override
        public void execute() {
            pdfJsWindow_.openPdf(server_.getApplicationURL(url), 0, synctex);
            lastSuccessfulPdfUrl_ = url;
        }
    };
    // in the browser we need to close and reopen the window
    if (haveActivePdfJsWindow() && !Desktop.isDesktop()) {
        width = pdfJsWindow_.getOuterWidth();
        height = pdfJsWindow_.getOuterHeight();
        pos = new Point(pdfJsWindow_.getLeft(), pdfJsWindow_.getTop());
        pdfJsWindow_.close();
        pdfJsWindow_ = null;
    }
    lastSuccessfulPdfUrl_ = null;
    if (!haveActivePdfJsWindow()) {
        // open the window and continue
        String viewerUrl = server_.getApplicationURL("pdf_js/web/viewer.html?file=");
        NewWindowOptions options = new NewWindowOptions();
        options.setName(WINDOW_NAME);
        options.setShowDesktopToolbar(false);
        if (pos != null)
            options.setPosition(pos);
        options.setCallback(new OperationWithInput<WindowEx>() {

            @Override
            public void execute(WindowEx win) {
                initializePdfJsWindow(win);
            }
        });
        executeOnPdfJsLoad_ = loadPdf;
        if (Desktop.isDesktop() && Desktop.getFrame().isCocoa()) {
            // on cocoa, we can open a native window
            display_.openMinimalWindow(viewerUrl, false, width, height, options);
        } else {
            // on Qt, we need to open a web window so window.opener is wired
            display_.openWebMinimalWindow(viewerUrl, false, width, height, options);
        }
    } else {
        // we already have an open window, activate it
        if (Desktop.isDesktop())
            Desktop.getFrame().activateMinimalWindow(WINDOW_NAME);
        loadPdf.execute();
    }
}
Also used : NewWindowOptions(org.rstudio.studio.client.common.GlobalDisplay.NewWindowOptions) Point(org.rstudio.core.client.Point) Operation(org.rstudio.core.client.widget.Operation) WindowEx(org.rstudio.core.client.dom.WindowEx) Point(org.rstudio.core.client.Point)

Example 22 with WindowEx

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

the class ShinyApplication method activateWindow.

private void activateWindow(ShinyApplicationParams params) {
    WindowEx win = satelliteManager_.getSatelliteWindowObject(ShinyApplicationSatellite.NAME);
    boolean isRefresh = win != null && (params == null || (params_ != null && params.getPath().equals(params_.getPath())));
    boolean isChrome = !Desktop.isDesktop() && BrowseCap.isChrome();
    if (params != null)
        params_ = params;
    if (win == null || (!isRefresh && !isChrome)) {
        // If there's no window yet, or we're switching apps in a browser
        // other than Chrome, do a normal open
        satelliteManager_.openSatellite(ShinyApplicationSatellite.NAME, params_, new Size(960, 1100));
    } else if (isChrome) {
        // we have a window and we're Chrome, so force a close and reopen
        satelliteManager_.forceReopenSatellite(ShinyApplicationSatellite.NAME, params_, true);
    } else {
        satelliteManager_.activateSatelliteWindow(ShinyApplicationSatellite.NAME);
    }
}
Also used : Size(org.rstudio.core.client.Size) WindowEx(org.rstudio.core.client.dom.WindowEx)

Example 23 with WindowEx

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

the class HelpPane method createSecondaryToolbar.

@Override
protected SecondaryToolbar createSecondaryToolbar() {
    SecondaryToolbar toolbar = new SecondaryToolbar();
    toolbar.addLeftPopupMenu(title_ = new Label(), history_.getMenu());
    if (isFindSupported()) {
        final SmallButton btnNext = new SmallButton("&gt;", true);
        btnNext.setTitle("Find next (Enter)");
        btnNext.setVisible(false);
        btnNext.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                findNext();
            }
        });
        final SmallButton btnPrev = new SmallButton("&lt;", true);
        btnPrev.setTitle("Find previous");
        btnPrev.setVisible(false);
        btnPrev.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                findPrev();
            }
        });
        findTextBox_ = new FindTextBox("Find in Topic");
        findTextBox_.setOverrideWidth(90);
        toolbar.addLeftWidget(findTextBox_);
        findTextBox_.addKeyUpHandler(new KeyUpHandler() {

            @Override
            public void onKeyUp(KeyUpEvent event) {
                // ignore modifier key release
                if (event.getNativeKeyCode() == KeyCodes.KEY_CTRL || event.getNativeKeyCode() == KeyCodes.KEY_ALT || event.getNativeKeyCode() == KeyCodes.KEY_SHIFT) {
                    return;
                }
                WindowEx contentWindow = getContentWindow();
                if (contentWindow != null) {
                    // into the main content window
                    if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE || event.getNativeKeyCode() == KeyCodes.KEY_TAB) {
                        event.preventDefault();
                        event.stopPropagation();
                        if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE)
                            clearTerm();
                        contentWindow.focus();
                    } else {
                        // minimizing or maximizing the help pane
                        if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                            event.preventDefault();
                            event.stopPropagation();
                        }
                        // check for term
                        String term = findTextBox_.getValue().trim();
                        int modifier = KeyboardShortcut.getModifierValue(event.getNativeEvent());
                        boolean isShift = modifier == KeyboardShortcut.SHIFT;
                        // if there is a term then search for it
                        if (term.length() > 0) {
                            // make buttons visible
                            setButtonVisibility(true);
                            // perform the find (check for incremental)
                            if (isIncrementalFindSupported()) {
                                boolean incremental = !event.isAnyModifierKeyDown() && (event.getNativeKeyCode() != KeyCodes.KEY_ENTER);
                                performFind(term, !isShift, incremental);
                            } else {
                                if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER)
                                    performFind(term, !isShift, false);
                            }
                        } else // no term means clear term and remove selection
                        {
                            if (isIncrementalFindSupported()) {
                                clearTerm();
                                contentWindow.removeSelection();
                            }
                        }
                    }
                }
            }

            private void clearTerm() {
                findTextBox_.setValue("");
                setButtonVisibility(false);
            }

            private void setButtonVisibility(final boolean visible) {
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                    @Override
                    public void execute() {
                        btnNext.setVisible(visible);
                        btnPrev.setVisible(visible);
                    }
                });
            }
        });
        findTextBox_.addKeyDownHandler(new KeyDownHandler() {

            @Override
            public void onKeyDown(KeyDownEvent event) {
                // from handling them
                if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE || event.getNativeKeyCode() == KeyCodes.KEY_TAB || event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                    event.preventDefault();
                    event.stopPropagation();
                }
            }
        });
        if (isIncrementalFindSupported()) {
            btnPrev.getElement().getStyle().setMarginRight(3, Unit.PX);
            toolbar.addLeftWidget(btnPrev);
            toolbar.addLeftWidget(btnNext);
        }
    }
    return toolbar;
}
Also used : KeyUpEvent(com.google.gwt.event.dom.client.KeyUpEvent) KeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) KeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) NativeKeyDownEvent(org.rstudio.core.client.events.NativeKeyDownEvent) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) SmallButton(org.rstudio.core.client.widget.SmallButton) SecondaryToolbar(org.rstudio.core.client.widget.SecondaryToolbar) WindowEx(org.rstudio.core.client.dom.WindowEx) FindTextBox(org.rstudio.core.client.widget.FindTextBox)

Example 24 with WindowEx

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

the class HelpPane method performFind.

private void performFind(String term, boolean forwards, boolean incremental) {
    WindowEx contentWindow = getContentWindow();
    if (contentWindow == null)
        return;
    // if this is an incremental search then reset the selection first
    if (incremental)
        contentWindow.removeSelection();
    contentWindow.find(term, false, !forwards, true, false);
}
Also used : WindowEx(org.rstudio.core.client.dom.WindowEx)

Example 25 with WindowEx

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

the class Plots method onZoomPlot.

void onZoomPlot() {
    Size windowSize = ZoomUtils.getZoomWindowSize(view_.getPlotFrameSize(), zoomWindowDefaultSize_);
    // determine whether we should scale (see comment in ImageFrame.onLoad
    // for why we wouldn't want to scale)
    int scale = 1;
    if (Desktop.isDesktop() && BrowseCap.isMacintosh())
        scale = 0;
    // compose url string
    String url = server_.getGraphicsUrl("plot_zoom?" + "width=" + windowSize.width + "&" + "height=" + windowSize.height + "&" + "scale=" + scale);
    // open the window
    ZoomUtils.openZoomWindow("_rstudio_zoom", url, windowSize, new OperationWithInput<WindowEx>() {

        @Override
        public void execute(WindowEx input) {
            zoomWindow_ = input;
        }
    });
}
Also used : Size(org.rstudio.core.client.Size) WindowEx(org.rstudio.core.client.dom.WindowEx) Point(org.rstudio.core.client.Point)

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