     [match] = os.filter (o) -> o.id is id
 
     match || null
+
+  removeFromTabs: (id) ->
+    tabsToRemove = []
+    for tab in @tabs()
+      switch tab.type
+        when 'property'
+          o = tab.property.object
+        when 'verb'
+          o = tab.verb.object
+      if o.id is id
+        tabsToRemove.push tab
+
+    @removeTab tab for tab in tabsToRemove
+
+  removeTab: (tab) ->
+    tab.restore()
+    tabIndex = @tabs.indexOf(tab)
+    selectOther = tab.active()
+    @tabs.remove(tab)
+    if selectOther
+      otherTab = @tabs()[tabIndex]
+      if not otherTab? and tabIndex > 0
+        otherTab = @tabs()[tabIndex-1]
+      @selectTab(otherTab) if otherTab?
+
+    if @tabs().length == 0
+      @selectedTab null
 
   #################
   # Context Menus #


  new_object: (obj) =>
    obj.children = []

    insertChild = (o, p) =>
      if p.id == o.parent_id
        p.children.push new TreeNode o, @, p.level+1
        return true
      else
        added = false
        for child in p.children()
          added = insertChild(o, child)
          break if added
        return added

    for o in @objects()
      break if insertChild obj, o

  rm_object: (id) =>
    removeChild = (id, p) =>
      [match] = (child for child in p.children() when child.id is id)
      if match?
        p.children.remove match
        return true
      else
        removed = false
        for child in p.children()
          removed = removeChild(id, child)
          break if removed
        return removed

    for o in @objects()
      break if removeChild id, o

  object_parent_changed: (spec) =>
    console.log 'TODO: object parent changed:', spec

  object_name_changed: (spec) =>
    o = @findInTree spec.id

  #############################

  connect: =>
    # console.log 'Connected!'
    @loadBrowser()

  connecting: =>
    # console.log 'Connecting...'

  disconnect: =>
    # console.log 'Disconnected from server.'
    bootbox.alert 'Disconnected from server.'
    @clearEditor()

  connect_failed: =>
    # console.log 'Connection to server failed.'
    bootbox.alert 'Connection to server failed.'

  error: =>
    # console.log 'An unknown error occurred.'
    bootbox.alert 'An unknown error occurred.'

  reconnect_failed: =>
    # console.log 'Unable to reconnect to server.'
    bootbox.alert 'Unable to reconnect to server.'

  reconnect: =>
    # console.log 'Reconnected!'

  reconnecting: =>
    # console.log 'Attempting to reconnect...'