Revert "Deprecate Project::resolve"

This reverts commit 3c5bd9f10a.
This commit is contained in:
Nathan Sobo
2015-01-09 13:58:01 -08:00
parent 3c5bd9f10a
commit 19bf64f3cd
8 changed files with 85 additions and 48 deletions

View File

@@ -139,9 +139,25 @@ class Project extends Model
Grim.deprecate("Use ::getDirectories instead")
@rootDirectory
# Public: Given a uri, this resolves it relative to the project directory. If
# the path is already absolute or if it is prefixed with a scheme, it is
# returned unchanged.
#
# * `uri` The {String} name of the path to convert.
#
# Returns a {String} or undefined if the uri is not missing or empty.
resolve: (uri) ->
Grim.deprecate("Use `Project::getDirectories()[0]?.resolve()` instead")
@rootDirectory?.resolve(uri)
return unless uri
if uri?.match(/[A-Za-z0-9+-.]+:\/\//) # leave path alone if it has a scheme
uri
else
if fs.isAbsolute(uri)
path.normalize(fs.absolute(uri))
else if projectPath = @getPaths()[0]
path.normalize(fs.absolute(path.join(projectPath, uri)))
else
undefined
# Public: Make the given path relative to the project directory.
#
@@ -204,14 +220,14 @@ class Project extends Model
#
# Returns a promise that resolves to an {TextEditor}.
open: (filePath, options={}) ->
filePath = @rootDirectory?.resolve(filePath)
filePath = @resolve(filePath)
@bufferForPath(filePath).then (buffer) =>
@buildEditorForBuffer(buffer, options)
# Deprecated
openSync: (filePath, options={}) ->
deprecate("Use Project::open instead")
filePath = @rootDirectory?.resolve(filePath)
filePath = @resolve(filePath)
@buildEditorForBuffer(@bufferForPathSync(filePath), options)
# Retrieves all the {TextBuffer}s in the project; that is, the
@@ -223,14 +239,14 @@ class Project extends Model
# Is the buffer for the given path modified?
isPathModified: (filePath) ->
@findBufferForPath(@rootDirectory?.resolve(filePath))?.isModified()
@findBufferForPath(@resolve(filePath))?.isModified()
findBufferForPath: (filePath) ->
_.find @buffers, (buffer) -> buffer.getPath() == filePath
# Only to be used in specs
bufferForPathSync: (filePath) ->
absoluteFilePath = @rootDirectory?.resolve(filePath)
absoluteFilePath = @resolve(filePath)
existingBuffer = @findBufferForPath(absoluteFilePath) if filePath
existingBuffer ? @buildBufferSync(absoluteFilePath)
@@ -243,7 +259,7 @@ class Project extends Model
#
# Returns a promise that resolves to the {TextBuffer}.
bufferForPath: (filePath) ->
absoluteFilePath = @rootDirectory?.resolve(filePath)
absoluteFilePath = @resolve(filePath)
existingBuffer = @findBufferForPath(absoluteFilePath) if absoluteFilePath
Q(existingBuffer ? @buildBuffer(absoluteFilePath))

View File

@@ -383,7 +383,7 @@ class Workspace extends Model
open: (uri, options={}) ->
searchAllPanes = options.searchAllPanes
split = options.split
uri = atom.project.getDirectories()[0]?.resolve(uri)
uri = atom.project.resolve(uri)
pane = @paneContainer.paneForUri(uri) if searchAllPanes
pane ?= switch split
@@ -422,7 +422,7 @@ class Workspace extends Model
{initialLine, initialColumn} = options
activatePane = options.activatePane ? true
uri = atom.project.getDirectories()[0]?.resolve(uri)
uri = atom.project.resolve(uri)
item = @getActivePane().itemForUri(uri)
if uri
@@ -445,7 +445,7 @@ class Workspace extends Model
if uri?
item = pane.itemForUri(uri)
item ?= opener(atom.project.getDirectories()[0]?.resolve(uri), options) for opener in @getOpeners() when !item
item ?= opener(atom.project.resolve(uri), options) for opener in @getOpeners() when !item
item ?= atom.project.open(uri, options)
Q(item)