Max*_*mov 2 python plugins sublimetext2 sublimetext3
我开发插件sublime text 3
.并希望获得当前打开的文件路径...
absolute1 = self.window.view.file_name()
Run Code Online (Sandbox Code Playgroud)
...这里self
是sublime_plugin.WindowCommand
但失败了:
AttributeError: 'Window' object has no attribute 'view'
Run Code Online (Sandbox Code Playgroud)
完整的插件代码:
import sublime, sublime_plugin
import re, os, os.path
class OpenrelCommand(sublime_plugin.WindowCommand):
def run(self):
relative = sublime.get_clipboard()
absolute1 = self.window.view.file_name()
absolute2 = os.path.normpath(os.path.join(os.path.dirname(absolute1), relative))
self.window.open_file(absolute2)
def is_enabled(self):
return bool(sublime.get_clipboard().strip())
Run Code Online (Sandbox Code Playgroud)
如果self
是,sublime_plugin.TextCommand
我可以没有问题得到当前的文件路径:
fileName = self.view.file_name()
Run Code Online (Sandbox Code Playgroud)
...但self
必须是sublime_plugin.WindowCommand
因为我想使用方法open_file
:
self.window.open_file(absolute2)
Run Code Online (Sandbox Code Playgroud)
请查看API(http://www.sublimetext.com/docs/3/api_reference.html#sublime.Window).self
是一个窗口对象.所以你需要做的self.window.active_view()
就是获得视图.
对于Sublime Text 3,对我有用的命令是:
self.view.window().active_view().file_name()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2638 次 |
最近记录: |