Open folder in current untitled window

Untitled windows will now have their project path set when a folder
is opened.
This commit is contained in:
Kevin Sawicki
2014-08-22 12:10:33 -07:00
parent 154fe4006f
commit a853a27857
4 changed files with 28 additions and 4 deletions

View File

@@ -308,6 +308,9 @@ class Atom extends Model
@themes.loadBaseStylesheets()
@packages.loadPackages()
@deserializeEditorWindow()
@watchProjectPath()
@packages.activate()
@keymaps.loadUserKeymap()
@requireUserInitScript()
@@ -347,6 +350,13 @@ class Atom extends Model
pack.reloadStylesheets?()
null
# Notify the browser project of the window's current project path
watchProjectPath: ->
onProjectPathChanged = =>
ipc.send('window-command', 'project-path-changed', @project.getPath())
@subscribe @project, 'path-changed', onProjectPathChanged
onProjectPathChanged()
# Public: Open a new Atom window using the given options.
#
# Calling this method without an options parameter will open a prompt to pick

View File

@@ -327,9 +327,17 @@ class AtomApplication
{pathToOpen, initialLine, initialColumn} = @locationForPathToOpen(pathToOpen)
unless pidToKillWhenClosed or newWindow
# Open files in the specified window or the last focused window
if fs.statSyncNoException(pathToOpen).isFile?()
existingWindow = window ? @topWindow
pathToOpenStat = fs.statSyncNoException(pathToOpen)
# Default to using the specified window or the last focused window
currentWindow = window ? @topWindow
if pathToOpenStat.isFile?()
# Open the file in the current window
existingWindow = currentWindow
else if pathToOpenStat.isDirectory?()
# Open the folder in the current window if it doesn't have a path
existingWindow = currentWindow unless currentWindow?.hasProjectPath()
# Don't reuse windows in dev mode
existingWindow ?= @windowForPath(pathToOpen) unless devMode

View File

@@ -49,6 +49,8 @@ class AtomWindow
@emit 'window:loaded'
@loaded = true
@browserWindow.on 'project-path-changed', (@projectPath) =>
@browserWindow.loadUrl @getUrl(loadSettings)
@browserWindow.focusOnWebView() if @isSpec
@@ -66,6 +68,8 @@ class AtomWindow
slashes: true
query: {loadSettings: JSON.stringify(loadSettings)}
hasProjectPath: -> @projectPath?.length > 0
getInitialPath: ->
@browserWindow.loadSettings.initialPath

View File

@@ -28,7 +28,9 @@ class WindowEventHandler
@subscribe $(window), 'blur', -> document.body.classList.add('is-blurred')
@subscribe $(window), 'window:open-path', (event, {pathToOpen, initialLine, initialColumn}) ->
unless fs.isDirectorySync(pathToOpen)
if fs.isDirectorySync(pathToOpen)
atom.project.setPath(pathToOpen) unless atom.project.getPath()
else
atom.workspace?.open(pathToOpen, {initialLine, initialColumn})
@subscribe $(window), 'beforeunload', =>