From 49ed2cddbcd1793aef2c1d0cb28c7c5cd2edc8b7 Mon Sep 17 00:00:00 2001 From: Wliu <50Wliu@users.noreply.github.com> Date: Wed, 15 Nov 2017 19:48:26 +0100 Subject: [PATCH 1/3] Add commands to non-active text editors --- lib/tree-view-package.js | 4 +-- lib/tree-view.coffee | 21 ++++++++++++--- menus/tree-view.cson | 12 ++++----- spec/tree-view-package-spec.coffee | 41 ------------------------------ 4 files changed, 26 insertions(+), 52 deletions(-) diff --git a/lib/tree-view-package.js b/lib/tree-view-package.js index 8b19ff03..3795af1f 100644 --- a/lib/tree-view-package.js +++ b/lib/tree-view-package.js @@ -16,8 +16,8 @@ class TreeViewPackage { 'tree-view:add-folder': () => this.getTreeViewInstance().add(false), 'tree-view:duplicate': () => this.getTreeViewInstance().copySelectedEntry(), 'tree-view:remove': () => this.getTreeViewInstance().removeSelectedEntries(), - 'tree-view:rename': () => this.getTreeViewInstance().moveSelectedEntry(), - 'tree-view:show-current-file-in-file-manager': () => this.getTreeViewInstance().showCurrentFileInFileManager() + 'tree-view:rename': (event) => this.getTreeViewInstance().moveSelectedEntry(event), + 'tree-view:show-current-file-in-file-manager': (event) => this.getTreeViewInstance().showSelectedEntryInFileManager(event) })) const treeView = this.getTreeViewInstance() diff --git a/lib/tree-view.coffee b/lib/tree-view.coffee index d7ee2356..bfb9cf11 100644 --- a/lib/tree-view.coffee +++ b/lib/tree-view.coffee @@ -225,7 +225,7 @@ class TreeView 'tree-view:open-selected-entry-left': => @openSelectedEntryLeft() 'tree-view:open-selected-entry-up': => @openSelectedEntryUp() 'tree-view:open-selected-entry-down': => @openSelectedEntryDown() - 'tree-view:move': => @moveSelectedEntry() + 'tree-view:move': (event) => @moveSelectedEntry(event) 'tree-view:copy': => @copySelectedEntries() 'tree-view:cut': => @cutSelectedEntries() 'tree-view:paste': => @pasteEntries() @@ -551,13 +551,14 @@ class TreeView if pane and selectedEntry.classList.contains('file') atom.workspace.openURIInPane selectedEntry.getPath(), pane - moveSelectedEntry: -> + moveSelectedEntry: (event) -> if @hasFocus() entry = @selectedEntry() return if not entry? or entry in @roots oldPath = entry.getPath() else - oldPath = @getActivePath() + oldPath = event.target.closest('.tab').querySelector('.title').getAttribute('data-path') + oldPath ?= @getActivePath() if oldPath dialog = new MoveDialog oldPath, @@ -594,6 +595,20 @@ class TreeView else return 'File Manager' + showSelectedEntryInFileManager: (event) -> + if @hasFocus() + entry = @selectedEntry() + return unless entry? + entryPath = entry.getPath() + else + entryPath = event.target.closest('.tab').querySelector('.title').getAttribute('data-path') + entryPath ?= @getActivePath() + return unless entryPath? + + isFile = fs.isFileSync(entryPath) + {command, args, label} = @fileManagerCommandForPath(entryPath, isFile) + @openInFileManager(command, args, label, isFile) + openSelectedEntryInNewWindow: -> if pathToOpen = @selectedEntry()?.getPath() atom.open({pathsToOpen: [pathToOpen], newWindow: true}) diff --git a/menus/tree-view.cson b/menus/tree-view.cson index f108645a..b4758060 100644 --- a/menus/tree-view.cson +++ b/menus/tree-view.cson @@ -95,21 +95,21 @@ {'label': 'Reveal in Tree View', 'command': 'tree-view:reveal-active-file'} ] - 'atom-pane[data-active-item-path] .tab.active': [ + 'atom-pane[data-active-item-path] .tab': [ {'label': 'Rename', 'command': 'tree-view:rename'} {'label': 'Reveal in Tree View', 'command': 'tree-view:reveal-active-file'} ] - '.platform-darwin atom-pane[data-active-item-path] .tab.active': [ - {'label': 'Reveal In Finder', 'command': 'tree-view:show-current-file-in-file-manager'} + '.platform-darwin atom-pane[data-active-item-path] .tab': [ + {'label': 'Show In Finder', 'command': 'tree-view:show-current-file-in-file-manager'} ] - '.platform-win32 atom-pane[data-active-item-path] .tab.active': [ + '.platform-win32 atom-pane[data-active-item-path] .tab': [ {'label': 'Show In Explorer', 'command': 'tree-view:show-current-file-in-file-manager'} ] - '.platform-linux atom-pane[data-active-item-path] .tab.active': [ - {'label': 'Show in File Manager', 'command': 'tree-view:show-current-file-in-file-manager'} + '.platform-linux atom-pane[data-active-item-path] .tab': [ + {'label': 'Show In File Manager', 'command': 'tree-view:show-current-file-in-file-manager'} ] '.platform-darwin atom-text-editor:not([mini])': [ diff --git a/spec/tree-view-package-spec.coffee b/spec/tree-view-package-spec.coffee index 8719dde6..7c7d610f 100644 --- a/spec/tree-view-package-spec.coffee +++ b/spec/tree-view-package-spec.coffee @@ -3865,47 +3865,6 @@ describe "TreeView", -> expect(atom.notifications.getNotifications().length).toBe(1) expect(atom.notifications.getNotifications()[0].getMessage()).toContain('Unable to show') - describe "showCurrentFileInFileManager()", -> - beforeEach -> - spyOn(shell, 'showItemInFolder').andReturn(false) - - it "does nothing when no file is opened", -> - expect(atom.workspace.getCenter().getPaneItems().length).toBe(0) - - treeView.showCurrentFileInFileManager() - expect(shell.showItemInFolder).not.toHaveBeenCalled() - - it "does nothing when only an untitled tab is opened", -> - waitsForPromise -> - atom.workspace.open() - - runs -> - workspaceElement.focus() - treeView.showCurrentFileInFileManager() - expect(shell.showItemInFolder).not.toHaveBeenCalled() - - it "shows the current file in the OS's file manager", -> - filePath = path.join(os.tmpdir(), 'non-project-file.txt') - fs.writeFileSync(filePath, 'test') - waitsForPromise -> - atom.workspace.open(filePath) - - runs -> - treeView.showCurrentFileInFileManager() - expect(shell.showItemInFolder).toHaveBeenCalled() - - it "shows a notification if showing the file fails", -> - filePath = path.join(os.tmpdir(), 'non-project-file.txt') - fs.writeFileSync(filePath, 'test') - spyOn(fs, 'existsSync').andReturn(false) - waitsForPromise -> - atom.workspace.open(filePath) - - runs -> - treeView.showCurrentFileInFileManager() - expect(atom.notifications.getNotifications().length).toBe(1) - expect(atom.notifications.getNotifications()[0].getMessage()).toContain('Unable to show') - describe "when reloading a directory with deletions and additions", -> it "does not throw an error (regression)", -> projectPath = temp.mkdirSync('atom-project') From 8108c763b6f15b707ca11d71946dcadcc5708e08 Mon Sep 17 00:00:00 2001 From: Wliu <50Wliu@users.noreply.github.com> Date: Wed, 15 Nov 2017 21:35:22 +0100 Subject: [PATCH 2/3] Fix specs --- spec/tree-view-package-spec.coffee | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/spec/tree-view-package-spec.coffee b/spec/tree-view-package-spec.coffee index 7c7d610f..a93aec1f 100644 --- a/spec/tree-view-package-spec.coffee +++ b/spec/tree-view-package-spec.coffee @@ -2353,11 +2353,13 @@ describe "TreeView", -> expect(callback).not.toHaveBeenCalled() describe "tree-view:move", -> + beforeEach -> + jasmine.attachToDOM(workspaceElement) + describe "when a file is selected", -> [moveDialog, callback] = [] beforeEach -> - jasmine.attachToDOM(workspaceElement) callback = jasmine.createSpy("onEntryMoved") treeView.onEntryMoved(callback) @@ -2518,8 +2520,6 @@ describe "TreeView", -> moveDialog = null beforeEach -> - jasmine.attachToDOM(workspaceElement) - waitForWorkspaceOpenEvent -> atom.workspace.open(filePath) @@ -3848,7 +3848,26 @@ describe "TreeView", -> describe "showSelectedEntryInFileManager()", -> beforeEach -> - spyOn(shell, 'showItemInFolder').andReturn(false) + atom.notifications.clear() + jasmine.attachToDOM(workspaceElement) + + it "displays the standard error output when the process fails", -> + {BufferedProcess} = require 'atom' + spyOn(BufferedProcess.prototype, 'spawn').andCallFake -> + EventEmitter = require 'events' + fakeProcess = new EventEmitter() + fakeProcess.send = -> + fakeProcess.kill = -> + fakeProcess.stdout = new EventEmitter() + fakeProcess.stdout.setEncoding = -> + fakeProcess.stderr = new EventEmitter() + fakeProcess.stderr.setEncoding = -> + @process = fakeProcess + process.nextTick -> + fakeProcess.stderr.emit('data', 'bad process') + fakeProcess.stderr.emit('close') + fakeProcess.stdout.emit('close') + fakeProcess.emit('exit') it "does nothing if no entry is selected", -> treeView.deselect() From 55168b6261977789bee03317c4472f8b1b32fea1 Mon Sep 17 00:00:00 2001 From: Wliu <50Wliu@users.noreply.github.com> Date: Fri, 17 Nov 2017 20:23:20 +0100 Subject: [PATCH 3/3] :art: --- 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 bfb9cf11..cae638a4 100644 --- a/lib/tree-view.coffee +++ b/lib/tree-view.coffee @@ -225,7 +225,7 @@ class TreeView 'tree-view:open-selected-entry-left': => @openSelectedEntryLeft() 'tree-view:open-selected-entry-up': => @openSelectedEntryUp() 'tree-view:open-selected-entry-down': => @openSelectedEntryDown() - 'tree-view:move': (event) => @moveSelectedEntry(event) + 'tree-view:move': => @moveSelectedEntry() 'tree-view:copy': => @copySelectedEntries() 'tree-view:cut': => @cutSelectedEntries() 'tree-view:paste': => @pasteEntries()