Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Add commands to non-active text editors #1205

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions lib/tree-view-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 17 additions & 2 deletions lib/tree-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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})
Expand Down
12 changes: 6 additions & 6 deletions menus/tree-view.cson
Original file line number Diff line number Diff line change
Expand Up @@ -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])': [
Expand Down
68 changes: 23 additions & 45 deletions spec/tree-view-package-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -2518,8 +2520,6 @@ describe "TreeView", ->
moveDialog = null

beforeEach ->
jasmine.attachToDOM(workspaceElement)

waitForWorkspaceOpenEvent ->
atom.workspace.open(filePath)

Expand Down Expand Up @@ -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()
Expand All @@ -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')
Expand Down