Restore state when opening folders to applicable windows

Note: "clean window" is defined as 1) having an empty project and 2)
having no pane items or only empty unnamed buffers

When project is empty and there is saved state associated with the
opened/added folders...
* Open a file or folder (from command line or Open menu)
  * If we have a clean window, restore project state in window
  * If window is dirty, restore saved state in new window
This commit is contained in:
Michelle Tilley
2017-03-22 20:25:57 -07:00
committed by Katrina Uychaco
parent 910fef97a0
commit d9b73fa645
3 changed files with 112 additions and 47 deletions

View File

@@ -1019,23 +1019,38 @@ class AtomEnvironment extends Model
openLocations: (locations) ->
needsProjectPaths = @project?.getPaths().length is 0
foldersToAddToProject = []
fileLocationsToOpen = []
pushFolderToOpen = (folder) ->
if folder not in foldersToAddToProject
foldersToAddToProject.push(folder)
for {pathToOpen, initialLine, initialColumn, forceAddToWindow} in locations
if pathToOpen? and (needsProjectPaths or forceAddToWindow)
if fs.existsSync(pathToOpen)
@project.addPath(pathToOpen)
pushFolderToOpen @project.getDirectoryForProjectPath(pathToOpen).getPath()
else if fs.existsSync(path.dirname(pathToOpen))
@project.addPath(path.dirname(pathToOpen))
pushFolderToOpen @project.getDirectoryForProjectPath(path.dirname(pathToOpen)).getPath()
else
@project.addPath(pathToOpen)
pushFolderToOpen @project.getDirectoryForProjectPath(pathToOpen).getPath()
unless fs.isDirectorySync(pathToOpen)
fileLocationsToOpen.push({pathToOpen, initialLine, initialColumn})
if foldersToAddToProject.length > 0
@loadState(@getStateKey(foldersToAddToProject)).then (state) =>
if state and needsProjectPaths # only load state if this is the first path added to the project
files = (location.pathToOpen for location in fileLocationsToOpen)
@attemptRestoreProjectStateForPaths(state, foldersToAddToProject, files)
else
@project.addPath(folder) for folder in foldersToAddToProject
for {pathToOpen, initialLine, initialColumn} in fileLocationsToOpen
@workspace?.open(pathToOpen, {initialLine, initialColumn})
else
for {pathToOpen, initialLine, initialColumn} in fileLocationsToOpen
@workspace?.open(pathToOpen, {initialLine, initialColumn})
if needsProjectPaths
@loadState(@getStateKey(@project.getPaths())).then (state) =>
@restoreStateIntoEnvironment(state) if state
return
Promise.resolve(null)
# Preserve this deprecation until 2.0. Sorry. Should have removed Q sooner.
Promise.prototype.done = (callback) ->

View File

@@ -184,11 +184,7 @@ class Project extends Model
#
# * `projectPath` {String} The path to the directory to add.
addPath: (projectPath, options) ->
directory = null
for provider in @directoryProviders
break if directory = provider.directoryForURISync?(projectPath)
directory ?= @defaultDirectoryProvider.directoryForURISync(projectPath)
directory = @getDirectoryForProjectPath(projectPath)
return unless directory.existsSync()
for existingDirectory in @getDirectories()
return if existingDirectory.getPath() is directory.getPath()
@@ -203,6 +199,13 @@ class Project extends Model
unless options?.emitEvent is false
@emitter.emit 'did-change-paths', @getPaths()
getDirectoryForProjectPath: (projectPath) ->
directory = null
for provider in @directoryProviders
break if directory = provider.directoryForURISync?(projectPath)
directory ?= @defaultDirectoryProvider.directoryForURISync(projectPath)
directory
# Public: remove a path from the project's list of root paths.
#
# * `projectPath` {String} The path to remove.