       floating : yes
 
     @chat.on "WorkspaceChatClosed", =>
+      @lastActivePaneKey = null
       @updatePaneVisiblityState "chat", no
 
   createTerminalPane: ->


    @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"

    @["create#{paneKey.capitalize()}Pane"]()

  handleLaunch: (paneKey) ->
    pane = @getPaneByType paneKey
    if @lastActivePaneKey is paneKey
      @lastActivePaneKey = null
      @updatePaneVisiblityState paneKey, no
    else
      @lastActivePaneKey = paneKey
      @updatePaneVisiblityState paneKey, yes

  hidePane: (pane, paneKey) ->
    pane.unsetClass "active"

  showPane: (pane, paneKey) ->
    if paneKey is "chat"
      @chat.dock.emit "click"
    else
      pane.setClass "active"

  updatePaneVisiblityState: (paneKey, value) ->
    map          = @paneVisibilityState
