From a5a573d732327e1a87056f8f60ab4e28cde60525 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 17 Apr 2012 11:37:01 -0600 Subject: [PATCH] StatusBar.initialize appends a status bar view to every current and future editor pane --- spec/app/status-bar-spec.coffee | 19 +++++++++++++++++++ spec/spec-helper.coffee | 3 +++ src/app/editor.coffee | 6 +++++- src/app/status-bar.coffee | 19 +++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 spec/app/status-bar-spec.coffee create mode 100644 src/app/status-bar.coffee diff --git a/spec/app/status-bar-spec.coffee b/spec/app/status-bar-spec.coffee new file mode 100644 index 000000000..bc67f3a1b --- /dev/null +++ b/spec/app/status-bar-spec.coffee @@ -0,0 +1,19 @@ +$ = require 'jquery' +RootView = require 'root-view' +StatusBar = require 'status-bar' + +describe "StatusBar", -> + rootView = null + + beforeEach -> + rootView = new RootView + rootView.simulateDomAttachment() + StatusBar.initialize(rootView) + + describe "@initialize", -> + it "appends a status bar to all existing and new editors", -> + expect(rootView.panes.find('.pane').length).toBe 1 + expect(rootView.panes.find('.pane > .status-bar').length).toBe 1 + rootView.activeEditor().splitRight() + expect(rootView.find('.pane').length).toBe 2 + expect(rootView.panes.find('.pane > .status-bar').length).toBe 2 diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index feb1d6926..59479b8f3 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -124,6 +124,9 @@ $.fn.enableKeymap = -> $.fn.attachToDom = -> $('#jasmine-content').append(this) +$.fn.simulateDomAttachment = -> + $('').append(this) + $.fn.textInput = (data) -> event = document.createEvent 'TextEvent' event.initTextEvent('textInput', true, true, window, data) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 36ac30709..6747d63df 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -39,6 +39,7 @@ class Editor extends View softTabs: true tabText: ' ' editSessions: null + attached: false @deserialize: (viewState) -> new Editor(viewState) @@ -188,11 +189,14 @@ class Editor extends View else @gutter.addClass('drop-shadow') - @on 'attach', => + @on 'attach', (e) => + return if @attached or e.target != this[0] + @attached = true @calculateDimensions() @hiddenInput.width(@charWidth) @setMaxLineLength() if @softWrap @focus() if @isFocused + @trigger 'editor-open', [this] rootView: -> @parents('#root-view').view() diff --git a/src/app/status-bar.coffee b/src/app/status-bar.coffee new file mode 100644 index 000000000..fed28d98d --- /dev/null +++ b/src/app/status-bar.coffee @@ -0,0 +1,19 @@ +{View} = require 'space-pen' + +module.exports = +class StatusBar extends View + @initialize: (rootView) -> + for editor in rootView.editors() + @appendToEditorPane(editor) + + rootView.on 'editor-open', (e, editor) => + @appendToEditorPane(editor) + + @appendToEditorPane: (editor) -> + if pane = editor.pane() + pane.append(new StatusBar(editor)) + + @content: -> + @div class: 'status-bar' + + initialize: (@editor) ->