mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Project drawer state is restored upon refresh
This commit is contained in:
@@ -9,7 +9,9 @@ describe "TreeView", ->
|
||||
beforeEach ->
|
||||
rootView = new RootView(pathToOpen: require.resolve('fixtures/'))
|
||||
project = rootView.project
|
||||
treeView = new TreeView(rootView)
|
||||
|
||||
rootView.registerExtension(TreeView)
|
||||
treeView = rootView.find(".tree-view").view()
|
||||
treeView.root = treeView.find('> li:first').view()
|
||||
sampleJs = treeView.find('.file:contains(sample.js)')
|
||||
sampleTxt = treeView.find('.file:contains(sample.txt)')
|
||||
@@ -38,6 +40,24 @@ describe "TreeView", ->
|
||||
expect(rootEntries.find('> .file:contains(sample.js)')).toExist()
|
||||
expect(rootEntries.find('> .file:contains(sample.txt)')).toExist()
|
||||
|
||||
describe "serialization", ->
|
||||
newTreeView = null
|
||||
|
||||
afterEach ->
|
||||
newTreeView.deactivate()
|
||||
|
||||
it "restores expanded directories and selected file when deserialized", ->
|
||||
treeView.find('.directory:contains(zed)').click()
|
||||
sampleJs.click()
|
||||
newRootView = RootView.deserialize(rootView.serialize())
|
||||
newRootView.registerExtension(TreeView)
|
||||
|
||||
newTreeView = newRootView.find(".tree-view").view()
|
||||
|
||||
expect(newTreeView).toExist()
|
||||
expect(newTreeView.selectedEntry()).toMatchSelector(".file:contains(sample.js)")
|
||||
expect(newTreeView.find(".directory:contains(zed)")).toHaveClass("expanded")
|
||||
|
||||
describe "when a directory's disclosure arrow is clicked", ->
|
||||
it "expands / collapses the associated directory", ->
|
||||
subdir = treeView.root.find('.entries > li:contains(dir/)').view()
|
||||
|
||||
@@ -19,7 +19,6 @@ afterEach ->
|
||||
document.title = defaultTitle
|
||||
ensureNoDirectorySubscriptions()
|
||||
|
||||
|
||||
window.keymap.bindKeys '*', 'meta-w': 'close'
|
||||
$(document).on 'close', -> window.close()
|
||||
|
||||
|
||||
@@ -9,14 +9,31 @@ _ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class TreeView extends View
|
||||
@activate: (rootView) ->
|
||||
@activate: (rootView, state) ->
|
||||
requireStylesheet 'tree-view.css'
|
||||
rootView.horizontal.prepend(new TreeView(rootView))
|
||||
|
||||
if state
|
||||
@treeView = TreeView.deserialize(state, rootView)
|
||||
else
|
||||
@treeView = new TreeView(rootView)
|
||||
|
||||
rootView.horizontal.prepend(@treeView)
|
||||
|
||||
@content: (rootView) ->
|
||||
@div class: 'tree-view', tabindex: -1, =>
|
||||
@subview 'root', new DirectoryView(directory: rootView.project.getRootDirectory(), isExpanded: true)
|
||||
|
||||
@deserialize: (state, rootView) ->
|
||||
treeView = new TreeView(rootView)
|
||||
treeView.root.deserializeEntryExpansionStates(state.directoryExpansionStates)
|
||||
treeView.selectEntryForPath(state.selectedPath)
|
||||
treeView
|
||||
|
||||
@serialize: ->
|
||||
@treeView.serialize()
|
||||
|
||||
root: null
|
||||
|
||||
initialize: (@rootView) ->
|
||||
@on 'click', '.entry', (e) =>
|
||||
entry = $(e.currentTarget).view()
|
||||
@@ -37,15 +54,23 @@ class TreeView extends View
|
||||
@on 'tree-view:unfocus', => @rootView.activeEditor()?.focus()
|
||||
@rootView.on 'tree-view:focus', => this.focus()
|
||||
|
||||
serialize: ->
|
||||
directoryExpansionStates: @root.serializeEntryExpansionStates()
|
||||
selectedPath: @selectedEntry()?.getPath()
|
||||
|
||||
deactivate: ->
|
||||
@root.unwatchEntries()
|
||||
|
||||
selectActiveFile: ->
|
||||
activeFilePath = @rootView.activeEditor()?.buffer.path
|
||||
for element in @find(".file")
|
||||
fileView = $(element).view()
|
||||
if fileView.getPath() == activeFilePath
|
||||
@selectEntry(fileView)
|
||||
@selectEntryForPath(activeFilePath)
|
||||
|
||||
selectEntryForPath: (path) ->
|
||||
for element in @find(".entry")
|
||||
view = $(element).view()
|
||||
if view.getPath() == path
|
||||
@selectEntry(view)
|
||||
return
|
||||
|
||||
moveDown: ->
|
||||
selectedEntry = @selectedEntry()
|
||||
|
||||
Reference in New Issue
Block a user