Merge branch 'master' of github.com:github/atom

Conflicts:
	spec/app/root-view-spec.coffee
	src/app/root-view.coffee
This commit is contained in:
Nathan Sobo
2012-05-07 19:38:01 -06:00
7 changed files with 47 additions and 81 deletions

View File

@@ -1,42 +0,0 @@
(function() {
var Point, Range;
Range = require('range');
Point = require('point');
describe("Range", function() {
describe("constructor", function() {
return it("ensures that @start <= @end", function() {
var range1, range2;
range1 = new Range(new Point(0, 1), new Point(0, 4));
expect(range1.start).toEqual({
row: 0,
column: 1
});
range2 = new Range(new Point(1, 4), new Point(0, 1));
return expect(range2.start).toEqual({
row: 0,
column: 1
});
});
});
describe(".isEmpty()", function() {
return it("returns true if @start equals @end", function() {
expect(new Range(new Point(1, 1), new Point(1, 1)).isEmpty()).toBeTruthy();
return expect(new Range(new Point(1, 1), new Point(1, 2)).isEmpty()).toBeFalsy();
});
});
return describe(".intersectsWith(otherRange)", function() {
return fit("returns the intersection of the two ranges", function() {
var range1, range2;
range1 = new Range([1, 1], [2, 10]);
range2 = new Range([2, 1], [3, 10]);
expect(range1.intersectsWith(range2)).toBeTruth;
range2 = range1 = new Range([2, 1], [3, 10]);
return expect(range1.intersectsWith(range2)).toBeTruth;
});
});
});
}).call(this);

View File

@@ -16,7 +16,7 @@ describe "RootView", ->
rootView.focus()
project = rootView.project
describe "initialize(viewState)", ->
describe "initialize(pathToOpen)", ->
describe "when called with a pathToOpen", ->
describe "when pathToOpen references a file", ->
it "creates a project for the file's parent directory, then sets the document.title and opens the file in an editor", ->
@@ -45,13 +45,15 @@ describe "RootView", ->
beforeEach ->
rootView = new RootView
rootView.open()
editor1 = rootView.activeEditor()
buffer = editor1.buffer
editor1.splitRight()
viewState = rootView.serialize()
it "constructs the view with the same panes", ->
rootView = new RootView(viewState)
console.log 'spec'
rootView = RootView.deserialize(viewState)
expect(rootView.project.path).toBeNull()
expect(rootView.editors().length).toBe 2
expect(rootView.activeEditor().buffer.getText()).toBe buffer.getText()
@@ -74,7 +76,7 @@ describe "RootView", ->
rootView.remove()
it "constructs the view with the same project and panes", ->
rootView = new RootView(viewState)
rootView = RootView.deserialize(viewState)
rootView.attachToDom()
expect(rootView.editors().length).toBe 4
@@ -104,11 +106,10 @@ describe "RootView", ->
expect(document.title).toBe editor2.buffer.path
describe "when called with no state data", ->
it "opens an empty buffer and sets the document.title to untitled", ->
describe "when called with no pathToOpen", ->
it "opens no buffer", ->
rootView = new RootView
expect(rootView.editors().length).toBe 1
expect(rootView.activeEditor().buffer.path).toBeUndefined()
expect(rootView.editors().length).toBe 0
expect(document.title).toBe 'untitled'
describe "focus", ->
@@ -376,6 +377,7 @@ describe "RootView", ->
it "creates a project if there isn't one yet and the buffer was previously unsaved", ->
rootView = new RootView
rootView.open()
expect(rootView.project.path).toBeNull()
rootView.activeEditor().buffer.saveAs('/tmp/ignore-me')
expect(rootView.project.path).toBe '/tmp'

View File

@@ -28,6 +28,7 @@ describe "StatusBar", ->
describe "when associated with an unsaved buffer", ->
it "displays 'untitled' instead of the buffer's path, but still displays the buffer position", ->
rootView = new RootView
rootView.open()
rootView.simulateDomAttachment()
StatusBar.activate(rootView)
statusBar = rootView.find('.status-bar').view()

