我开发插件sublime text 3
。并希望得到当前打开的文件路径...从sublime_plugin.WindowCommand获取当前文件名
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
我可以得到curren没有问题牛逼文件路径:
fileName = self.view.file_name()
...但self
必须sublime_plugin.WindowCommand
,因为我想使用方法open_file
:
self.window.open_file(absolute2)
我尝试,但失败:'absolute1 = self.active_window()view.file_name() Attribu teError:'OpenrelCommand'对象没有属性'active_window'' –
Woops抱歉,我的意思是'self.active_view()' – skuroda
对不起。 'absolute1 = self.active_view().file_name() AttributeError:'OpenrelCommand'对象没有属性'active_view'' –