在 Sublime Text 中添加自定义菜单 [英] Adding Custom Menus in Sublime Text

查看:50
本文介绍了在 Sublime Text 中添加自定义菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 SublimeText 2 中添加自定义菜单项.

How to add a custom Menu item in SublimeText 2 .

有什么想法吗??
我看到有一个 Main.sublime-menu 文件,但不知道如何编辑它.

Any Ideas ??
I see there is a Main.sublime-menu file but dont know how to edit it.

谢谢!

推荐答案

*.sublime-menu 文件只是 JSON.您可以在您的用户目录中创建一个 Main.sublime-menu,它将与其他菜单条目合并.查看第三方插件的 Main.sublime-menu 文件可能会有所帮助.这些通常要短得多,因此可能更容易理解您需要在每个条目中定义的一些内容.

The *.sublime-menu file is simply JSON. You can create a Main.sublime-menu in your user directory and it will be merged with other menu entries. It may be beneficial to look through the Main.sublime-menu files third party plugins have. These are generally much shorter, so may be easier to understand some of the things you need to define in each entry.

编辑

您可以使用以下插件作为插件打开带有任意文件的记事本.

You can use the following as a plugin to open notepad with an arbitrary file.

import sublime
import sublime_plugin
import subprocess
import threading
class OpenNotepadCommand(sublime_plugin.TextCommand):
    def run(self, edit, filename=None):
        th = NotepadThread(filename)
        th.start()

class NotepadThread(threading.Thread):
    def __init__(self, filename=None):
        self.filename = filename
        threading.Thread.__init__(self)

    def run(self):
        if self.filename is not None:
            subprocess.call("notepad.exe %s" % self.filename)
        else:
            subprocess.call("notepad.exe")

当您创建菜单项时,对命令和参数使用如下所示的内容.

When you are creating a menu item use something like the following for the command and arguments.

{
    "command": "open_notepad",
    "args": { "filename": "<the absolute path here>"}
}

这篇关于在 Sublime Text 中添加自定义菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