Avi*_*Avi 14 sublimetext sublimetext2
如何在SublimeText 2中添加自定义菜单项.
有任何想法吗 ??
我看到有一个Main.sublime菜单文件,但不知道如何编辑它.
谢谢!
sku*_*oda 15
*.sublime-menu文件只是JSON.您可以在用户目录中创建Main.sublime菜单,它将与其他菜单项合并.查看第三方插件所具有的Main.sublime菜单文件可能是有益的.这些通常要短得多,因此可能更容易理解您需要在每个条目中定义的一些内容.
编辑
您可以使用以下内容作为插件来打开带有任意文件的记事本.
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")
Run Code Online (Sandbox Code Playgroud)
在创建菜单项时,请使用以下命令和参数.
{
"command": "open_notepad",
"args": { "filename": "<the absolute path here>"}
}
Run Code Online (Sandbox Code Playgroud)
小智 12
如果您想要的只是运行命令,更容易的选项.在Packages/User目录中创建一个Context.sublime-menu文件,并添加以下内容:
[
{ "caption": "<Your caption here>", "command": "exec", "args": {"cmd": ["<your cmd name>", "<arg1>", "<arg2>", <...>]} }
]
Run Code Online (Sandbox Code Playgroud)
例子:将菜单项添加到刚刚运行dir的上下文菜单中:
[
{ "caption": "List files in current dir", "command": "exec", "args": {"cmd": ["dir"]} }
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8485 次 |
| 最近记录: |