我为sublime text 3
. 并想获取当前打开的文件路径...
absolute1 = self.window.view.file_name()
...在self
哪里sublime_plugin.WindowCommand
但失败:
AttributeError: 'Window' object has no attribute 'view'
插件完整代码:
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())
如果self
是的话,sublime_plugin.TextCommand
我可以毫无问题地获得当前文件路径:
fileName = self.view.file_name()
...但self
一定是sublime_plugin.WindowCommand
因为我想使用方法open_file
:
self.window.open_file(absolute2)