Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/dialog.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{View} = require 'space-pen'
Editor = require 'editor'
fsUtils = require 'fs-utils'
{$, Editor, View} = require 'atom'
path = require 'path'
$ = require 'jquery'

module.exports =
class Dialog extends View
Expand Down
5 changes: 1 addition & 4 deletions lib/directory-view.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{View, $$} = require 'space-pen'
{$, $$, Directory, fs, View} = require 'atom'
FileView = require './file-view'
Directory = require 'directory'
$ = require 'jquery'
fs = require 'fs'

module.exports =
class DirectoryView extends View
Expand Down
14 changes: 6 additions & 8 deletions lib/file-view.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{View} = require 'space-pen'
$ = require 'jquery'
fsUtils = require 'fs-utils'
{$, fs, View} = require 'atom'
path = require 'path'

module.exports =
Expand All @@ -17,15 +15,15 @@ class FileView extends View
@fileName.addClass('icon-file-symlink-file')
else
extension = path.extname(@getPath())
if fsUtils.isReadmePath(@getPath())
if fs.isReadmePath(@getPath())
@fileName.addClass('icon-book')
else if fsUtils.isCompressedExtension(extension)
else if fs.isCompressedExtension(extension)
@fileName.addClass('icon-file-zip')
else if fsUtils.isImageExtension(extension)
else if fs.isImageExtension(extension)
@fileName.addClass('icon-file-media')
else if fsUtils.isPdfExtension(extension)
else if fs.isPdfExtension(extension)
@fileName.addClass('icon-file-pdf')
else if fsUtils.isBinaryExtension(extension)
else if fs.isBinaryExtension(extension)
@fileName.addClass('icon-file-binary')
else
@fileName.addClass('icon-file-text')
Expand Down
25 changes: 10 additions & 15 deletions lib/tree-view.coffee
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
{View, $$} = require 'space-pen'
ScrollView = require 'scroll-view'
Directory = require 'directory'
{_, $, $$, fs, ScrollView, View} = require 'atom'
DirectoryView = require './directory-view'
FileView = require './file-view'
Dialog = require './dialog'
fsUtils = require 'fs-utils'
path = require 'path'
shell = require 'shell'
$ = require 'jquery'
_ = require 'underscore'

module.exports =
class TreeView extends ScrollView
Expand Down Expand Up @@ -235,14 +230,14 @@ class TreeView extends ScrollView
dialog.close()
return

if fsUtils.exists(newPath)
if fs.exists(newPath)
dialog.showError("Error: #{newPath} already exists. Try a different path.")
return

directoryPath = path.dirname(newPath)
try
fsUtils.makeTree(directoryPath) unless fsUtils.exists(directoryPath)
fsUtils.move(oldPath, newPath)
fs.makeTree(directoryPath) unless fs.exists(directoryPath)
fs.move(oldPath, newPath)
dialog.close()
catch e
dialog.showError("Error: #{e.message} Try a different path.")
Expand All @@ -259,13 +254,13 @@ class TreeView extends ScrollView
"You are deleting #{entry.getPath()}",
"Move to Trash", (=> shell.moveItemToTrash(entry.getPath())),
"Cancel", null
"Delete", (=> fsUtils.remove(entry.getPath()))
"Delete", (=> fs.remove(entry.getPath()))
)

add: ->
selectedEntry = @selectedEntry() or @root
selectedPath = selectedEntry.getPath()
directoryPath = if fsUtils.isFileSync(selectedPath) then path.dirname(selectedPath) else selectedPath
directoryPath = if fs.isFileSync(selectedPath) then path.dirname(selectedPath) else selectedPath
relativeDirectoryPath = project.relativize(directoryPath)
relativeDirectoryPath += '/' if relativeDirectoryPath.length > 0

