Sublime Forum

Is there a way to cancel closing a view from `on_pre_close`?

#1

I would like to mimic the “Save/Close/Cancel” functionality that you get when closing a view with unsaved changes, but on a scratch view, via plugin on ST3.
Apart from the lack of yes_no_cancel_dialog from earlier releases, I haven’t found a way to signal Sublime that the close should be aborted.
My current workaround is cloning the view (with run_command("clone") for lack of a view.clone() method) and opening a quick panel with the options.
Is there a better way?

0 Likes

#2

You can do what was proposes for the save command (except that it didn’t work there): Stop the user from saving based on a condition

I just verified that the “close” command is indeed forwarded to on_window_command (which means you need to access the view using window.active_view()).
This does obviously not work if the view is closed via API directly, e.g. view.close().

0 Likes