Can't toggle VCS ignore from anywhere


I use the keymap '.platform-darwin': 'alt-tab': 'tree-view:toggle-focus' to switch between the editor and the tree view, and that mapping works fine.

I tried to add a similar keymap '.platform-darwin': 'alt-i': 'tree-view:toggle-vcs-ignored-files' that would toggle ignored files from anywhere, but that didn’t work. The default binding ('.tree-view': 'i': 'tree-view:toggle-vcs-ignored-files') does work, so I’m confused why the new one wouldn’t.

Is there some reason that action can only happen if the context is the .tree-view? Or am I missing something more obvious?


Toggle treeview vcs and ignored names in context menu

Not that I know of, it’s just toggling the configuration. Have you tried using the Keybinding Resolver Cmd+. to determine what keys Atom thinks you’re pressing?


It seems to resolve correctly, but nothing gets toggled.


Are you saying that executing the command “Tree View: Toggle Vcs Ignored Files” via cmd/ctrl-shift-P does something but executing the command via the keybinding does not? If it doesn’t work via cmd/ctrl-shift-P, either, then maybe it’s not a keybinding issue.


I don’t see that command in the command palette. After looking at the tree-view source, it appears as though the toggle commands are being added to @element, whereas some of the other command are added to atom-workspace, so I suspect that is the issue.


I’m seeing the same behavior.

This doesn’t work, unless I already have focus on the tree-view. Also, I don’t see the “Tree View: Toggle Vcs Ignored Files” in my command palette.

  'cmd-i': 'tree-view:toggle-vcs-ignored-files'


Commands don’t naturally work from anywhere. Some commands expect to be executed within a certain context. If you try to execute those commands outside of that context, they just won’t fire or they’ll do nothing. It appears that the tree-view:toggle-vcs-ignored-files is one of those.


@leedohm Any idea why this doesn’t work then?

atom.commands.add 'atom-workspace', 'custom:toggle-vcs-ignored-files', ->
  workspaceElement = atom.views.getView atom.workspace
  atom.commands.dispatch workspaceElement,  'tree-view:show'
  atom.commands.dispatch workspaceElement, 'tree-view:toggle-vcs-ignored-files'

When i trigger than custom event, focus is changed to the tree-view, but toggle-vcs-ignored-files doesn’t work.


Because despite focusing the Tree View, you’re still issuing the toggle-vcs-ignored-files on the workspaceElement, not the Tree View.


Of course!

No idea if this is the “right” way to do it, but this works:

atom.commands.add 'atom-workspace', 'custom:toggle-vcs-ignored-files', ->
  treeView = atom.views.getView(document.querySelector('div.tree-view-resizer.tool-panel'))
  atom.commands.dispatch(treeView, 'tree-view:toggle-vcs-ignored-files');


for anyone coming here these worked :-).

in `keymap.cson

  'ctrl-alt-i': 'tree-view:toggle-vcs-ignored-files'

a context menu item…put it in

atom.contextMenu.add {
  '.tree-view': [{label: 'Hidden', command: 'tree-view:toggle-vcs-ignored-files'}]

The second obviously works in the tree-view context but as @leedohm mentioned the keybinding will only work if the tree-view has the focus/context and you can’t force it to work in any other like atom-workspace

@leedohm, how does one do multiple commands from one keybinding/menu item? I’d like the toggle the core hidden ignores at the same time as the vcs ignores.


There isn’t a built-in way to launch multiple commands from one keybinding. You can write some code to launch more than one command and then activate that with a keybinding though.


trying this

but @leedohm that example isn’t helping me. What is the syntax to execute existing commands instead of calling some api method like in all the examples?

this is not working

atom.commands.add '.tree-view', 'custom:toggle-treeview-hidden', ->

maybe ??? tree-view.toggle-vcs-ignored-files(), …no that doesn’t work


Because the example is executing JavaScript functions and that’s not what you’re trying to do. What you need is the atom.commands.dispatch() method. This will work:

atom.commands.add '.tree-view', 'custom:toggle-treeview-hidden', ->
  atom.commands.dispatch document.querySelector('.tree-view'), 'tree-view:toggle-vcs-ignored-files'
  atom.commands.dispatch document.querySelector('.tree-view'), 'tree-view:toggle-ignored-files'


Getting close

I think that worked but there is an issue with the command 'tree-view:toggle-ignored-files'. It’s not right because it won’t toggle those even if I do the single command version

I am unsure what might be correct because it and the vcs command are not visible from the palette.
I just found that one in some old atom package docs.

So what might be the correct command for toggling just the ignored files.


Bingo, given that the core settings is called ignored names I tried


and that worked!

It was toggling them opposite not together but adding a just names fixed that.