diff --git a/src/atom.coffee b/src/atom.coffee index d497d1701..f208c3f92 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -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 diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index 624359ba9..81c561778 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -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 diff --git a/src/browser/atom-window.coffee b/src/browser/atom-window.coffee index 04d647ba6..4958dd782 100644 --- a/src/browser/atom-window.coffee +++ b/src/browser/atom-window.coffee @@ -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 diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index bdf50bd4b..5f2b09b62 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -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', =>