Make project a global and refactor startup process

This commit is contained in:
Nathan Sobo
2013-02-19 13:12:29 -07:00
committed by Corey Johnson & Nathan Sobo
parent 334a33cd74
commit 7f2747ead0
16 changed files with 126 additions and 128 deletions

View File

@@ -16,6 +16,9 @@ _.extend atom,
activatedAtomPackages: []
atomPackageStates: {}
getPathToOpen: ->
@getWindowState('pathToOpen') ? window.location.params.pathToOpen
activateAtomPackage: (pack) ->
@activatedAtomPackages.push(pack)
pack.packageMain.activate(@atomPackageStates[pack.name] ? {})

View File

@@ -33,9 +33,8 @@ class Config
load: ->
@loadUserConfig()
@requireUserInitScript()
atom.loadThemes()
atom.loadPackages()
keymap.loadUserKeymaps()
loadUserConfig: ->
if fs.exists(@configFilePath)

View File

@@ -63,7 +63,7 @@ class Keymap
keystrokeMap
handleKeyEvent: (event) ->
handleKeyEvent: (event) =>
event.keystrokes = @multiKeystrokeStringForEvent(event)
isMultiKeystroke = @queuedKeystrokes?
@queuedKeystrokes = null

View File

@@ -25,15 +25,9 @@ class RootView extends View
@div id: 'vertical', outlet: 'vertical', =>
@div id: 'panes', outlet: 'panes'
@deserialize: ({ projectState, panesViewState, packageStates, projectPath }) ->
if projectState
projectOrPathToOpen = Project.deserialize(projectState)
else
projectOrPathToOpen = projectPath # This will migrate people over to the new project serialization scheme. It should be removed eventually.
@deserialize: ({ panesViewState, packageStates, projectPath }) ->
atom.atomPackageStates = packageStates ? {}
rootView = new RootView(projectOrPathToOpen, suppressOpen: true)
rootView = new RootView(null, suppressOpen: true)
rootView.setRootPane(deserialize(panesViewState)) if panesViewState
rootView
@@ -44,23 +38,23 @@ class RootView extends View
window.rootView = this
@handleEvents()
@project = window.project
if not projectOrPathToOpen or _.isString(projectOrPathToOpen)
pathToOpen = projectOrPathToOpen
@project = new Project(projectOrPathToOpen)
else
@project = projectOrPathToOpen
pathToOpen = @project?.getPath()
@pathToOpenIsFile = pathToOpen and fs.isFile(pathToOpen)
config.load()
if pathToOpen
@open(pathToOpen) if @pathToOpenIsFile and not suppressOpen
else
@open()
unless suppressOpen
if pathToOpen
@open(pathToOpen) if @pathToOpenIsFile
else
@open()
serialize: ->
projectState: @project?.serialize()
panesViewState: @panes.children().view()?.serialize()
packageStates: atom.serializeAtomPackages()
@@ -113,7 +107,6 @@ class RootView extends View
@focus() if onDom
deactivate: ->
atom.setRootViewStateForPath(@project.getPath(), @serialize())
atom.deactivateAtomPackages()
@remove()

View File

@@ -3,9 +3,6 @@
fs = require 'fs'
$ = require 'jquery'
Config = require 'config'
Syntax = require 'syntax'
Pasteboard = require 'pasteboard'
require 'jquery-extensions'
require 'underscore-extensions'
require 'space-pen-extensions'
@@ -20,15 +17,22 @@ windowAdditions =
# This method runs when the file is required. Any code here will run
# in all environments: spec, benchmark, and application
startup: ->
@config = new Config
@syntax = new Syntax
@setUpKeymap()
@pasteboard = new Pasteboard
@setUpEventHandlers()
setUpEnvironment: ->
Config = require 'config'
Syntax = require 'syntax'
Pasteboard = require 'pasteboard'
Keymap = require 'keymap'
window.config = new Config
window.syntax = new Syntax
window.pasteboard = new Pasteboard
window.keymap = new Keymap()
$(document).on 'keydown', keymap.handleKeyEvent
keymap.bindDefaultKeys()
setUpEventHandlers: ->
$(window).on 'core:close', => @close()
handleWindowEvents: ->
$(window).command 'window:close', => @close()
$(window).command 'window:toggle-full-screen', => atom.toggleFullScreen()
$(window).on 'focus', -> $("body").removeClass('is-blurred')
@@ -37,37 +41,36 @@ windowAdditions =
# This method is intended only to be run when starting a normal application
# Note: RootView assigns itself on window on initialization so that
# window.rootView is available when loading user configuration
attachRootView: (pathToOpen) ->
RootView = require 'root-view'
if pathState = atom.getRootViewStateForPath(pathToOpen)
RootView.deserialize(pathState)
else
new RootView(pathToOpen)
$(@rootViewParentSelector).append(@rootView)
startApplication: ->
config.load()
buildProjectAndRootView()
keymap.loadBundledKeymaps()
keymap.loadUserKeymaps()
atom.loadThemes()
atom.loadPackages()
$(window).on 'beforeunload', -> stopApplication(); false
$(window).focus()
$(window).on 'beforeunload', =>
@shutdown()
false
shutdown: ->
if @rootView
atom.setWindowState('pathToOpen', @rootView.project.getPath())
@rootView.deactivate()
@rootView = null
$(window).off('focus')
$(window).off('blur')
$(window).off('before')
buildProjectAndRootView: ->
RootView = require 'root-view'
Project = require 'project'
setUpKeymap: ->
Keymap = require 'keymap'
if windowState = atom.getRootViewStateForPath(atom.getPathToOpen()) and windowState?.project?
window.project = deserialize(windowState.project)
window.rootView = deserialize(windowState.rootView)
else
window.project = new Project(atom.getPathToOpen())
window.rootView = new RootView(atom.getPathToOpen())
$(rootViewParentSelector).append(rootView)
@keymap = new Keymap()
@keymap.bindDefaultKeys()
@keymap.loadBundledKeymaps()
@_handleKeyEvent = (e) => @keymap.handleKeyEvent(e)
$(document).on 'keydown', @_handleKeyEvent
stopApplication: ->
atom.setWindowState('pathToOpen', rootView.project.getPath())
atom.setRootViewStateForPath project.getPath(),
project: project.serialize()
rootView: rootView.serialize()
rootView.deactivate()
project.destroy()
$(window).off('focus blur before')
stylesheetElementForId: (id) ->
$("head style[id='#{id}']")
@@ -121,7 +124,7 @@ windowAdditions =
value
window[key] = value for key, value of windowAdditions
window.startup()
window.setUpEnvironment()
requireStylesheet 'reset.css'
requireStylesheet 'atom.css'