Rename Layout to RootView

This commit is contained in:
Corey Johnson & Nathan Sobo 2011-12-28 17:14:32 -08:00
parent c6fbad8e9e
commit e617e129e0
6 changed files with 50 additions and 49 deletions

View File

@ -20,5 +20,5 @@ describe "App", ->
expect(app.windows().length).toBe 1
newWindow = app.windows()[0]
expect(newWindow.editor.buffer.url).toEqual filePath
expect(newWindow.editor.buffer.getText()).toEqual fs.read(filePath)
expect(newWindow.rootView.editor.buffer.url).toEqual filePath
expect(newWindow.rootView.editor.buffer.getText()).toEqual fs.read(filePath)

View File

@ -1,15 +0,0 @@
$ = require 'jquery'
Layout = require 'layout'
describe "Layout", ->
layout = null
beforeEach -> layout = Layout.build()
describe ".addPane(view)", ->
it "adds the given view to the layout (at the bottom by default)", ->
expect(layout.vertical.children().length).toBe 1
layout.addPane $('<div id="foo">')
expect(layout.vertical.children().length).toBe 2

View File

@ -0,0 +1,23 @@
$ = require 'jquery'
RootView = require 'root-view'
describe "RootView", ->
rootView = null
beforeEach -> rootView = RootView.build()
describe ".addPane(view)", ->
it "adds the given view to the rootView (at the bottom by default)", ->
expect(rootView.vertical.children().length).toBe 1
rootView.addPane $('<div id="foo">')
expect(rootView.vertical.children().length).toBe 2
describe "toggleFileFinder", ->
it "shows the FileFinder when it is not on screen and hides it when it is", ->
expect(rootView.find('.file-finder')).not.toExist()
rootView.toggleFileFinder()
expect(rootView.find('.file-finder')).toExist()
rootView.toggleFileFinder()
expect(rootView.find('.file-finder')).not.toExist()

View File

@ -93,16 +93,8 @@ describe "Window", ->
it "adds a Save item to the main menu after startup", ->
expect(OSX.NSApp.mainMenu.itemWithTitle('File').submenu.itemWithTitle('Save')).not.toBeNull()
describe "toggleFileFinder", ->
it "shows the FileFinder when it is not on screen and hides it when it is", ->
expect(window.layout.find('.file-finder')).not.toExist()
window.toggleFileFinder()
expect(window.layout.find('.file-finder')).toExist()
window.toggleFileFinder()
expect(window.layout.find('.file-finder')).not.toExist()
describe 'meta+s', ->
it 'saves the buffer', ->
spyOn(window.editor, 'save')
spyOn(window.rootView.editor, 'save')
window.keydown 'meta+s'
expect(window.editor.save).toHaveBeenCalled()
expect(window.rootView.editor.save).toHaveBeenCalled()

View File

@ -1,8 +1,11 @@
$ = require 'jquery'
Editor = require 'editor'
FileFinder = require 'file-finder'
Template = require 'template'
module.exports =
class Layout extends Template
class RootView extends Template
@attach: ->
view = @build()
$('body').append view
@ -15,7 +18,19 @@ class Layout extends Template
@div id: 'main', outlet: 'main'
viewProperties:
initialize: ->
@editor = new Editor $atomController.url?.toString()
addPane: (view) ->
pane = $('<div class="pane">')
pane.append(view)
@main.after(pane)
toggleFileFinder: ->
if @fileFinder
@fileFinder.remove()
@fileFinder = null
else
@fileFinder = FileFinder.build(urls: [@editor.buffer.url])
@addPane(@fileFinder)
@fileFinder.input.focus()

View File

@ -2,52 +2,38 @@ fs = require 'fs'
_ = require 'underscore'
$ = require 'jquery'
Layout = require 'layout'
Editor = require 'editor'
FileFinder = require 'file-finder'
RootView = require 'root-view'
# This a weirdo file. We don't create a Window class, we just add stuff to
# the DOM window.
windowAdditions =
editor: null
keyBindings: null
layout: null
rootView: null
menuItemActions: null
startup: ->
@keyBindings = {}
@menuItemActions = {}
@layout = Layout.attach()
@editor = new Editor $atomController.url?.toString()
@rootView = RootView.attach()
@registerEventHandlers()
@bindKeys()
@bindMenuItems()
$(window).focus()
shutdown: ->
@layout.remove()
@editor.shutdown()
@rootView.remove()
$(window).unbind('focus')
$(window).unbind('blur')
$(window).unbind('keydown')
toggleFileFinder: ->
if @fileFinder
@fileFinder.remove()
@fileFinder = null
else
@fileFinder = FileFinder.build(urls: [@editor.buffer.url])
window.layout.addPane(fileFinder)
fileFinder.input.focus()
bindKeys: ->
@bindKey 'meta+s', => @editor.save()
@bindKey 'meta+s', => @rootView.editor.save()
@bindKey 'meta+w', => @close()
@bindKey 'meta+t', => @toggleFileFinder()
@bindKey 'meta+t', => @rootView.toggleFileFinder()
bindMenuItems: ->
@bindMenuItem "File > Save", "meta+s", => @editor.save()
@bindMenuItem "File > Save", "meta+s", => @rootView.editor.save()
bindMenuItem: (path, pattern, action) ->
@menuItemActions[path] = {action: action, pattern: pattern}