Expand All @@ -279,16 +274,16 @@ class TreeView extends ScrollView
endsWithDirectorySeparator = /\/$/.test(relativePath)
pathToCreate = project.resolve(relativePath)
try
if fsUtils.exists(pathToCreate)
pathType = if fsUtils.isFileSync(pathToCreate) then "file" else "directory"
if fs.exists(pathToCreate)
pathType = if fs.isFileSync(pathToCreate) then "file" else "directory"
dialog.showError("Error: A #{pathType} already exists at path '#{pathToCreate}'. Try a different path.")
else if endsWithDirectorySeparator
fsUtils.makeTree(pathToCreate)
fs.makeTree(pathToCreate)
dialog.cancel()
@entryForPath(pathToCreate).buildEntries()
@selectEntryForPath(pathToCreate)
else
fsUtils.writeSync(pathToCreate, "")
fs.writeSync(pathToCreate, "")
rootView.open(pathToCreate)
dialog.close()
catch e
Expand Down
97 changes: 46 additions & 51 deletions spec/tree-view-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
$ = require 'jquery'
{$$} = require 'space-pen'
_ = require 'underscore'
{_, $, $$, fs, RootView} = require 'atom'
TreeView = require '../lib/tree-view'
RootView = require 'root-view'
Directory = require 'directory'
fsUtils = require 'fs-utils'
path = require 'path'

describe "TreeView", ->
Expand Down Expand Up @@ -260,20 +255,20 @@ describe "TreeView", ->

sampleJs.trigger clickEvent(originalEvent: { detail: 1 })
expect(sampleJs).toHaveClass 'selected'
expect(rootView.getActiveView().getPath()).toBe fsUtils.resolveOnLoadPath('fixtures/tree-view/tree-view.js')
expect(rootView.getActiveView().getPath()).toBe project.resolve('tree-view.js')
expect(rootView.getActiveView().isFocused).toBeFalsy()

sampleTxt.trigger clickEvent(originalEvent: { detail: 1 })
expect(sampleTxt).toHaveClass 'selected'
expect(treeView.find('.selected').length).toBe 1
expect(rootView.getActiveView().getPath()).toBe fsUtils.resolveOnLoadPath('fixtures/tree-view/tree-view.txt')
expect(rootView.getActiveView().getPath()).toBe project.resolve('tree-view.txt')
expect(rootView.getActiveView().isFocused).toBeFalsy()

describe "when a file is double-clicked", ->
it "selects the file and opens it in the active editor on the first click, then changes focus to the active editor on the second", ->
sampleJs.trigger clickEvent(originalEvent: { detail: 1 })
expect(sampleJs).toHaveClass 'selected'
expect(rootView.getActiveView().getPath()).toBe fsUtils.resolveOnLoadPath('fixtures/tree-view/tree-view.js')
expect(rootView.getActiveView().getPath()).toBe project.resolve('tree-view.js')
expect(rootView.getActiveView().isFocused).toBeFalsy()

sampleJs.trigger clickEvent(originalEvent: { detail: 2 })
Expand Down Expand Up @@ -301,7 +296,7 @@ describe "TreeView", ->
describe "when the item has a path", ->
it "selects the entry with that path in the tree view if it is visible", ->
sampleJs.click()
rootView.open(require.resolve('fixtures/tree-view/tree-view.txt'))
rootView.open(project.resolve('tree-view.txt'))

expect(sampleTxt).toHaveClass 'selected'
expect(treeView.find('.selected').length).toBe 1
Expand Down Expand Up @@ -574,7 +569,7 @@ describe "TreeView", ->
it "opens the file in the editor and focuses it", ->
treeView.root.find('.file:contains(tree-view.js)').click()
treeView.root.trigger 'tree-view:open-selected-entry'
expect(rootView.getActiveView().getPath()).toBe fsUtils.resolveOnLoadPath('fixtures/tree-view/tree-view.js')
expect(rootView.getActiveView().getPath()).toBe project.resolve('tree-view.js')
expect(rootView.getActiveView().isFocused).toBeTruthy()

describe "when a directory is selected", ->
Expand All @@ -599,14 +594,14 @@ describe "TreeView", ->
beforeEach ->
atom.deactivatePackage('tree-view')

rootDirPath = path.join(fsUtils.absolute("/tmp"), "atom-tests")
fsUtils.remove(rootDirPath) if fsUtils.exists(rootDirPath)
rootDirPath = path.join(fs.absolute("/tmp"), "atom-tests")
fs.remove(rootDirPath) if fs.exists(rootDirPath)

dirPath = path.join(rootDirPath, "test-dir")
filePath = path.join(dirPath, "test-file.txt")
fsUtils.makeTree(rootDirPath)
fsUtils.makeTree(dirPath)
fsUtils.writeSync(filePath, "doesn't matter")
fs.makeTree(rootDirPath)
fs.makeTree(dirPath)
fs.writeSync(filePath, "doesn't matter")

project.setPath(rootDirPath)

Expand All @@ -618,7 +613,7 @@ describe "TreeView", ->
fileView = treeView.find('.file:contains(test-file.txt)').view()

