Search in sources :

Example 1 with WindowEx

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

the class CopyPlotToClipboardDesktopDialog method copyAsBitmap.

protected void copyAsBitmap(final Operation onCompleted) {
    final ExportPlotSizeEditor sizeEditor = getSizeEditor();
    sizeEditor.prepareForExport(new Command() {

        @Override
        public void execute() {
            if (BrowseCap.isCocoaDesktop()) {
                clipboard_.copyPlotToCocoaPasteboard(sizeEditor.getImageWidth(), sizeEditor.getImageHeight(), new Command() {

                    @Override
                    public void execute() {
                        onCompleted.execute();
                    }
                });
            } else {
                WindowEx win = sizeEditor.getPreviewIFrame().getContentWindow();
                Document doc = win.getDocument();
                NodeList<Element> images = doc.getElementsByTagName("img");
                if (images.getLength() > 0) {
                    ElementEx img = images.getItem(0).cast();
                    DesktopFrame frame = Desktop.getFrame();
                    frame.copyImageToClipboard(img.getClientLeft(), img.getClientTop(), img.getClientWidth(), img.getClientHeight());
                }
                onCompleted.execute();
            }
        }
    });
}
Also used : Command(com.google.gwt.user.client.Command) ElementEx(org.rstudio.core.client.dom.ElementEx) NodeList(com.google.gwt.dom.client.NodeList) WindowEx(org.rstudio.core.client.dom.WindowEx) Document(com.google.gwt.dom.client.Document) DesktopFrame(org.rstudio.studio.client.application.DesktopFrame) ExportPlotSizeEditor(org.rstudio.studio.client.workbench.exportplot.ExportPlotSizeEditor)

Example 2 with WindowEx

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

the class SourceWindowManager method getLastFocusedSourceWindow.

private WindowEx getLastFocusedSourceWindow() {
    String lastFocusedSourceWindow = MainWindowObject.lastFocusedSourceWindow().get();
    // addressable window, there's nothing to do
    if (StringUtil.isNullOrEmpty(lastFocusedSourceWindow) || !isSourceWindowOpen(lastFocusedSourceWindow))
        return null;
    WindowEx window = getSourceWindowObject(lastFocusedSourceWindow);
    if (window != null && !window.isClosed()) {
        return window;
    }
    return null;
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) WindowEx(org.rstudio.core.client.dom.WindowEx)

Example 3 with WindowEx

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

the class SourceWindowManager method openSourceWindow.

private void openSourceWindow(String windowId, Point position, String docId, SourcePosition sourcePosition) {
    // create default options
    Size size = new Size(800, 800);
    Integer ordinal = null;
    // if we have geometry for the window, apply it
    SatelliteWindowGeometry geometry = windowGeometry_.getObject(windowId);
    if (geometry != null) {
        size = geometry.getSize();
        ordinal = geometry.getOrdinal();
        if (position == null)
            position = geometry.getPosition();
    }
    // window may exactly overlap an existing source window)
    if (geometry == null) {
        if (!StringUtil.isNullOrEmpty(mostRecentSourceWindow_) && isSourceWindowOpen(mostRecentSourceWindow_)) {
            WindowEx window = getSourceWindowObject(mostRecentSourceWindow_);
            if (window != null && !window.isClosed()) {
                size = new Size(window.getInnerWidth(), window.getInnerHeight());
                if (position == null)
                    position = new Point(window.getScreenX() + 50, window.getScreenY() + 50);
            }
        }
    }
    // assign ordinal if not already assigned
    if (ordinal == null)
        ordinal = ++maxOrdinal_;
    pSatelliteManager_.get().openSatellite(SourceSatellite.NAME_PREFIX + windowId, SourceWindowParams.create(ordinal, pWorkbenchContext_.get().createWindowTitle(), pWorkbenchContext_.get().getCurrentWorkingDir().getPath(), docId, sourcePosition), size, false, position);
    mostRecentSourceWindow_ = windowId;
    sourceWindows_.put(windowId, ordinal);
}
Also used : SatelliteWindowGeometry(org.rstudio.studio.client.common.satellite.model.SatelliteWindowGeometry) WindowEx(org.rstudio.core.client.dom.WindowEx)

Example 4 with WindowEx

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

the class SourceWindowManager method handleUnsavedChangesBeforeExit.

public void handleUnsavedChangesBeforeExit(ArrayList<UnsavedChangesTarget> targets, Command onCompleted) {
    // accumulate the unsaved change targets that represent satellite windows
    final JsArray<UnsavedChangesItem> items = JsArray.createArray().cast();
    for (UnsavedChangesTarget target : targets) {
        if (target instanceof UnsavedChangesItem) {
            items.push((UnsavedChangesItem) target);
        }
    }
    // let each window have a crack at saving the targets (the windows will
    // discard any targets they don't own)
    doForAllSourceWindows(new SourceWindowCommand() {

        @Override
        public void execute(String windowId, WindowEx window, Command continuation) {
            handleUnsavedChangesBeforeExit(window, items, continuation);
        }
    }, onCompleted);
}
Also used : UnsavedChangesItem(org.rstudio.studio.client.workbench.model.UnsavedChangesItem) UnsavedChangesTarget(org.rstudio.studio.client.workbench.model.UnsavedChangesTarget) Command(com.google.gwt.user.client.Command) JsArrayString(com.google.gwt.core.client.JsArrayString) WindowEx(org.rstudio.core.client.dom.WindowEx)

Example 5 with WindowEx

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

the class SourceWindowManager method doForAllSourceWindows.

// execute a command on all source windows (synchronously)
private void doForAllSourceWindows(OperationWithInput<Pair<String, WindowEx>> command) {
    for (final String windowId : sourceWindows_.keySet()) {
        final WindowEx window = getSourceWindowObject(windowId);
        if (window == null || window.isClosed())
            continue;
        command.execute(new Pair<String, WindowEx>(windowId, window));
    }
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) WindowEx(org.rstudio.core.client.dom.WindowEx)

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