Make all edit session uri's relative

This allows them to be collaborated without having absolute paths
in the shared document.
This commit is contained in:
Kevin Sawicki
2013-07-12 13:26:47 -07:00
parent a9710e7a63
commit 9ccf9365c3
8 changed files with 23 additions and 12 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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.
#