From 9ccf9365c3c8a4dff334fe1ca9d1a9e8003b4c64 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 12 Jul 2013 13:26:47 -0700 Subject: [PATCH] Make all edit session uri's relative This allows them to be collaborated without having absolute paths in the shared document. --- spec/app/project-spec.coffee | 3 ++- src/app/directory.coffee | 8 ++++++-- src/app/edit-session.coffee | 2 +- src/app/project.coffee | 1 + src/app/root-view.coffee | 2 +- src/app/text-buffer.coffee | 5 ++++- src/packages/archive-view/lib/archive-edit-session.coffee | 7 ++++--- src/packages/image-view/lib/image-edit-session.coffee | 7 ++++--- 8 files changed, 23 insertions(+), 12 deletions(-) diff --git a/spec/app/project-spec.coffee b/spec/app/project-spec.coffee index 7ae1e62cc..e73041c37 100644 --- a/spec/app/project-spec.coffee +++ b/spec/app/project-spec.coffee @@ -82,7 +82,8 @@ describe "Project", -> describe "when passed a path that matches a custom opener", -> it "returns the resource returned by the custom opener", -> - expect(project.open("a.foo", hey: "there")).toEqual { foo: "a.foo", options: {hey: "there"} } + pathToOpen = project.resolve('a.foo') + expect(project.open(pathToOpen, hey: "there")).toEqual { foo: pathToOpen, options: {hey: "there"} } expect(project.open("bar://baz")).toEqual { bar: "bar://baz" } describe ".bufferForPath(path)", -> diff --git a/src/app/directory.coffee b/src/app/directory.coffee index 802c814fd..e4bc243a6 100644 --- a/src/app/directory.coffee +++ b/src/app/directory.coffee @@ -49,7 +49,9 @@ class Directory # pathToCheck - the {String} path to check. # # Returns a {Boolean}. - contains: (pathToCheck='') -> + contains: (pathToCheck) -> + return false unless pathToCheck + if pathToCheck.indexOf(path.join(@getPath(), path.sep)) is 0 true else if pathToCheck.indexOf(path.join(@getRealPath(), path.sep)) is 0 @@ -62,7 +64,9 @@ class Directory # fullPath - The {String} path to convert. # # Returns a {String}. - relativize: (fullPath='') -> + relativize: (fullPath) -> + return fullPath unless fullPath + if fullPath is @getPath() '' else if fullPath.indexOf(path.join(@getPath(), path.sep)) is 0 diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index b7bb9e64c..d9ec4d836 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -304,7 +304,7 @@ class EditSession # Retrieves the current buffer's URI. # # Returns a {String}. - getUri: -> @getPath() + getUri: -> @buffer.getUri() # {Delegates to: Buffer.isRowBlank} isBufferRowBlank: (bufferRow) -> @buffer.isRowBlank(bufferRow) diff --git a/src/app/project.coffee b/src/app/project.coffee index 08fac445e..9abfd99ef 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -162,6 +162,7 @@ class Project # # Returns either an {EditSession} (for text) or {ImageEditSession} (for images). open: (filePath, options={}) -> + filePath = @resolve(filePath) if filePath? for opener in @constructor.openers return resource if resource = opener(filePath, options) diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index 0af310717..ee54e48d9 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -114,7 +114,7 @@ class RootView extends View # Returns the `EditSession` for the file URI. open: (path, options = {}) -> changeFocus = options.changeFocus ? true - path = project.resolve(path) if path? + path = project.relativize(path) if activePane = @getActivePane() editSession = activePane.itemForUri(path) ? project.open(path) activePane.showItem(editSession) diff --git a/src/app/text-buffer.coffee b/src/app/text-buffer.coffee index baed87b80..e5bf61052 100644 --- a/src/app/text-buffer.coffee +++ b/src/app/text-buffer.coffee @@ -74,7 +74,7 @@ class TextBuffer serialize: -> deserializer: 'TextBuffer' - path: @getPath() + path: @getUri() text: @getText() if @isModified() @deserialize: ({path, text}) -> @@ -133,6 +133,9 @@ class TextBuffer getPath: -> @file?.getPath() + getUri: -> + project?.relativize(@getPath()) ? @getPath() + # Sets the path for the file. # # path - A {String} representing the new file path diff --git a/src/packages/archive-view/lib/archive-edit-session.coffee b/src/packages/archive-view/lib/archive-edit-session.coffee index 94d6e7be9..c3a2e8e10 100644 --- a/src/packages/archive-view/lib/archive-edit-session.coffee +++ b/src/packages/archive-view/lib/archive-edit-session.coffee @@ -14,10 +14,11 @@ class ArchiveEditSession new ArchiveEditSession(filePath) if archive.isPathSupported(filePath) @deserialize: ({path}={}) -> + path = project.resolve(path) if fsUtils.isFileSync(path) new ArchiveEditSession(path) else - console.warn "Could not build edit session for path '#{path}' because that file no longer exists" + console.warn "Could not build archive edit session for path '#{path}' because that file no longer exists" constructor: (@path) -> @file = new File(@path) @@ -27,7 +28,7 @@ class ArchiveEditSession serialize: -> deserializer: 'ArchiveEditSession' - path: @path + path: @getUri() getViewClass: -> require './archive-view' @@ -38,7 +39,7 @@ class ArchiveEditSession else 'untitled' - getUri: -> @path + getUri: -> project?.relativize(@getPath()) ? @getPath() getPath: -> @path diff --git a/src/packages/image-view/lib/image-edit-session.coffee b/src/packages/image-view/lib/image-edit-session.coffee index ac0410350..cc59431f9 100644 --- a/src/packages/image-view/lib/image-edit-session.coffee +++ b/src/packages/image-view/lib/image-edit-session.coffee @@ -18,7 +18,8 @@ class ImageEditSession new ImageEditSession(filePath) @deserialize: ({path}={}) -> - if fsUtils.exists(path) + path = project.resolve(path) + if fsUtils.isFileSync(path) new ImageEditSession(path) else console.warn "Could not build image edit session for path '#{path}' because that file no longer exists" @@ -27,7 +28,7 @@ class ImageEditSession serialize: -> deserializer: 'ImageEditSession' - path: @path + path: @getUri() getViewClass: -> require './image-view' @@ -48,7 +49,7 @@ class ImageEditSession # Retrieves the URI of the current image. # # Returns a {String}. - getUri: -> @path + getUri: -> project?.relativize(@getPath()) ? @getPath() # Retrieves the path of the current image. #