TreeView doesn't raise exceptions when RootView's project has no path.

This commit is contained in:
Corey Johnson
2012-05-08 09:02:35 -07:00
parent af2263f49b
commit 7e32d73d73
2 changed files with 26 additions and 15 deletions

View File

@@ -26,7 +26,8 @@ class TreeView extends View
@content: (rootView) ->
@div class: 'tree-view', tabindex: -1, =>
@subview 'root', new DirectoryView(directory: rootView.project.getRootDirectory(), isExpanded: true)
if rootView.project.getRootDirectory()
@subview 'root', new DirectoryView(directory: rootView.project.getRootDirectory(), isExpanded: true)
@deserialize: (state, rootView) ->
treeView = new TreeView(rootView)
@@ -39,19 +40,7 @@ class TreeView extends View
focusAfterAttach: false
initialize: (@rootView) ->
@on 'click', '.entry', (e) =>
entry = $(e.currentTarget).view()
switch e.originalEvent?.detail ? 1
when 1
@selectEntry(entry)
@openSelectedEntry() if (entry instanceof FileView)
when 2
if entry.is('.selected.file')
@rootView.activeEditor().focus()
else if entry.is('.selected.directory')
entry.toggleExpansion()
false
@on 'click', '.entry', (e) => @entryClicked(e)
@on 'move-up', => @moveUp()
@on 'move-down', => @moveDown()
@on 'tree-view:expand-directory', => @expandDirectory()
@@ -75,7 +64,21 @@ class TreeView extends View
hasFocus: @is(':focus')
deactivate: ->
@root.unwatchEntries()
@root?.unwatchEntries()
entryClicked: (e) ->
entry = $(e.currentTarget).view()
switch e.originalEvent?.detail ? 1
when 1
@selectEntry(entry)
@openSelectedEntry() if (entry instanceof FileView)
when 2
if entry.is('.selected.file')
@rootView.activeEditor().focus()
else if entry.is('.selected.directory')
entry.toggleExpansion()
false
selectActiveFile: ->
activeFilePath = @rootView.activeEditor()?.buffer.path