5

I see a lot of calls to this show_panel function with an args object like this:

{
    "keys": ["ctrl+shift+f"],
    "command": "show_panel",
    "args": {"panel": "find_in_files"}
}

I cannot find where the show_panel function is defined and am beginning to think that it is not exposed. Is it possible to define a new panel?

4

1 回答 1

6

是的。这是可能的。
在 Sublime Text 2 中,基本上你需要的是:

  1. 创建一个输出面板:window.get_output_panel("paneltest"),这会返回一个 <sublime.View object>
  2. 启用版本:<sublime.View object>.set_read_only(False)
  3. 打开缓冲区编辑器:<sublime.View object>.begin_edit(),这会返回一个 <sublime.Edit object>
  4. 写到你想要的视图:<sublime.View object>.insert(edit, pt.size(), "Writing...")
  5. 关闭缓冲区编辑器:<sublime.View object>.end_edit()
  6. 禁用版本:<sublime.View object>.set_read_only(True)
  7. 显示您的面板:window.run_command("show_panel", {"panel": "output.paneltest"})

要进行测试,请在 Sublime 的 Console View 上一一输入以上行:

pt = window.get_output_panel("paneltest")
pt.set_read_only(False)
edit = pt.begin_edit()
pt.insert(edit, pt.size(), "Writing...")
pt.end_edit(edit)
window.run_command("show_panel", {"panel": "output.paneltest"})

在 Sublime Text 3 中,不要执行步骤 3 和 5。

于 2014-02-07T09:49:05.310 回答