Skip to content

Commit

Permalink
close all satellites when the main window is closed or otherwise disc…
Browse files Browse the repository at this point in the history
…onnected
  • Loading branch information
jjallaire committed Nov 11, 2011
1 parent 007c042 commit 10878fa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Expand Up @@ -87,6 +87,7 @@ public Application(ApplicationView view,
events_ = events;
session_ = session;
commands_ = commands;
satelliteManager_ = satelliteManager;
clientStateUpdater_ = clientStateUpdater;
server_ = server;
uiPrefs_ = uiPrefs;
Expand Down Expand Up @@ -603,6 +604,8 @@ private void showToolbar(boolean showToolbar)

private void cleanupWorkbench()
{
satelliteManager_.closeAllSatellites();

if (clientStateUpdaterInstance_ != null)
{
clientStateUpdaterInstance_.suspend();
Expand All @@ -620,6 +623,7 @@ private void navigateToSignIn()
private final EventBus events_;
private final Session session_;
private final Commands commands_;
private final SatelliteManager satelliteManager_;
private final Provider<ClientStateUpdater> clientStateUpdater_;
private final Server server_;
private final Provider<UIPrefs> uiPrefs_;
Expand Down
26 changes: 18 additions & 8 deletions src/gwt/src/org/rstudio/studio/client/common/SatelliteManager.java
Expand Up @@ -20,31 +20,33 @@ public SatelliteManager()

}

// the main window should call this method during startup to set itself
// up to manage and communicate with the satellite windows
public void initMainWindow()
{
// export the registration hook used by satellites
exportSatelliteRegistrationCallback();

// handle onClosed to automatically close all satellites
Window.addCloseHandler(this);

}



// satellite windows should call this during startup to setup a
// communication channel with the main window
public native void initSatelliteWindow() /*-{
$wnd.isRStudioSatellite = true;
$wnd.opener.registerAsRStudioSatellite($wnd);
}-*/;


// check whether the current window is a satellite
public native boolean isCurrentWindowSatellite() /*-{
return !!$wnd.isRStudioSatellite;
}-*/;

// close all satellites when we are closed
@Override
public void onClose(CloseEvent<Window> event)

// close all satellite windows
public void closeAllSatellites()
{
for (int i=0; i<satellites_.size(); i++)
{
Expand All @@ -57,16 +59,24 @@ public void onClose(CloseEvent<Window> event)
{
}
}
satellites_.clear();
}

// close all satellites when we are closed
@Override
public void onClose(CloseEvent<Window> event)
{
closeAllSatellites();
}


// called by satellites to connect themselves with the main window
private void registerAsSatellite(JavaScriptObject wnd)
{
WindowEx satelliteWnd = wnd.<WindowEx>cast();
satellites_.add(satelliteWnd);
}

// export the global function requried for satellites to register
private native void exportSatelliteRegistrationCallback() /*-{
var manager = this;
$wnd.registerAsRStudioSatellite = $entry(
Expand Down

0 comments on commit 10878fa

Please sign in to comment.