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 | void ScriptEditorWindow::tabCloseRequested(int tabIndex) { | 173 | void ScriptEditorWindow::tabCloseRequested(int tabIndex) { |
| 174 | if (ignoreCloseForModal(nullptr)) { | ||
| 175 | return; | ||
| 176 | } | ||
| 174 | ScriptEditorWidget* closingScriptWidget = static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget | 177 | ScriptEditorWidget* closingScriptWidget = static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget |
| 175 | ->widget(tabIndex)); | 178 | ->widget(tabIndex)); |
| 176 | if(closingScriptWidget->questionSave()) { | 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 | void ScriptEditorWindow::closeEvent(QCloseEvent *event) { | 200 | void ScriptEditorWindow::closeEvent(QCloseEvent *event) { |
| 201 | if (ignoreCloseForModal(event)) { | ||
| 202 | return; | ||
| 203 | } | ||
| 182 | bool unsaved_docs_warning = false; | 204 | bool unsaved_docs_warning = false; |
| 183 | for (int i = 0; i < _ScriptEditorWindowUI->tabWidget->count(); i++){ | 205 | for (int i = 0; i < _ScriptEditorWindowUI->tabWidget->count(); i++){ |
| 184 | if(static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget->widget(i))->isModified()){ | 206 | if(static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget->widget(i))->isModified()){ |