mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
Merge pull request #1305 from atom/ns-telepathic-atom-global
Make atom global a Telepath model subclass
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
{Document, Model, Point, Range} = require 'telepath'
|
||||
{TelepathicObject, Model, Point, Range} = require 'telepath'
|
||||
|
||||
module.exports =
|
||||
_: require 'underscore-plus'
|
||||
BufferedNodeProcess: require '../src/buffered-node-process'
|
||||
BufferedProcess: require '../src/buffered-process'
|
||||
Directory: require '../src/directory'
|
||||
Document: Document
|
||||
TelepathicObject: TelepathicObject
|
||||
Document: TelepathicObject # Deprecated Shim
|
||||
File: require '../src/file'
|
||||
fs: require 'fs-plus'
|
||||
Git: require '../src/git'
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
"season": "0.14.0",
|
||||
"semver": "1.1.4",
|
||||
"space-pen": "2.0.2",
|
||||
"telepath": "0.70.0",
|
||||
"telepath": "0.76.0",
|
||||
"temp": "0.5.0",
|
||||
"underscore-plus": "0.6.1"
|
||||
},
|
||||
|
||||
@@ -442,7 +442,7 @@ describe "the `atom` global", ->
|
||||
describe ".isReleasedVersion()", ->
|
||||
it "returns false if the version is a SHA and true otherwise", ->
|
||||
version = '0.1.0'
|
||||
spyOn(atom, 'getVersion').andCallFake -> version
|
||||
spyOn(atom.constructor, 'getVersion').andCallFake -> version
|
||||
expect(atom.isReleasedVersion()).toBe true
|
||||
version = '36b5518'
|
||||
expect(atom.isReleasedVersion()).toBe false
|
||||
|
||||
@@ -4,7 +4,7 @@ require('crash-reporter').start(productName: 'Atom', companyName: 'GitHub')
|
||||
try
|
||||
require '../src/window'
|
||||
Atom = require '../src/atom'
|
||||
window.atom = new Atom()
|
||||
window.atom = Atom.loadOrCreate('spec')
|
||||
window.atom.show() unless atom.getLoadSettings().exitWhenDone
|
||||
{runSpecSuite} = require './jasmine-helper'
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require '../src/window'
|
||||
atom.setUpEnvironment('spec')
|
||||
atom.restoreDimensions()
|
||||
atom.initialize()
|
||||
atom.restoreWindowDimensions()
|
||||
|
||||
require '../vendor/jasmine-jquery'
|
||||
path = require 'path'
|
||||
@@ -28,9 +28,8 @@ keyBindingsToRestore = atom.keymap.getKeyBindings()
|
||||
|
||||
$(window).on 'core:close', -> window.close()
|
||||
$(window).on 'unload', ->
|
||||
atom.windowMode = 'spec'
|
||||
atom.getWindowState().set('dimensions', atom.getDimensions())
|
||||
atom.saveWindowState()
|
||||
atom.storeWindowDimensions()
|
||||
atom.saveSync()
|
||||
$('html,body').css('overflow', 'auto')
|
||||
|
||||
jasmine.getEnv().addEqualityTester(_.isEqual) # Use underscore's definition of equality for toEqual assertions
|
||||
@@ -51,15 +50,15 @@ if specDirectory
|
||||
beforeEach ->
|
||||
$.fx.off = true
|
||||
projectPath = specProjectPath ? path.join(@specDirectory, 'fixtures')
|
||||
atom.project = atom.getWindowState().set('project', new Project(path: projectPath))
|
||||
atom.project = new Project(path: projectPath)
|
||||
atom.keymap.keyBindings = _.clone(keyBindingsToRestore)
|
||||
|
||||
window.resetTimeouts()
|
||||
atom.packages.packageStates = {}
|
||||
|
||||
serializedWindowState = null
|
||||
spyOn(atom, 'saveWindowState').andCallFake -> serializedWindowState = @getWindowState().serialize()
|
||||
spyOn(atom, 'loadSerializedWindowState').andCallFake -> serializedWindowState
|
||||
|
||||
spyOn(atom, 'saveSync')
|
||||
atom.syntax.clearGrammarOverrides()
|
||||
atom.syntax.clearProperties()
|
||||
|
||||
@@ -111,13 +110,17 @@ afterEach ->
|
||||
|
||||
atom.workspaceView?.remove?()
|
||||
atom.workspaceView = null
|
||||
atom.state.remove('workspaceView')
|
||||
|
||||
atom.project?.destroy?()
|
||||
atom.project = null
|
||||
|
||||
atom.state.remove('packageStates')
|
||||
|
||||
$('#jasmine-content').empty() unless window.debugContent
|
||||
delete atom.windowState
|
||||
jasmine.unspy(atom, 'saveWindowState')
|
||||
atom.destroyOrphans()
|
||||
|
||||
jasmine.unspy(atom, 'saveSync')
|
||||
ensureNoPathSubscriptions()
|
||||
atom.syntax.off()
|
||||
waits(0) # yield to ui thread to make screen update more frequently
|
||||
@@ -136,7 +139,7 @@ jasmine.StringPrettyPrinter.prototype.emitObject = (obj) ->
|
||||
emitObject.call(this, obj)
|
||||
|
||||
jasmine.unspy = (object, methodName) ->
|
||||
throw new Error("Not a spy") unless object[methodName].originalValue?
|
||||
throw new Error("Not a spy") unless object[methodName].hasOwnProperty('originalValue')
|
||||
object[methodName] = object[methodName].originalValue
|
||||
|
||||
addCustomMatchers = (spec) ->
|
||||
|
||||
@@ -8,8 +8,11 @@ describe "Window", ->
|
||||
|
||||
beforeEach ->
|
||||
spyOn(atom, 'hide')
|
||||
atom.getLoadSettings() # Causes atom.loadSettings to be initialized
|
||||
atom.loadSettings.initialPath = atom.project.getPath()
|
||||
initialPath = atom.project.getPath()
|
||||
spyOn(atom, 'getLoadSettings').andCallFake ->
|
||||
loadSettings = atom.getLoadSettings.originalValue.call(atom)
|
||||
loadSettings.initialPath = initialPath
|
||||
loadSettings
|
||||
atom.project.destroy()
|
||||
windowEventHandler = new WindowEventHandler()
|
||||
atom.deserializeEditorWindow()
|
||||
@@ -90,9 +93,9 @@ describe "Window", ->
|
||||
|
||||
atom.unloadEditorWindow()
|
||||
|
||||
expect(atom.getWindowState().getObject('workspaceView')).toEqual workspaceViewState.toObject()
|
||||
expect(atom.getWindowState().getObject('syntax')).toEqual syntaxState
|
||||
expect(atom.saveWindowState).toHaveBeenCalled()
|
||||
expect(atom.state.getObject('workspaceView')).toEqual workspaceViewState.toObject()
|
||||
expect(atom.state.getObject('syntax')).toEqual syntaxState
|
||||
expect(atom.saveSync).toHaveBeenCalled()
|
||||
|
||||
it "unsubscribes from all buffers", ->
|
||||
atom.workspaceView.openSync('sample.js')
|
||||
|
||||
@@ -19,8 +19,10 @@ describe "WorkspaceView", ->
|
||||
viewState = null
|
||||
|
||||
simulateReload = ->
|
||||
atom.unloadEditorWindow()
|
||||
atom.deserializeEditorWindow()
|
||||
state = atom.workspaceView.serialize().replicate()
|
||||
atom.workspaceView.remove()
|
||||
atom.workspaceView = WorkspaceView.deserialize(state)
|
||||
atom.workspaceView.attachToDom()
|
||||
|
||||
describe "when the serialized WorkspaceView has an unsaved buffer", ->
|
||||
it "constructs the view with the same panes", ->
|
||||
@@ -29,12 +31,12 @@ describe "WorkspaceView", ->
|
||||
editor1 = atom.workspaceView.getActiveView()
|
||||
buffer = editor1.getBuffer()
|
||||
editor1.splitRight()
|
||||
expect(atom.workspaceView.getActiveView()).toBe atom.workspaceView.getEditorViews()[2]
|
||||
expect(atom.workspaceView.getActivePane()).toBe atom.workspaceView.getPanes()[1]
|
||||
|
||||
simulateReload()
|
||||
|
||||
expect(atom.workspaceView.getEditorViews().length).toBe 2
|
||||
expect(atom.workspaceView.getActiveView()).toBe atom.workspaceView.getEditorViews()[1]
|
||||
expect(atom.workspaceView.getActivePane()).toBe atom.workspaceView.getPanes()[1]
|
||||
expect(atom.workspaceView.title).toBe "untitled - #{atom.project.getPath()}"
|
||||
|
||||
describe "when there are open editors", ->
|
||||
|
||||
306
src/atom.coffee
306
src/atom.coffee
@@ -10,13 +10,10 @@ app = remote.require 'app'
|
||||
|
||||
_ = require 'underscore-plus'
|
||||
telepath = require 'telepath'
|
||||
{Document} = telepath
|
||||
{Model} = telepath
|
||||
fs = require 'fs-plus'
|
||||
{Subscriber} = require 'emissary'
|
||||
|
||||
{$} = require './space-pen-extensions'
|
||||
DeserializerManager = require './deserializer-manager'
|
||||
Package = require './package'
|
||||
SiteShim = require './site-shim'
|
||||
WindowEventHandler = require './window-event-handler'
|
||||
|
||||
@@ -37,24 +34,103 @@ WindowEventHandler = require './window-event-handler'
|
||||
# * `atom.syntax` - A {Syntax} instance
|
||||
# * `atom.themes` - A {ThemeManager} instance
|
||||
module.exports =
|
||||
class Atom
|
||||
Subscriber.includeInto(this)
|
||||
class Atom extends Model
|
||||
# Public: Load or create the Atom environment in the given mode
|
||||
#
|
||||
# - mode: Pass 'editor' or 'spec' depending on the kind of environment you
|
||||
# want to build.
|
||||
#
|
||||
# Returns an Atom instance, fully initialized
|
||||
@loadOrCreate: (mode) ->
|
||||
telepath.devMode = not @isReleasedVersion()
|
||||
|
||||
if documentState = @loadDocumentState(mode)
|
||||
environment = @deserialize(documentState)
|
||||
|
||||
environment ? @createAsRoot({mode})
|
||||
|
||||
# Private: Loads and returns the serialized state corresponding to this window
|
||||
# if it exists; otherwise returns undefined.
|
||||
@loadDocumentState: (mode) ->
|
||||
statePath = @getStatePath(mode)
|
||||
|
||||
if fs.existsSync(statePath)
|
||||
try
|
||||
documentStateString = fs.readFileSync(statePath, 'utf8')
|
||||
catch error
|
||||
console.warn "Error reading window state: #{statePath}", error.stack, error
|
||||
else
|
||||
documentStateString = @getLoadSettings().windowState
|
||||
|
||||
try
|
||||
JSON.parse(documentStateString) if documentStateString?
|
||||
catch error
|
||||
console.warn "Error parsing window state: #{statePath}", error.stack, error
|
||||
|
||||
# Private: Returns the path where the state for the current window will be
|
||||
# located if it exists.
|
||||
@getStatePath: (mode) ->
|
||||
switch mode
|
||||
when 'spec'
|
||||
filename = 'spec'
|
||||
when 'editor'
|
||||
{initialPath} = @getLoadSettings()
|
||||
if initialPath
|
||||
sha1 = crypto.createHash('sha1').update(initialPath).digest('hex')
|
||||
filename = "editor-#{sha1}"
|
||||
|
||||
if filename
|
||||
path.join(@getStorageDirPath(), filename)
|
||||
else
|
||||
null
|
||||
|
||||
# Private: Get the directory path to Atom's configuration area.
|
||||
#
|
||||
# Returns the absolute path to ~/.atom
|
||||
@getConfigDirPath: ->
|
||||
@configDirPath ?= fs.absolute('~/.atom')
|
||||
|
||||
# Private: Get the path to Atom's storage directory.
|
||||
#
|
||||
# Returns the absolute path to ~/.atom/storage
|
||||
@getStorageDirPath: ->
|
||||
@storageDirPath ?= path.join(@getConfigDirPath(), 'storage')
|
||||
|
||||
# Private: Returns the load settings hash associated with the current window.
|
||||
@getLoadSettings: ->
|
||||
_.deepClone(@loadSettings ?= _.deepClone(@getCurrentWindow().loadSettings))
|
||||
|
||||
# Private:
|
||||
constructor: ->
|
||||
@loadTime = null
|
||||
@workspaceViewParentSelector = 'body'
|
||||
@getCurrentWindow: ->
|
||||
remote.getCurrentWindow()
|
||||
|
||||
# Private: Get the version of the Atom application.
|
||||
@getVersion: ->
|
||||
@version ?= app.getVersion()
|
||||
|
||||
# Private: Determine whether the current version is an official release.
|
||||
@isReleasedVersion: ->
|
||||
not /\w{7}/.test(@getVersion()) # Check if the release is a 7-character SHA prefix
|
||||
|
||||
@properties
|
||||
mode: null
|
||||
project: null
|
||||
|
||||
workspaceViewParentSelector: 'body'
|
||||
|
||||
# Private: Called by telepath. I'd like this to be merged with initialize eventually.
|
||||
created: ->
|
||||
DeserializerManager = require './deserializer-manager'
|
||||
@deserializers = new DeserializerManager()
|
||||
|
||||
# Private: Initialize all the properties in this object.
|
||||
# Public: Sets up the basic services that should be available in all modes
|
||||
# (both spec and application). Call after this instance has been assigned to
|
||||
# the `atom` global.
|
||||
initialize: ->
|
||||
@unsubscribe()
|
||||
@setBodyPlatformClass()
|
||||
|
||||
{devMode, resourcePath} = atom.getLoadSettings()
|
||||
configDirPath = @getConfigDirPath()
|
||||
|
||||
telepath.devMode = not @isReleasedVersion()
|
||||
@loadTime = null
|
||||
|
||||
Config = require './config'
|
||||
Keymap = require './keymap'
|
||||
@@ -64,40 +140,42 @@ class Atom
|
||||
ThemeManager = require './theme-manager'
|
||||
ContextMenuManager = require './context-menu-manager'
|
||||
MenuManager = require './menu-manager'
|
||||
{devMode, resourcePath} = @getLoadSettings()
|
||||
configDirPath = @getConfigDirPath()
|
||||
|
||||
@config = new Config({configDirPath, resourcePath})
|
||||
@keymap = new Keymap({configDirPath, resourcePath})
|
||||
@packages = new PackageManager({devMode, configDirPath, resourcePath})
|
||||
|
||||
@subscribe @packages, 'activated', => @watchThemes()
|
||||
@themes = new ThemeManager({packageManager: @packages, configDirPath, resourcePath})
|
||||
@contextMenu = new ContextMenuManager(devMode)
|
||||
@menu = new MenuManager({resourcePath})
|
||||
@pasteboard = new Pasteboard()
|
||||
@syntax = @deserializers.deserialize(@getWindowState('syntax')) ? new Syntax()
|
||||
@syntax = @deserializers.deserialize(@state.get('syntax')) ? new Syntax()
|
||||
@site = new SiteShim(this)
|
||||
|
||||
# Private: This method is called in any window needing a general environment, including specs
|
||||
setUpEnvironment: (@windowMode) ->
|
||||
@initialize()
|
||||
@subscribe @packages, 'activated', => @watchThemes()
|
||||
|
||||
Project = require './project'
|
||||
TextBuffer = require './text-buffer'
|
||||
TokenizedBuffer = require './tokenized-buffer'
|
||||
DisplayBuffer = require './display-buffer'
|
||||
Editor = require './editor'
|
||||
@registerRepresentationClasses(Project, TextBuffer, TokenizedBuffer, DisplayBuffer, Editor)
|
||||
|
||||
@windowEventHandler = new WindowEventHandler
|
||||
|
||||
# Private:
|
||||
setBodyPlatformClass: ->
|
||||
document.body.classList.add("platform-#{process.platform}")
|
||||
|
||||
# Public: Create a new telepath model. We won't need to define this method when
|
||||
# the atom global is a telepath model itself because all model subclasses inherit
|
||||
# a create method.
|
||||
create: (model) ->
|
||||
@site.createDocument(model)
|
||||
|
||||
# Public: Get the current window
|
||||
getCurrentWindow: ->
|
||||
remote.getCurrentWindow()
|
||||
@constructor.getCurrentWindow()
|
||||
|
||||
# Public: Get the dimensions of this window.
|
||||
#
|
||||
# Returns an object with x, y, width, and height keys.
|
||||
getDimensions: ->
|
||||
getWindowDimensions: ->
|
||||
browserWindow = @getCurrentWindow()
|
||||
[x, y] = browserWindow.getPosition()
|
||||
[width, height] = browserWindow.getSize()
|
||||
@@ -106,65 +184,59 @@ class Atom
|
||||
# Public: Set the dimensions of the window.
|
||||
#
|
||||
# The window will be centered if either the x or y coordinate is not set
|
||||
# in the dimensions parameter.
|
||||
# in the dimensions parameter. If x or y are omitted the window will be
|
||||
# centered. If height or width are omitted only the position will be changed.
|
||||
#
|
||||
# * dimensions:
|
||||
# + x:
|
||||
# The new x coordinate.
|
||||
# + y:
|
||||
# The new y coordinate.
|
||||
# + width:
|
||||
# The new width.
|
||||
# + height:
|
||||
# The new height.
|
||||
setDimensions: ({x, y, width, height}) ->
|
||||
# + x: The new x coordinate.
|
||||
# + y: The new y coordinate.
|
||||
# + width: The new width.
|
||||
# + height: The new height.
|
||||
setWindowDimensions: ({x, y, width, height}) ->
|
||||
browserWindow = @getCurrentWindow()
|
||||
browserWindow.setSize(width, height)
|
||||
if width? and height?
|
||||
browserWindow.setSize(width, height)
|
||||
if x? and y?
|
||||
browserWindow.setPosition(x, y)
|
||||
else
|
||||
browserWindow.center()
|
||||
|
||||
# Private:
|
||||
restoreDimensions: ->
|
||||
dimensions = @getWindowState().getObject('dimensions')
|
||||
unless dimensions?.width and dimensions?.height
|
||||
{height, width} = @getLoadSettings().initialSize ? {}
|
||||
height ?= screen.availHeight
|
||||
width ?= Math.min(screen.availWidth, 1024)
|
||||
dimensions = {width, height}
|
||||
@setDimensions(dimensions)
|
||||
restoreWindowDimensions: ->
|
||||
windowDimensions = @state.getObject('windowDimensions') ? {}
|
||||
{initialSize} = @getLoadSettings()
|
||||
windowDimensions.height ?= initialSize?.height ? global.screen.availHeight
|
||||
windowDimensions.width ?= initialSize?.width ? Math.min(global.screen.availWidth, 1024)
|
||||
@setWindowDimensions(windowDimensions)
|
||||
|
||||
# Private:
|
||||
storeWindowDimensions: ->
|
||||
@state.set('windowDimensions', @getWindowDimensions())
|
||||
|
||||
# Public: Get the load settings for the current window.
|
||||
#
|
||||
# Returns an object containing all the load setting key/value pairs.
|
||||
getLoadSettings: ->
|
||||
@loadSettings ?= _.deepClone(@getCurrentWindow().loadSettings)
|
||||
_.deepClone(@loadSettings)
|
||||
@constructor.getLoadSettings()
|
||||
|
||||
# Private:
|
||||
deserializeProject: ->
|
||||
Project = require './project'
|
||||
@project = @getWindowState('project')
|
||||
unless @project instanceof Project
|
||||
@project = new Project(path: @getLoadSettings().initialPath)
|
||||
@setWindowState('project', @project)
|
||||
@project ?= new Project(path: @getLoadSettings().initialPath)
|
||||
|
||||
# Private:
|
||||
deserializeWorkspaceView: ->
|
||||
WorkspaceView = require './workspace-view'
|
||||
state = @getWindowState()
|
||||
@workspaceView = @deserializers.deserialize(state.get('workspaceView'))
|
||||
@workspaceView = @deserializers.deserialize(@state.get('workspaceView'))
|
||||
unless @workspaceView?
|
||||
@workspaceView = new WorkspaceView()
|
||||
state.set('workspaceView', @workspaceView.getState())
|
||||
@state.set('workspaceView', @workspaceView.getState())
|
||||
$(@workspaceViewParentSelector).append(@workspaceView)
|
||||
|
||||
# Private:
|
||||
deserializePackageStates: ->
|
||||
state = @getWindowState()
|
||||
@packages.packageStates = state.getObject('packageStates') ? {}
|
||||
state.remove('packageStates')
|
||||
@packages.packageStates = @state.getObject('packageStates') ? {}
|
||||
@state.remove('packageStates')
|
||||
|
||||
# Private:
|
||||
deserializeEditorWindow: ->
|
||||
@@ -172,15 +244,14 @@ class Atom
|
||||
@deserializeProject()
|
||||
@deserializeWorkspaceView()
|
||||
|
||||
# Private: This method is only called when opening a real application window
|
||||
# Private: Call this method when establishing a real application window.
|
||||
startEditorWindow: ->
|
||||
if process.platform is 'darwin'
|
||||
CommandInstaller = require './command-installer'
|
||||
CommandInstaller.installAtomCommand()
|
||||
CommandInstaller.installApmCommand()
|
||||
|
||||
@windowEventHandler = new WindowEventHandler
|
||||
@restoreDimensions()
|
||||
@restoreWindowDimensions()
|
||||
@config.load()
|
||||
@config.setDefaults('core', require('./workspace-view').configDefaults)
|
||||
@config.setDefaults('editor', require('./editor-view').configDefaults)
|
||||
@@ -204,29 +275,17 @@ class Atom
|
||||
unloadEditorWindow: ->
|
||||
return if not @project and not @workspaceView
|
||||
|
||||
windowState = @getWindowState()
|
||||
windowState.set('project', @project)
|
||||
windowState.set('syntax', @syntax.serialize())
|
||||
windowState.set('workspaceView', @workspaceView.serialize())
|
||||
@state.set('syntax', @syntax.serialize())
|
||||
@state.set('workspaceView', @workspaceView.serialize())
|
||||
@packages.deactivatePackages()
|
||||
windowState.set('packageStates', @packages.packageStates)
|
||||
@saveWindowState()
|
||||
@state.set('packageStates', @packages.packageStates)
|
||||
@saveSync()
|
||||
@workspaceView.remove()
|
||||
@workspaceView = null
|
||||
@project.destroy()
|
||||
@windowEventHandler?.unsubscribe()
|
||||
@windowState = null
|
||||
|
||||
# Set up the default event handlers and menus for a non-editor window.
|
||||
#
|
||||
# This can be used by packages to have a minimum level of keybindings and
|
||||
# menus available when not using the standard editor window.
|
||||
#
|
||||
# This should only be called after setUpEnvironment() has been called.
|
||||
setUpDefaultEvents: ->
|
||||
@windowEventHandler = new WindowEventHandler
|
||||
@keymap.loadBundledKeymaps()
|
||||
@menu.update()
|
||||
|
||||
# Private:
|
||||
loadThemes: ->
|
||||
@themes.load()
|
||||
@@ -362,11 +421,11 @@ class Atom
|
||||
|
||||
# Public: Get the version of the Atom application.
|
||||
getVersion: ->
|
||||
@version ?= app.getVersion()
|
||||
@constructor.getVersion()
|
||||
|
||||
# Public: Determine whether the current version is an official release.
|
||||
isReleasedVersion: ->
|
||||
not /\w{7}/.test(@getVersion()) # Check if the release is a 7-character SHA prefix
|
||||
@constructor.isReleasedVersion()
|
||||
|
||||
getGitHubAuthTokenName: ->
|
||||
'Atom GitHub API Token'
|
||||
@@ -383,86 +442,15 @@ class Atom
|
||||
#
|
||||
# Returns the absolute path to ~/.atom
|
||||
getConfigDirPath: ->
|
||||
@configDirPath ?= fs.absolute('~/.atom')
|
||||
|
||||
# Public: Get the directory path to Atom's storage area.
|
||||
#
|
||||
# Returns the absoluste path to ~/.atom/storage
|
||||
getStorageDirPath: ->
|
||||
@storageDirPath ?= path.join(@getConfigDirPath(), 'storage')
|
||||
@constructor.getConfigDirPath()
|
||||
|
||||
# Private:
|
||||
getWindowStatePath: ->
|
||||
switch @windowMode
|
||||
when 'spec'
|
||||
filename = @windowMode
|
||||
when 'editor'
|
||||
{initialPath} = @getLoadSettings()
|
||||
if initialPath
|
||||
sha1 = crypto.createHash('sha1').update(initialPath).digest('hex')
|
||||
filename = "editor-#{sha1}"
|
||||
|
||||
if filename
|
||||
path.join(@getStorageDirPath(), filename)
|
||||
saveSync: ->
|
||||
if statePath = @constructor.getStatePath(@mode)
|
||||
super(statePath)
|
||||
else
|
||||
null
|
||||
@getCurrentWindow().loadSettings.windowState = JSON.stringify(@serializeForPersistence())
|
||||
|
||||
# Public: Set the window state of the given keypath to the value.
|
||||
setWindowState: (keyPath, value) ->
|
||||
windowState = @getWindowState()
|
||||
windowState.set(keyPath, value)
|
||||
windowState
|
||||
|
||||
# Private
|
||||
loadSerializedWindowState: ->
|
||||
if windowStatePath = @getWindowStatePath()
|
||||
if fs.existsSync(windowStatePath)
|
||||
try
|
||||
documentStateJson = fs.readFileSync(windowStatePath, 'utf8')
|
||||
catch error
|
||||
console.warn "Error reading window state: #{windowStatePath}", error.stack, error
|
||||
else
|
||||
documentStateJson = @getLoadSettings().windowState
|
||||
|
||||
try
|
||||
documentState = JSON.parse(documentStateJson) if documentStateJson
|
||||
catch error
|
||||
console.warn "Error parsing window state: #{windowStatePath}", error.stack, error
|
||||
|
||||
# Private:
|
||||
loadWindowState: ->
|
||||
serializedWindowState = @loadSerializedWindowState()
|
||||
doc = Document.deserialize(serializedWindowState) if serializedWindowState?
|
||||
doc ?= Document.create()
|
||||
doc.registerModelClasses(
|
||||
require('./text-buffer'),
|
||||
require('./project'),
|
||||
require('./tokenized-buffer'),
|
||||
require('./display-buffer'),
|
||||
require('./editor')
|
||||
)
|
||||
# TODO: Remove this when everything is using telepath models
|
||||
if @site?
|
||||
@site.setRootDocument(doc)
|
||||
else
|
||||
@site = new SiteShim(doc)
|
||||
doc
|
||||
|
||||
# Private:
|
||||
saveWindowState: ->
|
||||
windowState = @getWindowState()
|
||||
if windowStatePath = @getWindowStatePath()
|
||||
windowState.saveSync(windowStatePath)
|
||||
else
|
||||
@getCurrentWindow().loadSettings.windowState = JSON.stringify(windowState.serializeForPersistence())
|
||||
|
||||
# Public: Get the window state for the key path.
|
||||
getWindowState: (keyPath) ->
|
||||
@windowState ?= @loadWindowState()
|
||||
if keyPath
|
||||
@windowState.get(keyPath)
|
||||
else
|
||||
@windowState
|
||||
|
||||
# Public: Get the time taken to completely load the current window.
|
||||
#
|
||||
@@ -474,10 +462,6 @@ class Atom
|
||||
getWindowLoadTime: ->
|
||||
@loadTime
|
||||
|
||||
# Private: Returns a replicated copy of the current state.
|
||||
replicate: ->
|
||||
@getWindowState().replicate()
|
||||
|
||||
# Private:
|
||||
crashMainProcess: ->
|
||||
remote.process.crash()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{Document, Model} = require 'telepath'
|
||||
{TelepathicObject, Model} = require 'telepath'
|
||||
|
||||
# Public: Manages the deserializers used for serialized state
|
||||
#
|
||||
@@ -30,7 +30,7 @@ class DeserializerManager
|
||||
if deserializer = @get(state)
|
||||
stateVersion = state.get?('version') ? state.version
|
||||
return if deserializer.version? and deserializer.version isnt stateVersion
|
||||
if (state instanceof Document) and not deserializer.acceptsDocuments
|
||||
if (state instanceof TelepathicObject) and not deserializer.acceptsDocuments
|
||||
state = state.toObject()
|
||||
deserializer.deserialize(state, params)
|
||||
else
|
||||
|
||||
@@ -1401,7 +1401,7 @@ class Editor extends Model
|
||||
|
||||
# Private:
|
||||
inspect: ->
|
||||
JSON.stringify @state.toObject()
|
||||
"<Editor #{@id}>"
|
||||
|
||||
# Private:
|
||||
logScreenLines: (start, end) -> @displayBuffer.logLines(start, end)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{$, View} = require './space-pen-extensions'
|
||||
telepath = require 'telepath'
|
||||
{TelepathicObject} = require 'telepath'
|
||||
|
||||
### Internal ###
|
||||
module.exports =
|
||||
@@ -10,12 +10,12 @@ class PaneAxis extends View
|
||||
new this(state)
|
||||
|
||||
initialize: (args...) ->
|
||||
if args[0] instanceof telepath.Document
|
||||
if args[0] instanceof TelepathicObject
|
||||
@state = args[0]
|
||||
@state.get('children').each (child, index) =>
|
||||
@addChild(atom.deserializers.deserialize(child), index, updateState: false)
|
||||
else
|
||||
@state = atom.site.createDocument(deserializer: @className(), children: [])
|
||||
@state = atom.create(deserializer: @className(), children: [])
|
||||
@addChild(child) for child in args
|
||||
|
||||
@state.get('children').on 'changed', ({index, insertedValues, removedValues, siteId}) =>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{$, View} = require './space-pen-extensions'
|
||||
Pane = require './pane'
|
||||
telepath = require 'telepath'
|
||||
{TelepathicObject} = require 'telepath'
|
||||
|
||||
# Private: Manages the list of panes within a {WorkspaceView}
|
||||
module.exports =
|
||||
@@ -19,11 +19,11 @@ class PaneContainer extends View
|
||||
@div class: 'panes'
|
||||
|
||||
initialize: (state) ->
|
||||
if state instanceof telepath.Document
|
||||
if state instanceof TelepathicObject
|
||||
@state = state
|
||||
@setRoot(atom.deserializers.deserialize(@state.get('root')))
|
||||
else
|
||||
@state = atom.site.createDocument(deserializer: 'PaneContainer')
|
||||
@state = atom.create(deserializer: 'PaneContainer')
|
||||
|
||||
@subscribe @state, 'changed', ({newValues, siteId}) =>
|
||||
return if siteId is @state.siteId
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{dirname} = require 'path'
|
||||
{$, View} = require './space-pen-extensions'
|
||||
_ = require 'underscore-plus'
|
||||
telepath = require 'telepath'
|
||||
{TelepathicObject} = require 'telepath'
|
||||
PaneRow = require './pane-row'
|
||||
PaneColumn = require './pane-column'
|
||||
|
||||
@@ -32,7 +32,7 @@ class Pane extends View
|
||||
# Private:
|
||||
initialize: (args...) ->
|
||||
@items = []
|
||||
if args[0] instanceof telepath.Document
|
||||
if args[0] instanceof TelepathicObject
|
||||
@state = args[0]
|
||||
@items = _.compact @state.get('items').map (item) ->
|
||||
item = atom.deserializers.deserialize(item)
|
||||
@@ -40,7 +40,7 @@ class Pane extends View
|
||||
item
|
||||
else
|
||||
@items = args
|
||||
@state = atom.site.createDocument
|
||||
@state = atom.create
|
||||
deserializer: 'Pane'
|
||||
items: @items.map (item) -> item.getState?() ? item.serialize()
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class Project extends Model
|
||||
@setPath(@path)
|
||||
|
||||
# Private: Called by telepath.
|
||||
beforePersistence: ->
|
||||
willBePersisted: ->
|
||||
@destroyUnretainedBuffers()
|
||||
|
||||
# Public: Register an opener for project files.
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
# Private: TODO remove once telepath upgrades are complete.
|
||||
module.exports =
|
||||
class SiteShim
|
||||
constructor: (document) ->
|
||||
@setRootDocument(document)
|
||||
|
||||
setRootDocument: (@document) ->
|
||||
@id = @document.siteId
|
||||
constructor: (@environment) ->
|
||||
{@id} = @environment.state.siteId
|
||||
|
||||
createDocument: (values) ->
|
||||
@document.create({values})
|
||||
@environment.create(values)
|
||||
|
||||
@@ -48,7 +48,7 @@ class TextBuffer extends telepath.Model
|
||||
@load() if @loadWhenAttached
|
||||
|
||||
# Private: Called by telepath.
|
||||
beforePersistence: ->
|
||||
willBePersisted: ->
|
||||
@modifiedWhenLastPersisted = @isModified()
|
||||
@digestWhenLastPersisted = @file?.getDigest()
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ require('crash-reporter').start(productName: 'Atom', companyName: 'GitHub')
|
||||
require './window'
|
||||
|
||||
Atom = require './atom'
|
||||
window.atom = new Atom()
|
||||
atom.setUpEnvironment('editor')
|
||||
window.atom = Atom.loadOrCreate('editor')
|
||||
atom.initialize()
|
||||
atom.startEditorWindow()
|
||||
window.atom.loadTime = Date.now() - startTime
|
||||
console.log "Window load time: #{atom.getWindowLoadTime()}ms"
|
||||
|
||||
@@ -38,7 +38,7 @@ class WindowEventHandler
|
||||
confirmed
|
||||
|
||||
@subscribe $(window), 'unload', ->
|
||||
atom.getWindowState().set('dimensions', atom.getDimensions())
|
||||
atom.storeWindowDimensions()
|
||||
|
||||
@subscribeToCommand $(window), 'window:toggle-full-screen', => atom.toggleFullScreen()
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ Q = require 'q'
|
||||
{$, $$, View} = require './space-pen-extensions'
|
||||
_ = require 'underscore-plus'
|
||||
fs = require 'fs-plus'
|
||||
telepath = require 'telepath'
|
||||
{TelepathicObject} = require 'telepath'
|
||||
EditorView = require './editor-view'
|
||||
Pane = require './pane'
|
||||
PaneColumn = require './pane-column'
|
||||
@@ -65,12 +65,12 @@ class WorkspaceView extends View
|
||||
|
||||
# Private:
|
||||
initialize: (state={}) ->
|
||||
if state instanceof telepath.Document
|
||||
if state instanceof TelepathicObject
|
||||
@state = state
|
||||
panes = atom.deserializers.deserialize(state.get('panes'))
|
||||
else
|
||||
panes = new PaneContainer
|
||||
@state = atom.site.createDocument
|
||||
@state = atom.create
|
||||
deserializer: @constructor.name
|
||||
version: @constructor.version
|
||||
panes: panes.getState()
|
||||
@@ -333,7 +333,6 @@ class WorkspaceView extends View
|
||||
# Private: Destroys everything.
|
||||
remove: ->
|
||||
editorView.remove() for editorView in @getEditorViews()
|
||||
atom.project?.destroy()
|
||||
super
|
||||
|
||||
# Private: Adds the destroyed item's uri to the list of items to reopen.
|
||||
|
||||
Reference in New Issue
Block a user