【发布时间】:2013-10-31 17:45:30
【问题描述】:
我为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)
【问题讨论】:
标签: python plugins sublimetext2 sublimetext3