Marijke Luttekes
Marijke Luttekes

Reputation: 1293

Sublime Text 3, sidebar items are not showing

I'm making a simple plugin for Sublime Text 3, which should create a .gitignore file in one or more folders. So far the package contains two commands, which can be called from the ST3 console using window.command(...).

I want to be able to right-click a folder in the sidebar and select a command from the menu that pops up. I've added Side Bar.sublime-menu with items to call the methods, but the menu items are not showing when right-clicking a folder or file in the sidebar.

From the info below, does someone know what's missing here?


Plugin tree:

~/Library/Application Support/Sublime Text 3/Packages/GitIgnoreFolderContents
├── Side\ Bar.sublime-menu
├── git_ignore_folder_contents.py
├── git_ignore_folder_contents.sublime-settings
├── libs
│   ├── settings.py
│   └── util.py
└── notes_use_later.txt

Side Bar.sublime-menu:

[
    {
        "caption": "-"
    },
    {
        "caption": "Git Ignore Folder Contents",
        "id": "git_ignore_folder_contents",
        "children:": [
            {
                "caption": "Create .gitignore",
                "command": "create_folder_gitignore",
                "args": {
                    "paths": []
                }
            },
            {
                "caption": "Create .gitkeep",
                "command": "create_folder_gitkeep",
                "args": {
                    "paths": []
                }
            }
        ]
    }
]

git_ignore_folder_contents.py:

import sublime
import sublime_plugin

from .libs.util import print_debug


class BaseCreateFolderIgnoreFileCommand(sublime_plugin.WindowCommand):
    def run(self, paths=[]):
        print_debug('[GIFC] running {}'.format(self.__class__.__name__))
        print_debug('[GIFC] paths:', paths)
        if not paths:
            print_debug('[GIFC] paths is empty, halting function')
            return

        for path in paths:
            # ToDo: create files here
            pass

    def is_enabled(self, paths=[]):
        # ToDo: disable when one of paths is not a folder
        return True


class CreateFolderGitignoreCommand(BaseCreateFolderIgnoreFileCommand):
    filename = '.gitignore'
    contents = '*\n!.gitignore'


class CreateFolderGitkeepCommand(BaseCreateFolderIgnoreFileCommand):
    filename = '.gitkeep'
    contents = ''

Environment:

Upvotes: 1

Views: 2290

Answers (1)

OdatNurd
OdatNurd

Reputation: 22791

It looks like the reason this isn't working for you is that your sublime-menu file is subtly broken; the children key has a stray : character in it.

In particular, when I create a package with the files you've provided here (same build of Sublime, but on Windows and not MacOS), the top level menu item appears in the menu, but it doesn't have any children as one might expect. Selecting the Git Ignore Folder Contents command generates an error in the console. I'm guessing that's because it has no direct command to execute since it's not supposed to be selectable.

Fixing this line to not have a colon inside of the key should fix your issue; or at least it does for me:

"children:": [

Upvotes: 1

Related Questions