Add another "toggle" function?


#1

Hi guys,

I am writing my first package for atom and it is working well.
Now I want to implement another function in the same package which does something different.
I tried to add the

          "label": "mypackagename",
          "submenu": [
            {
              "label": "Toggle align",
              "command": "mypackagename:toggle"
            },
            {
              "label": "Toggle module 2 instance",
              "command": "mypackagename:module_2_instance"
            }
          ]

But when I click in the line in the menu, nothing happen… As if the “module_2_instance” was empty.
How can I add many functions like this ?
I didn’t find anything like this in the Atom Flight Manual and existing packages are too complicated to me.

I am using Javascript to write the package.

Thank you.


#2

In order for a menu item or keybinding to do anything, you have to first register a command in the CommandRegistry. The Flight Manual covers how to do this in the chapter on the init.coffee file, since that’s the place where most users get their first taste of defining new commands. There’s a whole section for CommandRegistry methods in the API docs and you can look at the definition for the mypackagename:toggle command inside your package.


#3

Thank you, and also this discussion helped me : Only 1 of 3 registered commands triggers activation
Now it’s working very well.
I’m loving more and more Atom !