afterEach ->
fsUtils.remove(rootDirPath) if fsUtils.exists(rootDirPath)
fs.remove(rootDirPath) if fs.exists(rootDirPath)

describe "tree-view:add", ->
addDialog = null
Expand Down Expand Up @@ -652,8 +647,8 @@ describe "TreeView", ->
newPath = path.join(dirPath, "new-test-file.txt")
addDialog.miniEditor.insertText(path.basename(newPath))
addDialog.trigger 'core:confirm'
expect(fsUtils.exists(newPath)).toBeTruthy()
expect(fsUtils.isFileSync(newPath)).toBeTruthy()
expect(fs.exists(newPath)).toBeTruthy()
expect(fs.isFileSync(newPath)).toBeTruthy()
expect(addDialog.parent()).not.toExist()
expect(rootView.getActiveView().getPath()).toBe newPath

Expand All @@ -666,7 +661,7 @@ describe "TreeView", ->
describe "when a file already exists at that location", ->
it "shows an error message and does not close the dialog", ->
newPath = path.join(dirPath, "new-test-file.txt")
fsUtils.writeSync(newPath, '')
fs.writeSync(newPath, '')
addDialog.miniEditor.insertText(path.basename(newPath))
addDialog.trigger 'core:confirm'

Expand All @@ -682,8 +677,8 @@ describe "TreeView", ->
newPath = path.join(dirPath, "new/dir")
addDialog.miniEditor.insertText("new/dir/")
addDialog.trigger 'core:confirm'
expect(fsUtils.exists(newPath)).toBeTruthy()
expect(fsUtils.isDirectorySync(newPath)).toBeTruthy()
expect(fs.exists(newPath)).toBeTruthy()
expect(fs.isDirectorySync(newPath)).toBeTruthy()
expect(addDialog.parent()).not.toExist()
expect(rootView.getActiveView().getPath()).not.toBe newPath
expect(treeView.find(".tree-view")).toMatchSelector(':focus')
Expand All @@ -695,8 +690,8 @@ describe "TreeView", ->
newPath = path.join(dirPath, "new2/")
addDialog.miniEditor.insertText("new2/")
addDialog.trigger 'core:confirm'
expect(fsUtils.exists(newPath)).toBeTruthy()
expect(fsUtils.isDirectorySync(newPath)).toBeTruthy()
expect(fs.exists(newPath)).toBeTruthy()
expect(fs.isDirectorySync(newPath)).toBeTruthy()
expect(addDialog.parent()).not.toExist()
expect(rootView.getActiveView().getPath()).not.toBe newPath
expect(treeView.find(".tree-view")).toMatchSelector(':focus')
Expand All @@ -706,7 +701,7 @@ describe "TreeView", ->
describe "when a file or directory already exists at the given path", ->
it "shows an error message and does not close the dialog", ->
newPath = path.join(dirPath, "new-dir")
fsUtils.makeTree(newPath)
fs.makeTree(newPath)
addDialog.miniEditor.insertText("new-dir/")
addDialog.trigger 'core:confirm'

Expand Down Expand Up @@ -792,8 +787,8 @@ describe "TreeView", ->

moveDialog.trigger 'core:confirm'

expect(fsUtils.exists(newPath)).toBeTruthy()
expect(fsUtils.exists(filePath)).toBeFalsy()
expect(fs.exists(newPath)).toBeTruthy()
expect(fs.exists(filePath)).toBeFalsy()
expect(moveDialog.parent()).not.toExist()

waitsFor "tree view to update", ->
Expand All @@ -815,13 +810,13 @@ describe "TreeView", ->
treeView.root.find('> .entries > .directory:contains(new)').length > 0

runs ->
expect(fsUtils.exists(newPath)).toBeTruthy()
expect(fsUtils.exists(filePath)).toBeFalsy()
expect(fs.exists(newPath)).toBeTruthy()
expect(fs.exists(filePath)).toBeFalsy()

describe "when a file or directory already exists at the target path", ->
it "shows an error message and does not close the dialog", ->
runs ->
fsUtils.writeSync(path.join(rootDirPath, 'target.txt'), '')
fs.writeSync(path.join(rootDirPath, 'target.txt'), '')
newPath = path.join(rootDirPath, 'target.txt')
moveDialog.miniEditor.setText(newPath)

Expand Down Expand Up @@ -851,7 +846,7 @@ describe "TreeView", ->

