Showing the changes to interface/src/ui/ScriptEditorWindow.cpp (1 of 3 files). Show all
Unified · Split
| @@ -171,6 +171,9 @@ void ScriptEditorWindow::tabSwitched(int tabIndex) { · 170 unmodified lines | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | void ScriptEditorWindow::tabCloseRequested(int tabIndex) { |
| 174 | + if (ignoreCloseForModal(nullptr)) { | |
| 175 | + return; | |
| 176 | + } | |
| 174 | 177 | ScriptEditorWidget* closingScriptWidget = static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget |
| 175 | 178 | ->widget(tabIndex)); |
| 176 | 179 | if(closingScriptWidget->questionSave()) { |
| @@ -178,7 +181,26 @@ void ScriptEditorWindow::tabCloseRequested(int tabIndex) { · 1 unmodified line | ||
| 178 | 181 | } |
| 179 | 182 | } |
| 180 | 183 | |
| 184 | +// If this operating system window causes a qml overlay modal dialog (which might not even be seen by the user), closing this window | |
| 185 | +// will crash the code that was waiting on the dialog result. So that code whousl set inModalDialog to true while the question is up. | |
| 186 | +// This code will not be necessary when switch out all operating system windows for qml overlays. | |
| 187 | +bool ScriptEditorWindow::ignoreCloseForModal(QCloseEvent* event) { | |
| 188 | + if (!inModalDialog) { | |
| 189 | + return false; | |
| 190 | + } | |
| 191 | + // Deliberately not using OffscreenUi, so that the dialog is seen. | |
| 192 | + QMessageBox::information(this, tr("Interface"), tr("There is a modal dialog that must be answered before closing."), | |
| 193 | + QMessageBox::Discard, QMessageBox::Discard); | |
| 194 | + if (event) { | |
| 195 | + event->ignore(); // don't close | |
| 196 | + } | |
| 197 | + return true; | |
| 198 | +} | |
| 199 | + | |
| 181 | 200 | void ScriptEditorWindow::closeEvent(QCloseEvent *event) { |
| 201 | + if (ignoreCloseForModal(event)) { | |
| 202 | + return; | |
| 203 | + } | |
| 182 | 204 | bool unsaved_docs_warning = false; |
| 183 | 205 | for (int i = 0; i < _ScriptEditorWindowUI->tabWidget->count(); i++){ |
| 184 | 206 | if(static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget->widget(i))->isModified()){ |