diff --git a/spec/project-spec.coffee b/spec/project-spec.coffee index a4e6c0a03..976a5774b 100644 --- a/spec/project-spec.coffee +++ b/spec/project-spec.coffee @@ -330,6 +330,28 @@ describe "Project", -> expect(atom.project.getPaths()).toEqual([oldPath]) expect(onDidChangePathsSpy).not.toHaveBeenCalled() + describe ".removePath(path)", -> + onDidChangePathsSpy = null + + beforeEach -> + onDidChangePathsSpy = jasmine.createSpy('onDidChangePaths listener') + atom.project.onDidChangePaths(onDidChangePathsSpy) + + it "removes the directory and repository for the path", -> + result = atom.project.removePath(atom.project.getPaths()[0]) + expect(atom.project.getDirectories()).toEqual([]) + expect(atom.project.getRepositories()).toEqual([]) + expect(atom.project.getPaths()).toEqual([]) + expect(result).toBe true + expect(onDidChangePathsSpy).toHaveBeenCalled() + + it "does nothing if the path is not one of the project's root paths", -> + originalPaths = atom.project.getPaths() + result = atom.project.removePath(originalPaths[0] + "xyz") + expect(result).toBe false + expect(atom.project.getPaths()).toEqual(originalPaths) + expect(onDidChangePathsSpy).not.toHaveBeenCalled() + describe ".relativize(path)", -> it "returns the path, relative to whichever root directory it is inside of", -> atom.project.addPath(temp.mkdirSync("another-path")) diff --git a/src/project.coffee b/src/project.coffee index ac2242a28..8844fa231 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -209,6 +209,29 @@ class Project extends Model @emit "path-changed" @emitter.emit 'did-change-paths', @getPaths() + # Public: remove a path from the project's list of root paths. + # + # * `projectPath` {String} The path to remove. + removePath: (projectPath) -> + projectPath = path.normalize(projectPath) + + indexToRemove = null + for directory, i in @rootDirectories + if directory.getPath() is projectPath + indexToRemove = i + break + + if indexToRemove? + [removedDirectory] = @rootDirectories.splice(indexToRemove, 1) + [removedRepository] = @repositories.splice(indexToRemove, 1) + removedDirectory.off() + removedRepository?.destroy() + @emit "path-changed" + @emitter.emit "did-change-paths", @getPaths() + true + else + false + # Public: Get an {Array} of {Directory}s associated with this project. getDirectories: -> @rootDirectories