Sublime Forum

Differentiating between closing view and closing ST3: on_close hook


I am looking for a way to differentiate the following two events:

  • Closing a view by clicking the ‘X’ icon on its tab
  • Closing Sublime Text

According to my tests, both events trigger the on_close method in an EventListener class. (The only way I could test this was to write to a file upon closure or quitting.) I need to separate these events because I want a specific file that is a part of the rest of the plugin to be deleted when closed. At the moment, the file is also deleted when I exit the application as the on_close method is still called.

I’ve tested the plugin_unloaded function, but it seems as if it called after the files are closed as I tried creating a global flag exiting (boolean) which can be checked inside on_close and there was no difference.

Are there any ways around this?

I’ve changed the hook to on_pre_close and added a yes_no_cancel_dialog to interrupt the file closing so that the method ends if ‘Don’t Save’ (sublime.DIALOG_NO) is clicked. The view is then cloned to prevent it from ‘closong’.



you can vote for this feature here