Remove fixed editor subview from root view.

This commit is contained in:
Nathan Sobo
2012-03-20 16:55:33 -06:00
parent 8ea4b4eb72
commit 50f11f1a4c
3 changed files with 22 additions and 16 deletions

View File

@@ -30,8 +30,8 @@ describe "App", ->
runs ->
expect(atom.windows.length).toBe 1
newWindow = atom.windows[0]
expect(newWindow.rootView.editor.buffer.url).toEqual filePath
expect(newWindow.rootView.editor.buffer.getText()).toEqual fs.read(filePath)
expect(newWindow.rootView.lastActiveEditor().buffer.url).toEqual filePath
expect(newWindow.rootView.lastActiveEditor().buffer.getText()).toEqual fs.read(filePath)
describe ".windowOpened(window)", ->
app = null

View File

@@ -18,7 +18,7 @@ describe "RootView", ->
describe "when called with a url that references a file", ->
it "creates a project for the file's parent directory and opens it in the editor", ->
expect(rootView.project.url).toBe fs.directory(url)
expect(rootView.editor.buffer.path).toBe url
expect(rootView.lastActiveEditor().buffer.path).toBe url
describe "when called with a url that references a directory", ->
it "creates a project for the directory and opens an empty buffer", ->
@@ -26,12 +26,12 @@ describe "RootView", ->
rootView = new RootView({url})
expect(rootView.project.url).toBe url
expect(rootView.editor.buffer.url).toBeUndefined()
expect(rootView.lastActiveEditor().buffer.url).toBeUndefined()
describe "when not called with a url", ->
it "opens an empty buffer", ->
rootView = new RootView
expect(rootView.editor.buffer.url).toBeUndefined()
expect(rootView.lastActiveEditor().buffer.url).toBeUndefined()
describe "split editor panes", ->
editor1 = null
@@ -294,7 +294,7 @@ describe "RootView", ->
rootView = new RootView
it "does not open the FileFinder", ->
expect(rootView.editor.buffer.url).toBeUndefined()
expect(rootView.lastActiveEditor().buffer.url).toBeUndefined()
expect(rootView.find('.file-finder')).not.toExist()
rootView.trigger 'toggle-file-finder'
expect(rootView.find('.file-finder')).not.toExist()

View File

@@ -13,14 +13,12 @@ module.exports =
class RootView extends View
@content: ->
@div id: 'root-view', =>
@div id: 'panes', outlet: 'panes', =>
@subview 'editor', new Editor
@div id: 'panes', outlet: 'panes'
editors: null
initialize: ({url}) ->
@editors = []
@editor.keyEventHandler = window.keymap
@createProject(url)
window.keymap.bindKeys '*'
@@ -32,10 +30,13 @@ class RootView extends View
@on 'toggle-file-finder', => @toggleFileFinder()
@on 'show-console', -> window.showConsole()
createProject: (url) ->
if url
@project = new Project(fs.directory(url))
@editor.setBuffer(@project.open(url)) if fs.isFile(url)
createProject: (path) ->
if path
@project = new Project(fs.directory(path))
@open(path) if fs.isFile(path)
open: (path) ->
@lastActiveEditor().setBuffer(@project.open(path))
addPane: (view) ->
@append(view)
@@ -55,7 +56,13 @@ class RootView extends View
window.close()
lastActiveEditor: ->
_.last(@editors)
if @editors.length
_.last(@editors)
else
new Editor()
.appendTo(@panes)
.focus()
adjustSplitPanes: (element = @panes.children(':first'))->
if element.hasClass('row')
@@ -118,6 +125,5 @@ class RootView extends View
relativePaths = (path.replace(@project.url, "") for path in paths)
@fileFinder = new FileFinder
urls: relativePaths
selected: (relativePath) =>
@lastActiveEditor().setBuffer(@project.open(relativePath))
selected: (relativePath) => @open(relativePath)
@addPane @fileFinder