mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Rename Layout to RootView
This commit is contained in:
parent
c6fbad8e9e
commit
e617e129e0
@ -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)
|
||||
|
@ -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
|
||||
|
23
spec/atom/root-view-spec.coffee
Normal file
23
spec/atom/root-view-spec.coffee
Normal 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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user