Sublime Forum

A plugin which can be used normally in ST3 but can not be used in ST4

#1
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.

0 Likes

#2

In what way is it “not compatible”?

0 Likes

#4

because it also can be rectified when I open in read-only mode.

0 Likes

#5

Please clarify in what way the plugin isn’t working how it did in ST3.

0 Likes

#6

Excuse me, I re-clarified my situation. ST3 is available. However, ST4 can not be used in a regular way,because the contents in the text in ST4 still can be rectified under the read-only mode.(in other words,I think that under read-only mode,all contents should not be rectified )

0 Likes

#7

What do you mean by rectify?

0 Likes

#8

I guess “rectified” == “editable”.

That said, the plugin does what it should on my ST4134.

Calling sublime.run_command("toggle_read_only") toggles readonly mode of the active view. Depending on state I can manipulate/edit content or not.

0 Likes

#9

sorry, I misused the word. it means editable

when I perform
class ReadOnlyEventListener(…)

class ToggleReadOnlyCommand(…)

, it is still editable

0 Likes

#10

When I provided this plugin the instructions included an augmentation to the main menu to provide a version of the command that gives the event listener the information it needs to trigger the command; have you also included that step? You don’t mention it anywhere here.

0 Likes

#12

Maybe I missed something. Let me check.

Thank you very much.

0 Likes

#13

%E6%97%A0%E6%A0%87%E9%A2%98

if st3 :
editable = false
if st4:
editable = true

0 Likes