From 4c9e6c5a27e9c12cf2fba2b264596728e252aad2 Mon Sep 17 00:00:00 2001 From: Mostafa Eweda Date: Wed, 27 May 2015 11:18:15 -0700 Subject: [PATCH 1/3] Revert "Merge pull request #6977 from atom/revert-6813-local-initial-paths" This reverts commit 0c668022789a06330e2a6ddc73478a458bc3c625, reversing changes made to bdce576ab9c7e7a1a9cd0736999db5c38eac2a94. --- spec/default-directory-provider-spec.coffee | 6 ++++++ spec/integration/startup-spec.coffee | 10 ++++++++++ spec/window-spec.coffee | 11 +++++++++++ src/browser/atom-application.coffee | 8 +++++++- src/browser/main.coffee | 9 ++++++--- src/default-directory-provider.coffee | 21 +++++++++++++++------ src/window-event-handler.coffee | 10 ++++++---- 7 files changed, 61 insertions(+), 14 deletions(-) diff --git a/spec/default-directory-provider-spec.coffee b/spec/default-directory-provider-spec.coffee index 69370a77b..357348c4a 100644 --- a/spec/default-directory-provider-spec.coffee +++ b/spec/default-directory-provider-spec.coffee @@ -31,6 +31,12 @@ describe "DefaultDirectoryProvider", -> directory = provider.directoryForURISync(file) expect(directory.getPath()).toEqual tmp + it "creates a Directory with a path as a uri when passed a uri", -> + provider = new DefaultDirectoryProvider() + uri = 'remote://server:6792/path/to/a/dir' + directory = provider.directoryForURISync(uri) + expect(directory.getPath()).toEqual uri + describe ".directoryForURI(uri)", -> it "returns a Promise that resolves to a Directory with a path that matches the uri", -> provider = new DefaultDirectoryProvider() diff --git a/spec/integration/startup-spec.coffee b/spec/integration/startup-spec.coffee index 54817fedc..d2583ed27 100644 --- a/spec/integration/startup-spec.coffee +++ b/spec/integration/startup-spec.coffee @@ -227,3 +227,13 @@ describe "Starting Atom", -> [tempDirPath] [otherTempDirPath] ].sort() + + describe "opening a remote directory", -> + it "opens the parent directory and creates an empty text editor", -> + remoteDirectory = 'remote://server:3437/some/directory/path' + runAtom [remoteDirectory], {ATOM_HOME: atomHome}, (client) -> + client + .waitForWindowCount(1, 1000) + .waitForExist("atom-workspace", 5000) + .treeViewRootDirectories() + .then ({value}) -> expect(value).toEqual([remoteDirectory]) diff --git a/spec/window-spec.coffee b/spec/window-spec.coffee index 376a71ab3..94e605a36 100644 --- a/spec/window-spec.coffee +++ b/spec/window-spec.coffee @@ -293,3 +293,14 @@ describe "Window", -> pathToOpen = __dirname atom.getCurrentWindow().send 'message', 'open-locations', [{pathToOpen}] expect(atom.workspace.open.callCount).toBe 0 + + describe "when the opened path is a uri", -> + it "adds it to the project's paths as is", -> + pathToOpen = 'remote://server:7644/some/dir/path' + atom.getCurrentWindow().send 'message', 'open-locations', [{pathToOpen}] + + waitsFor -> + atom.project.getPaths().length is 1 + + runs -> + expect(atom.project.getPaths()[0]).toBe pathToOpen diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index 1b2aa2e86..5bd6be73e 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -369,7 +369,12 @@ class AtomApplication # :windowDimensions - Object with height and width keys. # :window - {AtomWindow} to open file paths in. openPaths: ({pathsToOpen, pidToKillWhenClosed, newWindow, devMode, safeMode, apiPreviewMode, windowDimensions, profileStartup, window}={}) -> - pathsToOpen = (fs.normalize(pathToOpen) for pathToOpen in pathsToOpen) + pathsToOpen = pathsToOpen.map (pathToOpen) -> + if fs.existsSync(pathToOpen) + fs.normalize(pathToOpen) + else + pathToOpen + locationsToOpen = (@locationForPathToOpen(pathToOpen) for pathToOpen in pathsToOpen) unless pidToKillWhenClosed or newWindow @@ -518,6 +523,7 @@ class AtomApplication locationForPathToOpen: (pathToOpen) -> return {pathToOpen} unless pathToOpen + return {pathToOpen} if url.parse(pathToOpen).protocol? return {pathToOpen} if fs.existsSync(pathToOpen) pathToOpen = pathToOpen.replace(/[:\s]+$/, '') diff --git a/src/browser/main.coffee b/src/browser/main.coffee index 1af0526dd..371dd71ea 100644 --- a/src/browser/main.coffee +++ b/src/browser/main.coffee @@ -5,6 +5,7 @@ app = require 'app' fs = require 'fs-plus' path = require 'path' yargs = require 'yargs' +url = require 'url' nslog = require 'nslog' console.log = nslog @@ -45,9 +46,11 @@ start = -> cwd = args.executedFrom?.toString() or process.cwd() args.pathsToOpen = args.pathsToOpen.map (pathToOpen) -> - pathToOpen = fs.normalize(pathToOpen) - if cwd - path.resolve(cwd, pathToOpen) + normalizedPath = fs.normalize(pathToOpen) + if url.parse(pathToOpen).protocol? + pathToOpen + else if cwd + path.resolve(cwd, normalizedPath) else path.resolve(pathToOpen) diff --git a/src/default-directory-provider.coffee b/src/default-directory-provider.coffee index 9e25e097b..da2d17593 100644 --- a/src/default-directory-provider.coffee +++ b/src/default-directory-provider.coffee @@ -1,6 +1,7 @@ {Directory} = require 'pathwatcher' fs = require 'fs-plus' path = require 'path' +url = require 'url' module.exports = class DefaultDirectoryProvider @@ -14,14 +15,22 @@ class DefaultDirectoryProvider # * {Directory} if the given URI is compatible with this provider. # * `null` if the given URI is not compatibile with this provider. directoryForURISync: (uri) -> - projectPath = path.normalize(uri) - - directoryPath = if not fs.isDirectorySync(projectPath) and fs.isDirectorySync(path.dirname(projectPath)) - path.dirname(projectPath) + normalizedPath = path.normalize(uri) + {protocol} = url.parse(uri) + directoryPath = if protocol? + uri + else if not fs.isDirectorySync(normalizedPath) and fs.isDirectorySync(path.dirname(normalizedPath)) + path.dirname(normalizedPath) else - projectPath + normalizedPath - new Directory(directoryPath) + # TODO: Stop normalizing the path in pathwatcher's Directory. + directory = new Directory(directoryPath) + if protocol? + directory.path = directoryPath + if fs.isCaseInsensitive() + directory.lowerCasePath = directoryPath.toLowerCase() + directory # Public: Create a Directory that corresponds to the specified URI. # diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index 7d67e87ab..0855b27a1 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -5,6 +5,7 @@ ipc = require 'ipc' shell = require 'shell' {Subscriber} = require 'emissary' fs = require 'fs-plus' +url = require 'url' # Handles low-level events related to the window. module.exports = @@ -23,12 +24,13 @@ class WindowEventHandler if pathToOpen? and needsProjectPaths if fs.existsSync(pathToOpen) atom.project.addPath(pathToOpen) + else if fs.existsSync(path.dirname(pathToOpen)) + atom.project.addPath(path.dirname(pathToOpen)) else - dirToOpen = path.dirname(pathToOpen) - if fs.existsSync(dirToOpen) - atom.project.addPath(dirToOpen) + atom.project.addPath(pathToOpen) - unless fs.isDirectorySync(pathToOpen) + {protocol} = url.parse(pathToOpen) + unless fs.isDirectorySync(pathToOpen) or protocol? atom.workspace?.open(pathToOpen, {initialLine, initialColumn}) return From 5e7bc308d4a0a78d1a99ac4fb1750623c7b13f3d Mon Sep 17 00:00:00 2001 From: Mostafa Eweda Date: Wed, 27 May 2015 11:20:49 -0700 Subject: [PATCH 2/3] Remove the protocol parse and check in the window-event-handler --- src/window-event-handler.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index 0855b27a1..c9fd94681 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -29,8 +29,7 @@ class WindowEventHandler else atom.project.addPath(pathToOpen) - {protocol} = url.parse(pathToOpen) - unless fs.isDirectorySync(pathToOpen) or protocol? + unless fs.isDirectorySync(pathToOpen) atom.workspace?.open(pathToOpen, {initialLine, initialColumn}) return From 952f92c367bccd1128d338bab539ea5aefef817f Mon Sep 17 00:00:00 2001 From: Mostafa Eweda Date: Wed, 27 May 2015 11:38:06 -0700 Subject: [PATCH 3/3] Remove uneeded require to url --- src/window-event-handler.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index c9fd94681..3b9d54b96 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -5,7 +5,6 @@ ipc = require 'ipc' shell = require 'shell' {Subscriber} = require 'emissary' fs = require 'fs-plus' -url = require 'url' # Handles low-level events related to the window. module.exports =