View File

@@ -5,6 +5,7 @@ describe "CommandPanel", ->
beforeEach ->
rootView = new RootView
rootView.open()
rootView.enableKeymap()
commandPanel = rootView.commandPanel

View File

@@ -7,6 +7,8 @@ describe "StripTrailingWhitespace", ->
beforeEach ->
rootView = new RootView
rootView.open()
StripTrailingWhitespace.activate(rootView)
rootView.focus()
editor = rootView.activeEditor()

View File

@@ -21,13 +21,33 @@ class RootView extends View
@div id: 'horizontal', outlet: 'horizontal', =>
@div id: 'panes', outlet: 'panes'
@deserialize: (viewState) ->
new RootView(viewState)
@deserialize: ({ projectPath, panesViewState, extensionStates }) ->
rootView = new RootView(pathToOpen: projectPath)
rootView.setRootPane(rootView.deserializeView(panesViewState)) if panesViewState
rootView.extensionStates = extensionStates if extensionStates
rootView
extensions: null
extensionStates: null
initialize: ({ pathToOpen, projectPath, panesViewState, @extensionStates }) ->
initialize: ({ pathToOpen }) ->
@handleEvents()
@extensions = {}
@extensionStates = {}
@commandPanel = new CommandPanel({rootView: this})
@setTitle()
@project = new Project(pathToOpen)
if pathToOpen? and fs.isFile(pathToOpen)
@open(pathToOpen)
serialize: ->
projectPath: @project?.path
panesViewState: @panes.children().view()?.serialize()
extensionStates: @serializeExtensions()
handleEvents: ->
@on 'show-console', => window.showConsole()
@on 'focus', (e) =>
if @activeEditor()
@@ -40,35 +60,9 @@ class RootView extends View
@project.setPath(path) unless @project.getPath()
@setTitle(path)
@commandPanel = new CommandPanel({rootView: this})
if pathToOpen?
@project = new Project(pathToOpen)
@open(pathToOpen) if fs.isFile(pathToOpen)
else
@project = new Project(projectPath)
@open() unless panesViewState?
@deserializePanes(panesViewState) if panesViewState
@extensionStates ?= {}
@extensions = {}
afterAttach: (onDom) ->
@focus() if onDom
serialize: ->
projectPath: @project?.path
panesViewState: @serializePanes()
extensionStates: @serializeExtensions()
serializePanes: ->
@panes.children().view()?.serialize()
deserializePanes: (panesViewState) ->
@panes.append @deserializeView(panesViewState)
@adjustPaneDimensions()
serializeExtensions: ->
extensionStates = {}
for name, extension of @extensions
@@ -132,6 +126,11 @@ class RootView extends View
else
@panes.find('.editor:first').view()
setRootPane: (pane) ->
@panes.empty()
@panes.append(pane)
@adjustPaneDimensions()
adjustPaneDimensions: ->
rootPane = @panes.children().first().view()
rootPane?.css(width: '100%', height: '100%', top: 0, left: 0)

View File

@@ -23,6 +23,7 @@ windowAdditions =
startup: (path) ->
@attachRootView(path)
@loadUserConfiguration()
rootView.activateExtension(require 'tree-view')
$(window).on 'close', => @close()
$(window).on 'beforeunload', =>
@shutdown()
@@ -39,10 +40,12 @@ windowAdditions =
attachRootView: (pathToOpen) ->
rootViewState = atom.rootViewStates[$windowNumber]
@rootView = if rootViewState
RootView.deserialize(rootViewState)
if rootViewState
@rootView = RootView.deserialize(rootViewState)
else
new RootView {pathToOpen}
@rootView = new RootView(pathToOpen: pathToOpen)
@rootView.open() unless pathToOpen
$(@rootViewParentSelector).append @rootView
loadUserConfiguration: ->