import sublime
import sublime_plugin
class ToggleReadOnlyCommand(sublime_plugin.ApplicationCommand):
def run(self):
_toggle_read_only(sublime.active_window().active_view())
def is_checked(self):
view = sublime.active_window().active_view()
if view and view.is_read_only():
return True
return False
def is_enabled(self):
return sublime.active_window().active_view() is not None
class ReadOnlyEventListener(sublime_plugin.EventListener):
def on_window_command(self, window, command, args):
if command in ("prompt_open_file", "prompt_open"):
readonly = False if args is None else args.get("readonly", False)
window.settings().set("_open_read_only",readonly)
def on_load(self, view):
if view.window() is not None:
readonly = view.window().settings().get("_open_read_only", False)
view.window().settings().erase("_open_read_only")
if readonly:
_toggle_read_only(view)
I have a plugin which can be used normally in version 3 but can not be used in version 4,because it also can be rectified when I open in read-only mode.