Sublime Text 3,侧边栏项目未显示

时间:2018-04-01 15:55:42

标签: sublimetext3 sublimetext sublime-text-plugin

我为Sublime Text 3制作了一个简单的插件,它应该在一个或多个文件夹中创建一个.gitignore文件。到目前为止,程序包包含两个命令,可以使用window.command(...)从ST3控制台调用。

我希望能够右键单击侧栏中的文件夹,然后从弹出的菜单中选择一个命令。我已添加Side Bar.sublime-menu项以调用方法,但右键单击侧栏中的文件夹或文件时,菜单项未显示。

根据以下信息,有人知道这里缺少什么吗?

插件树:

~/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 = ''

环境:

  • 从开发人员频道为macOS构建3160。
  • package" SideBarEnhancements"安装(在其他包中,一些包含工作侧边栏菜单项)

1 个答案:

答案 0 :(得分:1)

看起来这不适合你的原因是你的sublime-menu文件被巧妙地破坏了; children键中包含一个迷路:字符。

特别是,当我创建一个包含你在这里提供的文件的包(相同版本的Sublime,但是在Windows而不是MacOS上)时,顶级菜单项会出现在菜单中,但它并没有#39 ;有任何孩子可能会有所期待。选择Git Ignore Folder Contents命令会在控制台中生成错误。我猜这是因为它没有直接执行command,因为它不应该是可选择的。

修复此行以使密钥内部没有冒号应解决您的问题;或者至少它对我有用:

"children:": [