beforeEach ->
dotFilePath = path.join(dirPath, ".dotfile")
fsUtils.writeSync(dotFilePath, "dot")
fs.writeSync(dotFilePath, "dot")
dirView.collapse()
dirView.expand()
dotFileView = treeView.find('.file:contains(.dotfile)').view()
Expand Down Expand Up @@ -881,30 +876,30 @@ describe "TreeView", ->
temporaryFilePath = null

beforeEach ->
temporaryFilePath = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), 'temporary')
if fsUtils.exists(temporaryFilePath)
fsUtils.remove(temporaryFilePath)
temporaryFilePath = path.join(project.getPath(), 'temporary')
if fs.exists(temporaryFilePath)
fs.remove(temporaryFilePath)
waits(20)

afterEach ->
fsUtils.remove(temporaryFilePath) if fsUtils.exists(temporaryFilePath)
fs.remove(temporaryFilePath) if fs.exists(temporaryFilePath)

describe "when a file is added or removed in an expanded directory", ->
it "updates the directory view to display the directory's new contents", ->
entriesCountBefore = null

runs ->
expect(fsUtils.exists(temporaryFilePath)).toBeFalsy()
expect(fs.exists(temporaryFilePath)).toBeFalsy()
entriesCountBefore = treeView.root.entries.find('.entry').length
fsUtils.writeSync temporaryFilePath, 'hi'
fs.writeSync temporaryFilePath, 'hi'

waitsFor "directory view contens to refresh", ->
treeView.root.entries.find('.entry').length == entriesCountBefore + 1

runs ->
expect(treeView.root.entries.find('.entry').length).toBe entriesCountBefore + 1
expect(treeView.root.entries.find('.file:contains(temporary)')).toExist()
fsUtils.remove(temporaryFilePath)
fs.remove(temporaryFilePath)

waitsFor "directory view contens to refresh", ->
treeView.root.entries.find('.entry').length == entriesCountBefore
Expand All @@ -913,12 +908,12 @@ describe "TreeView", ->
[ignoreFile] = []

beforeEach ->
ignoreFile = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), '.gitignore')
fsUtils.writeSync(ignoreFile, 'tree-view.js')
ignoreFile = path.join(project.getPath(), '.gitignore')
fs.writeSync(ignoreFile, 'tree-view.js')
config.set "core.hideGitIgnoredFiles", false

afterEach ->
fsUtils.remove(ignoreFile) if fsUtils.exists(ignoreFile)
fs.remove(ignoreFile) if fs.exists(ignoreFile)

it "hides git-ignored files if the option is set, but otherwise shows them", ->
expect(treeView.find('.file:contains(tree-view.js)').length).toBe 1
Expand All @@ -936,26 +931,26 @@ describe "TreeView", ->

beforeEach ->
config.set "core.hideGitIgnoredFiles", false
ignoreFile = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), '.gitignore')
fsUtils.writeSync(ignoreFile, 'tree-view.js')
ignoreFile = path.join(project.getPath(), '.gitignore')
fs.writeSync(ignoreFile, 'tree-view.js')
project.getRepo().getPathStatus(ignoreFile)

newFile = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view/dir2'), 'new2')
fsUtils.writeSync(newFile, '')
newFile = path.join(project.resolve('dir2'), 'new2')
fs.writeSync(newFile, '')
project.getRepo().getPathStatus(newFile)

modifiedFile = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view/dir1'), 'file1')
originalFileContent = fsUtils.read(modifiedFile)
fsUtils.writeSync modifiedFile, 'ch ch changes'
modifiedFile = path.join(project.resolve('dir1'), 'file1')
originalFileContent = fs.read(modifiedFile)
fs.writeSync modifiedFile, 'ch ch changes'
project.getRepo().getPathStatus(modifiedFile)

treeView.updateRoot()
treeView.root.entries.find('.directory:contains(dir2)').view().expand()

afterEach ->
fsUtils.remove(ignoreFile) if fsUtils.exists(ignoreFile)
fsUtils.remove(newFile) if fsUtils.exists(newFile)
fsUtils.writeSync modifiedFile, originalFileContent
fs.remove(ignoreFile) if fs.exists(ignoreFile)
fs.remove(newFile) if fs.exists(newFile)
fs.writeSync modifiedFile, originalFileContent

describe "when a file is modified", ->
it "adds a custom style", ->
Expand Down