I develop plugin for sublime text 3
. And want to get currently opened file path ...
absolute1 = self.window.view.file_name()
... where self
is sublime_plugin.WindowCommand
But fail:
AttributeError: 'Window' object has no attribute 'view'
Full code of plugin:
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())
If self
would be sublime_plugin.TextCommand
I could get current file path without a problem:
fileName = self.view.file_name()
... but self
must be sublime_plugin.WindowCommand
because I want to use method open_file
:
self.window.open_file(absolute2)