Skip to content

Commit

Permalink
Allow plugins to hook into "Close all" action
Browse files Browse the repository at this point in the history
  • Loading branch information
jitseniesen committed Dec 27, 2024
1 parent 974a6ea commit e561527
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
10 changes: 10 additions & 0 deletions spyder/api/plugins/new_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,16 @@ def close_file(self) -> None:
"""
raise NotImplementedError

def close_all(self) -> None:
"""
Close all opened files.
This function will be called if the `File > Close all` menu item is
selected while the plugin has focus and `CAN_HANDLE_FILE_ACTIONS` is
set to `True`.
"""
raise NotImplementedError

def get_current_filename(self) -> Optional[str]:
"""
Return file name of the file that is currently displayed.
Expand Down
15 changes: 12 additions & 3 deletions spyder/plugins/application/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,19 @@ def close_file(self) -> None:

def close_all(self) -> None:
"""
Close all opened files in the Editor plugin.
Close all opened files in the current plugin.
If the plugin that currently has focus, has its
`CAN_HANDLE_FILE_ACTIONS` attribute set to `True`, then revert the
current file in that plugin to the version stored on disk. Otherwise,
revert the current file in the Editor plugin.
"""
editor = self.get_plugin(Plugins.Editor)
editor.close_all_files()
plugin = self.focused_plugin
if plugin and getattr(plugin, 'CAN_HANDLE_FILE_ACTIONS', False):
plugin.close_all()
elif self.is_plugin_available(Plugins.Editor):
editor = self.get_plugin(Plugins.Editor)
editor.close_all_files()

def enable_file_action(
self,
Expand Down

0 comments on commit e561527

Please sign in to comment.