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..cae638a4 100644 --- a/lib/tree-view.coffee +++ b/lib/tree-view.coffee @@ -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..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() @@ -3865,47 +3884,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')