From 061fdba44cbea51dd8de44aa20796ffdcfb4f28d Mon Sep 17 00:00:00 2001 From: glangford Date: Wed, 28 Oct 2015 19:16:29 -0400 Subject: [PATCH 1/4] Select files after paste operation --- lib/tree-view.coffee | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/tree-view.coffee b/lib/tree-view.coffee index 1fedee8a..e4bc9b2e 100644 --- a/lib/tree-view.coffee +++ b/lib/tree-view.coffee @@ -562,10 +562,12 @@ class TreeView extends View cutPaths = if LocalStorage['tree-view:cutPath'] then JSON.parse(LocalStorage['tree-view:cutPath']) else null copiedPaths = if LocalStorage['tree-view:copyPath'] then JSON.parse(LocalStorage['tree-view:copyPath']) else null initialPaths = copiedPaths or cutPaths + newPaths = [] - catchAndShowFileErrors = (operation) -> + catchAndShowFileErrors = (operation, newPath) -> try operation() + newPaths.push(newPath) catch error atom.notifications.addWarning("Unable to paste paths: #{initialPaths}", detail: error.message) @@ -590,15 +592,39 @@ class TreeView extends View if fs.isDirectorySync(initialPath) # use fs.copy to copy directories since read/write will fail for directories - catchAndShowFileErrors -> fs.copySync(initialPath, newPath) + catchAndShowFileErrors( (-> fs.copySync(initialPath, newPath)), newPath) else # read the old file and write a new one at target location - catchAndShowFileErrors -> fs.writeFileSync(newPath, fs.readFileSync(initialPath)) + catchAndShowFileErrors( (-> fs.writeFileSync(newPath, fs.readFileSync(initialPath))), newPath) else if cutPaths # Only move the target if the cut target doesn't exists and if the newPath # is not within the initial path unless fs.existsSync(newPath) or !!newPath.match(new RegExp("^#{initialPath}")) - catchAndShowFileErrors -> fs.moveSync(initialPath, newPath) + catchAndShowFileErrors( (-> fs.moveSync(initialPath, newPath)), newPath) + if repo = repoForPath(initialPath) + repo.getPathStatus(initialPath) # for side effect; cut may result in status change of parent dir + if newPaths.length > 0 + @deselect(@getSelectedEntries) + @selectOnCreate(newPaths) + + # For new paths that have been created, select each entry if it exists or + # set up a subscription to select it when it is added. + selectOnCreate: (newPaths) -> + subscribedDirectories = [] + for p in newPaths + entry = @entryForPath(p) + if entry.isPathEqual(p) + entry.classList.add('selected') + continue + if entry instanceof DirectoryView + continue if subscribedDirectories.indexOf(entry.directory.name) isnt -1 + subscribedDirectories.push(entry.directory.name) + subscription = entry.directory.onDidAddEntries (addedEntries) => + for e in addedEntries + @entryForPath(e.path)?.classList.add('selected') if newPaths.indexOf(e.path) isnt -1 + if repo = repoForPath(e.path) + repo.getPathStatus(e.path) + subscription.dispose() add: (isCreatingFile) -> selectedEntry = @selectedEntry() ? @roots[0] From 686a00314c699c8035fdaf071d77917688e78dfe Mon Sep 17 00:00:00 2001 From: glangford Date: Thu, 29 Oct 2015 16:00:53 -0400 Subject: [PATCH 2/4] Update specs for file selection after paste --- spec/tree-view-spec.coffee | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/tree-view-spec.coffee b/spec/tree-view-spec.coffee index a1fb81db..3fb21ca6 100644 --- a/spec/tree-view-spec.coffee +++ b/spec/tree-view-spec.coffee @@ -1270,7 +1270,7 @@ describe "TreeView", -> describe "when a file has been copied", -> describe "when a file is selected", -> - it "creates a copy of the original file in the selected file's parent directory", -> + it "creates a copy of the original file in the selected file's parent directory and selects it", -> LocalStorage['tree-view:copyPath'] = JSON.stringify([filePath]) fileView2.click() @@ -1279,6 +1279,16 @@ describe "TreeView", -> expect(fs.existsSync(path.join(dirPath2, path.basename(filePath)))).toBeTruthy() expect(fs.existsSync(filePath)).toBeTruthy() + waitsFor (done) -> + disposable = dirView2[0].directory.onDidAddEntries -> + disposable.dispose() + done() + + runs -> + newFileView = dirView2.find('.file:contains(test-file.txt)') + expect(newFileView).not.toBeNull() + expect(newFileView).toHaveClass('selected') + describe 'when target already exists', -> it 'appends a number to the destination name', -> LocalStorage['tree-view:copyPath'] = JSON.stringify([filePath]) From 784341afb7b7770172eb19bfcf1061fc86ec5ab1 Mon Sep 17 00:00:00 2001 From: glangford Date: Fri, 30 Oct 2015 07:55:03 -0400 Subject: [PATCH 3/4] Fix typo deselecting prior entries --- lib/tree-view.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tree-view.coffee b/lib/tree-view.coffee index e4bc9b2e..711b0f9f 100644 --- a/lib/tree-view.coffee +++ b/lib/tree-view.coffee @@ -604,7 +604,7 @@ class TreeView extends View if repo = repoForPath(initialPath) repo.getPathStatus(initialPath) # for side effect; cut may result in status change of parent dir if newPaths.length > 0 - @deselect(@getSelectedEntries) + @deselect(@getSelectedEntries()) @selectOnCreate(newPaths) # For new paths that have been created, select each entry if it exists or From b3c0c009b89926dbb213663d324a2ff5af95b852 Mon Sep 17 00:00:00 2001 From: glangford Date: Fri, 30 Oct 2015 08:25:47 -0400 Subject: [PATCH 4/4] Update specs; click selection not preserved after paste --- spec/tree-view-spec.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/tree-view-spec.coffee b/spec/tree-view-spec.coffee index 3fb21ca6..86d3fcc5 100644 --- a/spec/tree-view-spec.coffee +++ b/spec/tree-view-spec.coffee @@ -1295,6 +1295,7 @@ describe "TreeView", -> fileView.click() atom.commands.dispatch(treeView.element, "tree-view:paste") + fileView.click() atom.commands.dispatch(treeView.element, "tree-view:paste") fileArr = filePath.split(path.sep).pop().split('.') @@ -1320,6 +1321,7 @@ describe "TreeView", -> dirView.click() atom.commands.dispatch(treeView.element, "tree-view:paste") + dirView.click() atom.commands.dispatch(treeView.element, "tree-view:paste") fileArr = filePath.split(path.sep).pop().split('.')