Search in sources :

Example 1 with SatelliteManager

use of org.rstudio.studio.client.common.satellite.SatelliteManager in project rstudio by rstudio.

the class AppCommand method doExecute.

private void doExecute() {
    assert enabled_ : "AppCommand executed when it was not enabled";
    if (!enabled_)
        return;
    assert visible_ : "AppCommand executed when it was not visible";
    if (!visible_)
        return;
    // if this window is a satellite but the command only wants to be handled
    // in the a different window, execute the command there instead
    Satellite satellite = RStudioGinjector.INSTANCE.getSatellite();
    if (getWindowMode() != WINDOW_MODE_ANY && Satellite.isCurrentWindowSatellite() && satellite.getSatelliteName() != getWindowMode()) {
        if (getWindowMode().equals(WINDOW_MODE_MAIN)) {
            // raise the main window if it's not a background command
            satellite.focusMainWindow();
        } else if (getWindowMode().equals(WINDOW_MODE_BACKGROUND) && Desktop.isDesktop()) {
            // for background commands, we still want the main window to be
            // as visible as possible, so bring it up behind the current window
            // (this is of course only possible in desktop mode)
            Desktop.getFrame().bringMainFrameBehindActive();
        }
        // satellites don't fire commands peer-to-peer--route it to the main
        // window for processing
        SatelliteManager mgr = RStudioGinjector.INSTANCE.getSatelliteManager();
        mgr.dispatchCommand(this, null);
        return;
    }
    if (enableNoHandlerAssertions_) {
        assert handlers_.getHandlerCount(CommandEvent.TYPE) > 0 : "AppCommand executed but nobody was listening";
    }
    handlers_.fireEvent(new CommandEvent(this));
}
Also used : SatelliteManager(org.rstudio.studio.client.common.satellite.SatelliteManager) Satellite(org.rstudio.studio.client.common.satellite.Satellite)

Example 2 with SatelliteManager

use of org.rstudio.studio.client.common.satellite.SatelliteManager in project rstudio by rstudio.

the class WindowCloseMonitor method monitorSatelliteClosure.

// When a window is unloaded; it could be that the window is unloading for
// refresh or closing for good. To distinguish between the two cases, we ping
// the window for 5 seconds after receiving the unload.
public static void monitorSatelliteClosure(final String windowName, final Command onClosed, final Command onOpen) {
    final SatelliteManager satelliteManager = RStudioGinjector.INSTANCE.getSatelliteManager();
    final WindowEx window = satelliteManager.getSatelliteWindowObject(windowName);
    Scheduler.get().scheduleFixedDelay(new Scheduler.RepeatingCommand() {

        @Override
        public boolean execute() {
            if (window == null || window.isClosed() || satelliteManager.getSatelliteWindowObject(windowName) == null) {
                onClosed.execute();
                return false;
            }
            // retry up to 5 seconds (250ms per try)
            if (retries_++ < 20) {
                return true;
            } else {
                if (onOpen != null)
                    onOpen.execute();
                return false;
            }
        }

        private int retries_ = 0;
    }, 250);
}
Also used : SatelliteManager(org.rstudio.studio.client.common.satellite.SatelliteManager) Scheduler(com.google.gwt.core.client.Scheduler)

Aggregations

SatelliteManager (org.rstudio.studio.client.common.satellite.SatelliteManager)2 Scheduler (com.google.gwt.core.client.Scheduler)1 Satellite (org.rstudio.studio.client.common.satellite.Satellite)1