通过Sublime API在侧栏中右键单击获取文件夹的路径

时间:2016-10-01 18:39:29

标签: sublimetext2 sublimetext3 sublimetext sublime-text-plugin

如何通过Sublime API右键单击侧栏中的文件夹路径?我可以通过sublime.view.file_name()获取文件路径,但不能获取文件夹。

1 个答案:

答案 0 :(得分:2)

简而言之,使用命令定义创建Side Bar.sublime-menu文件:

[
    { "caption": "Side Bar Test Dirs",  "command": "side_bar_test_dirs",  "args": {"dirs": []} },
    { "caption": "Side Bar Test Paths", "command": "side_bar_test_paths", "args": {"paths": []} },
    { "caption": "Side Bar test Files", "command": "side_bar_test_files", "args": {"files": []} },
]

然后是命令:

import sublime
import sublime_plugin

class SideBarTestDirsCommand(sublime_plugin.WindowCommand):
    def run(self, dirs):
        print(dirs)

class SideBarTestPathsCommand(sublime_plugin.WindowCommand):
    def run(self, paths):
        print(paths)

class SideBarTestFilesCommand(sublime_plugin.WindowCommand):
    def run(self, files):
        print(files)

Sublime Text Unofficial Documentaion中有更详细的文档。