   handleLaunch: (paneKey) ->
     pane = @[paneKey]
     if @lastActivePaneKey is paneKey
-      @hidePane pane
+      @hidePane pane, paneKey
     else
       lastActivePane = @getPaneByType @lastActivePaneKey
-      @hidePane lastActivePane if lastActivePane
+      @hidePane lastActivePane, paneKey, no if lastActivePane
       @showPane pane, paneKey
 
-  hidePane: (pane) ->
+  hidePane: (pane, paneKey, writeToCloud = yes) ->
     pane.unsetClass "active"
     @lastActivePaneKey = null
+    @updatePaneVisiblityState paneKey, no if writeToCloud
 
-  showPane: (pane, paneKey) ->
-    return @chat.dock.emit "click"  if paneKey is "chat"
+  showPane: (pane, paneKey, writeToCloud = yes) ->
+    if paneKey is "chat"
+      @chat.dock.emit "click"
+      return @updatePaneVisiblityState "chat", yes
+
     pane.setClass "active"
     @lastActivePaneKey = paneKey
+    @updatePaneVisiblityState paneKey, yes  if writeToCloud
+
+  updatePaneVisiblityState: (paneKey, value) ->
+    map          = @paneVisibilityState
+    map[key]     = no for own key of map
+    map[paneKey] = value
+
+    @paneStateRef.set map
 
   createChatPane: ->
     @container.addSubView @chat = new ChatPane
       delegate : @panel.getDelegate()
       floating : yes
+
+    @chat.on "WorkspaceChatClosed", =>
+      @updatePaneVisiblityState "chat", no
 
   createTerminalPane: ->
     terminalClass    = SharableTerminalPane


    # options.cssClass = "workspace-launcher"
    # options.partial  = "<span>+</span>"
    options.cssClass  = "workspace-launcher vertical"

    super options, data

    @sessionKeys       = {}
    @panel             = @getDelegate()
    @workspace         = @panel.getDelegate()
    @container         = new KDView cssClass: "workspace-floating-panes"
    @keysRef           = @workspace.workspaceRef.child "floatingPaneKeys"
    @isJoinedASession  = @workspace.getOptions().joinedASession
    @lastActivePaneKey = null

    @panel.addSubView @container


        @createPanes()
    else
      @createPanes()

    @paneStateRef.on "value", (snapshot) =>
      state  = snapshot.val()
      map    = @paneVisibilityState
      return unless state

      for own key, value of state
        pane = @getPaneByType key
        if value is no then @hidePane pane, key, no else @showPane pane, key, no

  click: ->
    @toggleClass "active"
