mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Remove @path var from project
This commit is contained in:
@@ -69,5 +69,5 @@ describe "Project", ->
|
||||
describe "when path is null", ->
|
||||
it "sets its path and root directory to null", ->
|
||||
project.setPath(null)
|
||||
expect(project.getPath()).toBeNull()
|
||||
expect(project.getRootDirectory()).toBeNull()
|
||||
expect(project.getPath()?).toBeFalsy()
|
||||
expect(project.getRootDirectory()?).toBeFalsy()
|
||||
|
||||
@@ -20,7 +20,7 @@ describe "RootView", ->
|
||||
describe "when called with a pathToOpen", ->
|
||||
describe "when pathToOpen references a file", ->
|
||||
it "creates a project for the file's parent directory, then sets the document.title and opens the file in an editor", ->
|
||||
expect(rootView.project.path).toBe fs.directory(path)
|
||||
expect(rootView.project.getPath()).toBe fs.directory(path)
|
||||
expect(rootView.editors().length).toBe 1
|
||||
expect(rootView.editors()[0]).toHaveClass 'active'
|
||||
expect(rootView.activeEditor().buffer.getPath()).toBe path
|
||||
@@ -33,7 +33,7 @@ describe "RootView", ->
|
||||
rootView = new RootView(pathToOpen: path)
|
||||
rootView.focus()
|
||||
|
||||
expect(rootView.project.path).toBe path
|
||||
expect(rootView.project.getPath()).toBe path
|
||||
expect(rootView.editors().length).toBe 0
|
||||
expect(document.title).toBe path
|
||||
|
||||
@@ -53,7 +53,7 @@ describe "RootView", ->
|
||||
|
||||
it "constructs the view with the same panes", ->
|
||||
rootView = RootView.deserialize(viewState)
|
||||
expect(rootView.project.path).toBeNull()
|
||||
expect(rootView.project.getPath()?).toBeFalsy()
|
||||
expect(rootView.editors().length).toBe 2
|
||||
expect(rootView.activeEditor().buffer.getText()).toBe buffer.getText()
|
||||
expect(document.title).toBe 'untitled'
|
||||
@@ -377,9 +377,9 @@ describe "RootView", ->
|
||||
it "creates a project if there isn't one yet and the buffer was previously unsaved", ->
|
||||
rootView = new RootView
|
||||
rootView.open()
|
||||
expect(rootView.project.path).toBeNull()
|
||||
expect(rootView.project.getPath()?).toBeFalsy()
|
||||
rootView.activeEditor().buffer.saveAs('/tmp/ignore-me')
|
||||
expect(rootView.project.path).toBe '/tmp'
|
||||
expect(rootView.project.getPath()).toBe '/tmp'
|
||||
|
||||
describe "when editors are focused", ->
|
||||
it "triggers 'active-editor-path-change' events if the path of the active editor actually changes", ->
|
||||
@@ -407,5 +407,5 @@ describe "RootView", ->
|
||||
describe "when the last editor is removed", ->
|
||||
it "updates the title to the project path", ->
|
||||
rootView.editors()[0].remove()
|
||||
expect(document.title).toBe rootView.project.path
|
||||
expect(document.title).toBe rootView.project.getPath()
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ describe 'FileFinder', ->
|
||||
|
||||
describe "when root view's project has no path", ->
|
||||
beforeEach ->
|
||||
rootView.project.path = undefined
|
||||
rootView.project.setPath(null)
|
||||
|
||||
it "does not open the FileFinder", ->
|
||||
expect(rootView.find('.file-finder')).not.toExist()
|
||||
|
||||
@@ -43,7 +43,7 @@ describe "TreeView", ->
|
||||
expect(rootEntries.find('> .file:contains(sample.js)')).toExist()
|
||||
expect(rootEntries.find('> .file:contains(sample.txt)')).toExist()
|
||||
|
||||
describe "when the project has not path", ->
|
||||
describe "when the project has no path", ->
|
||||
beforeEach ->
|
||||
treeView.deactivate()
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ Directory = require 'directory'
|
||||
|
||||
module.exports =
|
||||
class Project
|
||||
path: null
|
||||
rootDirectory: null
|
||||
buffers: null
|
||||
|
||||
@@ -15,16 +14,15 @@ class Project
|
||||
@buffers = []
|
||||
|
||||
getPath: ->
|
||||
@path
|
||||
@rootDirectory?.path
|
||||
|
||||
setPath: (path) ->
|
||||
@rootDirectory.off() if @rootDirectory
|
||||
@rootDirectory?.off()
|
||||
|
||||
if path?
|
||||
@path = if fs.isDirectory(path) then path else fs.directory(path)
|
||||
@rootDirectory = new Directory(@path)
|
||||
directory = if fs.isDirectory(path) then path else fs.directory(path)
|
||||
@rootDirectory = new Directory(directory)
|
||||
else
|
||||
@path = null
|
||||
@rootDirectory = null
|
||||
|
||||
@trigger "path-change"
|
||||
@@ -33,8 +31,7 @@ class Project
|
||||
@rootDirectory
|
||||
|
||||
getFilePaths: ->
|
||||
projectPath = @path
|
||||
fs.async.listTree(@path).pipe (paths) =>
|
||||
fs.async.listTree(@getPath()).pipe (paths) =>
|
||||
@relativize(path) for path in paths when fs.isFile(path)
|
||||
|
||||
open: (filePath) ->
|
||||
@@ -51,11 +48,11 @@ class Project
|
||||
buffer
|
||||
|
||||
resolve: (filePath) ->
|
||||
filePath = fs.join(@path, filePath) unless filePath[0] == '/'
|
||||
filePath = fs.join(@getPath(), filePath) unless filePath[0] == '/'
|
||||
fs.absolute filePath
|
||||
|
||||
relativize: (fullPath) ->
|
||||
fullPath.replace(@path, "").replace(/^\//, '')
|
||||
fullPath.replace(@getPath(), "").replace(/^\//, '')
|
||||
|
||||
bufferWithId: (id) ->
|
||||
return buffer for buffer in @buffers when buffer.id == id
|
||||
|
||||
@@ -39,11 +39,10 @@ class RootView extends View
|
||||
|
||||
@setTitle()
|
||||
@project = new Project(pathToOpen)
|
||||
if pathToOpen? and fs.isFile(pathToOpen)
|
||||
@open(pathToOpen)
|
||||
@open(pathToOpen) if fs.isFile(pathToOpen)
|
||||
|
||||
serialize: ->
|
||||
projectPath: @project?.path
|
||||
projectPath: @project?.getPath()
|
||||
panesViewState: @panes.children().view()?.serialize()
|
||||
extensionStates: @serializeExtensions()
|
||||
|
||||
@@ -57,7 +56,7 @@ class RootView extends View
|
||||
@setTitle(@project?.getPath())
|
||||
|
||||
@on 'active-editor-path-change', (e, path) =>
|
||||
@project.setPath(path) unless @project.getPath()
|
||||
@project.setPath(path) unless @project.getRootDirectory()
|
||||
@setTitle(path)
|
||||
|
||||
afterAttach: (onDom) ->
|
||||
|
||||
@@ -33,7 +33,7 @@ class FileFinder extends View
|
||||
if @hasParent()
|
||||
@detach()
|
||||
else
|
||||
@attach() if @rootView.project.path?
|
||||
@attach() if @rootView.project.getPath()?
|
||||
|
||||
attach: ->
|
||||
@rootView.project.getFilePaths().done (@paths) => @populatePathList()
|
||||
|
||||
Reference in New Issue
Block a user