Disable script editor close and tab close when we have a modal dialog up

about external changes to the file.
This commit is contained in:
howard-stearns 2016-03-17 16:54:59 -07:00
parent 307a0cf05a
commit a957716511
3 changed files with 44 additions and 9 deletions

View file

@ -222,22 +222,32 @@ bool ScriptEditorWidget::questionSave() {
void ScriptEditorWidget::onWindowActivated() { void ScriptEditorWidget::onWindowActivated() {
if (!_isReloading) { if (!_isReloading) {
auto window = static_cast<ScriptEditorWindow*>(this->parent()->parent()->parent());
_isReloading = true; _isReloading = true;
if (QFileInfo(_currentScript).lastModified() > _currentScriptModified) { QDateTime fileStamp = QFileInfo(_currentScript).lastModified();
if (static_cast<ScriptEditorWindow*>(this->parent()->parent()->parent())->autoReloadScripts() if (fileStamp > _currentScriptModified) {
|| OffscreenUi::warning(this, _currentScript, bool doReload = false;
tr("This file has been modified outside of the Interface editor.") + "\n\n" window->inModalDialog = true;
+ (isModified() if (static_cast<ScriptEditorWindow*>(this->parent()->parent()->parent())->autoReloadScripts() ||
? tr("Do you want to reload it and lose the changes you've made in the Interface editor?") OffscreenUi::warning(this, _currentScript,
: tr("Do you want to reload it?")), tr("This file has been modified outside of the Interface editor.") + "\n\n" +
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { (isModified() ?
tr("Do you want to reload it and lose the changes you've made in the Interface editor?") :
tr("Do you want to reload it?")),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
doReload = true;
}
window->inModalDialog = false;
if (doReload) {
loadFile(_currentScript); loadFile(_currentScript);
if (_scriptEditorWidgetUI->onTheFlyCheckBox->isChecked() && isRunning()) { if (_scriptEditorWidgetUI->onTheFlyCheckBox->isChecked() && isRunning()) {
_isRestarting = true; _isRestarting = true;
setRunning(false); setRunning(false);
// Script is restarted once current script instance finishes. // Script is restarted once current script instance finishes.
} }
} else {
_currentScriptModified = fileStamp;
} }
} }
_isReloading = false; _isReloading = false;

View file

@ -171,6 +171,9 @@ void ScriptEditorWindow::tabSwitched(int tabIndex) {
} }
void ScriptEditorWindow::tabCloseRequested(int tabIndex) { void ScriptEditorWindow::tabCloseRequested(int tabIndex) {
if (ignoreCloseForModal(nullptr)) {
return;
}
ScriptEditorWidget* closingScriptWidget = static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget ScriptEditorWidget* closingScriptWidget = static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget
->widget(tabIndex)); ->widget(tabIndex));
if(closingScriptWidget->questionSave()) { if(closingScriptWidget->questionSave()) {
@ -178,7 +181,26 @@ void ScriptEditorWindow::tabCloseRequested(int tabIndex) {
} }
} }
// If this operating system window causes a qml overlay modal dialog (which might not even be seen by the user), closing this window
// will crash the code that was waiting on the dialog result. So that code whousl set inModalDialog to true while the question is up.
// This code will not be necessary when switch out all operating system windows for qml overlays.
bool ScriptEditorWindow::ignoreCloseForModal(QCloseEvent* event) {
if (!inModalDialog) {
return false;
}
// Deliberately not using OffscreenUi, so that the dialog is seen.
QMessageBox::information(this, tr("Interface"), tr("There is a modal dialog that must be answered before closing."),
QMessageBox::Discard, QMessageBox::Discard);
if (event) {
event->ignore(); // don't close
}
return true;
}
void ScriptEditorWindow::closeEvent(QCloseEvent *event) { void ScriptEditorWindow::closeEvent(QCloseEvent *event) {
if (ignoreCloseForModal(event)) {
return;
}
bool unsaved_docs_warning = false; bool unsaved_docs_warning = false;
for (int i = 0; i < _ScriptEditorWindowUI->tabWidget->count(); i++){ for (int i = 0; i < _ScriptEditorWindowUI->tabWidget->count(); i++){
if(static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget->widget(i))->isModified()){ if(static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget->widget(i))->isModified()){

View file

@ -28,6 +28,9 @@ public:
void terminateCurrentTab(); void terminateCurrentTab();
bool autoReloadScripts(); bool autoReloadScripts();
bool inModalDialog { false };
bool ignoreCloseForModal(QCloseEvent* event);
signals: signals:
void windowActivated(); void windowActivated();