Rename pathToOpen load setting to initialPath

Use the initialPath as the window state serialization key.

Also use the parent directory as the intitial path when the
path to open is a file.
This commit is contained in:
Corey Johnson & Kevin Sawicki
2013-06-11 15:38:04 -07:00
parent fc52ee518e
commit a4ee1eb785
3 changed files with 23 additions and 21 deletions

View File

@@ -15,12 +15,6 @@ window.atom =
getLoadSettings: ->
remote.getCurrentWindow().loadSettings
getPathToOpen: ->
@getLoadSettings().pathToOpen
setPathToOpen: (pathToOpen) ->
@getLoadSettings().pathToOpen = pathToOpen
getPackageState: (name) ->
@packageStates[name]
@@ -232,15 +226,16 @@ window.atom =
throw new Error("sendMessageToBrowserProcess no longer works for #{name}")
getWindowStatePath: ->
if @windowMode is 'config'
filename = 'config'
else if @windowMode is 'editor' and @getPathToOpen()
shasum = crypto.createHash('sha1')
shasum.update(@getPathToOpen())
filename = "editor-#{shasum.digest('hex')}"
else
filename = 'undefined'
switch @windowMode
when 'config'
filename = 'config'
when 'editor'
{initialPath} = @getLoadSettings()
if initialPath
sha1 = crypto.createHash('sha1').update(initialPath).digest('hex')
filename = "editor-#{sha1}"
filename ?= 'undefined'
fsUtils.join(config.userStoragePath, filename)
setWindowState: (keyPath, value) ->

View File

@@ -113,12 +113,12 @@ window.deserializeEditorWindow = ->
Project = require 'project'
Git = require 'git'
pathToOpen = atom.getPathToOpen()
{initialPath} = atom.getLoadSettings()
windowState = atom.getWindowState()
atom.packageStates = windowState.packageStates ? {}
window.project = new Project(pathToOpen)
window.project = new Project(initialPath)
window.rootView = deserialize(windowState.rootView) ? new RootView
$(rootViewParentSelector).append(rootView)

View File

@@ -2,6 +2,7 @@ BrowserWindow = require 'browser-window'
dialog = require 'dialog'
ipc = require 'ipc'
path = require 'path'
fs = require 'fs'
module.exports =
class AtomWindow
@@ -13,19 +14,25 @@ class AtomWindow
@browserWindow = new BrowserWindow show: false, title: 'Atom'
@handleEvents()
@browserWindow.loadSettings = {pathToOpen, bootstrapScript, resourcePath, exitWhenDone}
initialPath = pathToOpen
try
initialPath = path.dirname(pathToOpen) if fs.statSync(pathToOpen).isFile()
@browserWindow.loadSettings = {initialPath, bootstrapScript, resourcePath, exitWhenDone}
@browserWindow.once 'window:loaded', => @loaded = true
@browserWindow.loadUrl "file://#{resourcePath}/static/index.html"
getPathToOpen: ->
@browserWindow.loadSettings.pathToOpen
@openPath(pathToOpen)
getInitialPath: ->
@browserWindow.loadSettings.initialPath
containsPath: (pathToCheck) ->
if not pathToCheck
false
else if pathToCheck is @getPathToOpen()
else if pathToCheck is @getInitialPath()
true
else if pathToCheck.indexOf(path.join(@getPathToOpen(), path.sep)) is 0
else if pathToCheck.indexOf(path.join(@getInitialPath(), path.sep)) is 0
true
else
false