Joshua Cheek
Joshua Cheek

Reputation: 31726

How do I add my configuration to Sublime Text 2's menu?

I've written a plugin for Sublime Text 2, which talks to a binary that I wrote. I expose the flags to the binary through as settings file, but I cannot figure out how to get the settings file placed into the menu bar.

Where I want the settings

Here is my best attempt so far.

Here are the docs on settings (not sure where the ones on menus are).

Upvotes: 5

Views: 1752

Answers (1)

angerson
angerson

Reputation: 7402

From what I can tell, in order to add your own items to a menu, its original declaration must have a pre-existing id value, which must then be included in any package-specific menu expansions. For example, consider the default definition for Preferences:

{
    "caption": "Preferences",
    "mnemonic": "n",
    "id": "preferences",
    "children": [ ... ]
},

Notably, the Settings – More object in Packages/Default/Main.sublime-menu does not have an id.

{
   "caption": "Settings – More",
   "children": [ ... ]
},

You can prove this requirement yourself by adding an id value to Settings – More in the default Main.sublime-menu and including that id in your package's Main.sublime-menu, similarly to how Preferences' id is referenced. Your custom menu will then show up under Settings – More.

Based upon the exclusion of an id for Settings – More, I would assume that the creators of Sublime Text 2 did not intend for third party packages to be able to edit the menu in question. Also, note that the in Settings – More is not a hyphen (-); that's not the cause of your problem, but I initially suspected that it might have been.

The standard practice for adding one's own package settings to Preferences appears to be inserting a new item into Preferences -> Package Settings, which can be accomplished with a Main.sublime-menu file like this:

[
  {
    "caption": "Preferences",
    "mnemonic": "n", // The mnemonics are for quick keyboard access
    "id": "preferences",
    "children": [
      {
        "caption": "Package Settings",
        "mnemonic": "P", // On windows, Alt+N (above) followed by Alt+P would open this menu
        "id": "package-settings",
        "children": [
          { 
            "caption": "Seeing Is Believing",
            "children": [
              {
                "command": "open_file",
                "args": {"file": "${packages}/Seeing Is Believing/Seeing Is Believing.sublime-settings"},
                "caption": "Settings – Default"
              }
            ]
          }
        ]
      }
    ]
  }
]

I would highly recommend referencing a menu-rich plugin's Main.sublime-menu to figure out what else you should include and how you should do it. For my research I examined both Sublime Text 2's Main.sublime-menu and AdvancedNewFile's.

Upvotes: 1

Related Questions