Meta-/ (tree-view:toggle) attaches / detaches the TreeView

This commit is contained in:
Nathan Sobo 2012-05-08 15:35:03 -06:00
parent 79315b0ef6
commit 897f505e4f
3 changed files with 27 additions and 1 deletions

View File

@ -96,6 +96,19 @@ describe "TreeView", ->
newTreeView = newRootView.find(".tree-view").view()
expect(newTreeView).toMatchSelector ':focus'
describe "when tree-view:toggle is triggered on the root view", ->
it "shows/hides the tree view", ->
rootView.attachToDom()
treeView.focus()
expect(treeView.hasParent()).toBeTruthy()
rootView.trigger 'tree-view:toggle'
expect(treeView.hasParent()).toBeFalsy()
expect(rootView).toMatchSelector(':focus')
rootView.trigger 'tree-view:toggle'
expect(treeView.hasParent()).toBeTruthy()
expect(treeView).toMatchSelector(':focus')
describe "when a directory's disclosure arrow is clicked", ->
it "expands / collapses the associated directory", ->
subdir = treeView.root.find('.entries > li:contains(dir/)').view()

View File

@ -1,5 +1,6 @@
window.keymap.bindKeys '#root-view'
'alt-tab': 'tree-view:focus'
'meta-/': 'tree-view:toggle'
window.keymap.bindKeys '.tree-view'
'right': 'tree-view:expand-directory'

View File

@ -18,7 +18,7 @@ class TreeView extends View
else
@instance = new TreeView(rootView)
rootView.horizontal.prepend(@instance)
@instance.attach()
@serialize: ->
@instance.serialize()
@ -49,6 +49,7 @@ class TreeView extends View
@on 'tree-view:add', => @add()
@on 'tree-view:remove', => @removeSelectedEntry()
@on 'tree-view:directory-modified', => @selectActiveFile()
@rootView.on 'tree-view:toggle', => @toggle()
@rootView.on 'active-editor-path-change', => @selectActiveFile()
@rootView.project.on 'path-change', => @updateRoot()
@ -66,6 +67,17 @@ class TreeView extends View
deactivate: ->
@root?.unwatchEntries()
toggle: ->
if @hasParent()
@detach()
@rootView.focus()
else
@attach()
@focus()
attach: ->
@rootView.horizontal.prepend(this)
entryClicked: (e) ->
entry = $(e.currentTarget).view()
switch e.originalEvent?.detail ? 1