[SOLVED] How to clear the workspace where close-all-tabs does not work?


#1

Hello.

I have the following key-binding active:

'atom-text-editor':
  'ctrl-shift-f4': 'tabs:close-all-tabs'  # use 'f4' not 'F4'

If the tabs are spread over several panes, the above key-binding does not work. The tabs inside the active pane are all closed. Repeated triggering is required to close all panes too.

  1. What is the atom command for “close all tabs” when using this in Coffeescript?
  2. What command for testing if the workspace still contains tabs?

I appreciate your thoughts on this matter.
- Dan Padric

correction: Use ‘f4’ not ‘F4’


#2

Additional…

isActive is a way to see if a panel is active - right? For example atom.pane.isActive does not work. So how is this called?

Without call examples in the API documentation, I find it difficult to understand how the commands are structured for usage. I understand one should create an object variable, but not sure how.

Anyone has some helpful thoughts?


#3

You use atom.commands.dispatch().

isActive is a way to see if a panel is active - right? For example atom.pane.isActive does not work. So how is this called?

The globals like atom.workspace and atom.commands exist in all circumstances. Panes come and go. You might have one or two or five of them, so Atom has no way of knowing which one you’re referring to. If you want to find the active pane, you can use atom.workspace.getActivePane().


#4

@DamnedScholar :

Thank you for your efforts in giving me some hints.

Not wanting to sound unthankful, please allow me some thoughts:

  1. atom.commands.getActivePane() only references one active pane.

  2. Not sure how atom.commands.dispatch() will help to identify the coding calls that sits behind “close all tabs”. I would prefer getting the formal definitions from the open source code to reverse-engineer some concepts.

Regardless… please allow me to share the result.

### "keymap.cson" ###
'.platform-win32':
  'ctrl-shift-f4': 'custom:closeAllTabs'  # important! use 'f4' not 'F4'
### "init.coffee" ###
Custom = require "./customTools/tools.coffee"
custom = new Custom()

# ****************************************************
#  CLOSE ALL OPEN TABS .. REGARDLESS IF IN SEVERAL PANES
# ****************************************************
atom.commands.add 'atom-text-editor', 'custom:closeAllTabs', (e) ->
  e.abortKeyBinding() unless custom.closeAllTabs()
### "./customTools/tools.coffee" ###
module.exports =
class Custom

  # ****************************************************
  #  CLOSE ALL OPEN TABS .. REGARDLESS IF IN SEVERAL PANES
  # ****************************************************
  # Note: System requests automatically to save unsaved text editor. 
  closeAllTabs: () ->
    console.log 'Close all panes.'  # debug
    _panes = atom.workspace.getPanes()  # grab object representing all items in panes
    _pane.destroy() for _pane in _panes  # not all items can close; tree-view / dev-tools / ++ is kept open
    return true  # confirm to caller: no need to abort action

May this be helpful / useful to other n00bs.

- Dan Padric


[SOLVED] How to make a function call in "init.coffee"?
#5

You asked how to get the active pane.

Not sure how atom.commands.dispatch() will help to identify the coding calls that sits behind “close all tabs”.

It sounded like what you wanted was a way to tell Atom to close all tabs via CoffeeScript.

I would prefer getting the formal definitions from the open source code to reverse-engineer some concepts.

For that, you can just look at the code itself.


#6

Yes that is what I asked, but I was wrong in my request. If I followed that through, I would end up with what close-all-tabs does: only close the tabs in the active pane. Other panes are left untouched.

The result I wanted was to clear the work area. That means closing all the panes in the centre area. tree-view is also a pane but should be left untouched. The code I constructed does this.

Yes. Sorry for articulating this fact so badly.

YES!! Thank you. That is what I was looking for. Please educate me - which procedure / steps must I follow to sniff out these commands. Is there a registry somewhere to look this up when next time I need a command?

Regards.
- Dan Padric


#7

It’s conventional for commands to include the name of the package they come from, so you can find the package by looking at the command. In this case, tabs handles tabbing functionality, so I just went to that repo and looked around for where the command was defined.

For a core feature, you want to look at the register-default-commands.coffee file.