diff --git a/qt/applications/workbench/workbench/app/mainwindow.py b/qt/applications/workbench/workbench/app/mainwindow.py index 6d90a788410a8673317937397b7152e4e4cfe75d..19c6f7e14d6acdf693fa91d9c4eb084aa6d4ac3e 100644 --- a/qt/applications/workbench/workbench/app/mainwindow.py +++ b/qt/applications/workbench/workbench/app/mainwindow.py @@ -335,14 +335,16 @@ class MainWindow(QMainWindow): # ----------------------- Events --------------------------------- def closeEvent(self, event): # Close editors - self.editor.app_closing() - - # Close all open plots - # We don't want this at module scope here - import matplotlib.pyplot as plt #noqa - plt.close('all') - - event.accept() + if self.editor.app_closing(): + # Close all open plots + # We don't want this at module scope here + import matplotlib.pyplot as plt #noqa + plt.close('all') + + event.accept() + else: + # Cancel was pressed when closing an editor + event.ignore() # ----------------------- Slots --------------------------------- def open_file(self): diff --git a/qt/applications/workbench/workbench/plugins/editor.py b/qt/applications/workbench/workbench/plugins/editor.py index 2ee7be1c748f5f002e2bd2d292374ad340ebac6e..95a207e1e07af9bddb8e1760938e3c573bcd45d0 100644 --- a/qt/applications/workbench/workbench/plugins/editor.py +++ b/qt/applications/workbench/workbench/plugins/editor.py @@ -69,7 +69,11 @@ class MultiFileEditor(PluginWidget): # ----------- Plugin API -------------------- def app_closing(self): - self.editors.close_all() + """ + Tries to close all editors + :return: True if editors can be closed, false if cancelled + """ + return self.editors.close_all() def get_plugin_title(self): return "Editor" diff --git a/qt/python/mantidqt/widgets/codeeditor/multifileinterpreter.py b/qt/python/mantidqt/widgets/codeeditor/multifileinterpreter.py index 81f530f5e21f6026c709f4ed57a2a4d0ce9dacbb..5ccc4f9406806a2a65cc15e9bac3e101d0ed8739 100644 --- a/qt/python/mantidqt/widgets/codeeditor/multifileinterpreter.py +++ b/qt/python/mantidqt/widgets/codeeditor/multifileinterpreter.py @@ -70,9 +70,9 @@ class MultiPythonFileInterpreter(QWidget): interpreter.sig_editor_modified.connect(self.mark_current_tab_modified) interpreter.sig_filename_modified.connect(self.on_filename_modified) - tab_title, tab_toolip = _tab_title_and_toolip(filename) + tab_title, tab_tooltip = _tab_title_and_toolip(filename) tab_idx = self._tabs.addTab(interpreter, tab_title) - self._tabs.setTabToolTip(tab_idx, tab_toolip) + self._tabs.setTabToolTip(tab_idx, tab_tooltip) self._tabs.setCurrentIndex(tab_idx) return tab_idx @@ -81,22 +81,38 @@ class MultiPythonFileInterpreter(QWidget): self.current_editor().abort() def close_all(self): - """Close all tabs""" + """ + Close all tabs + :return: True if all tabs are closed, False if cancelled + """ for idx in reversed(range(self.editor_count)): - self.close_tab(idx) + if not self.close_tab(idx): + return False + + return True def close_tab(self, idx): - """Close the tab at the given index.""" + """ + Close the tab at the given index. + :param idx: The tab index + :return: True if tab is to be closed, False if cancelled + """ if idx >= self.editor_count: - return - editor = self.editor_at(idx) - if editor.confirm_close(): + return True + # Make the current tab active so that it is clear what you + # are being prompted to save + self._tabs.setCurrentIndex(idx) + if self.current_editor().confirm_close(): self._tabs.removeTab(idx) + else: + return False # we never want an empty widget if self.editor_count == 0: self.append_new_editor(content=self.default_content) + return True + def create_tabwidget(self): """Create a new QTabWidget with a button to add new tabs""" tabs = QTabWidget(self)