Merge pull request #7388 from howard-stearns/os-window-vs-modal-overlay-in-script-editor

Os window vs modal overlay in script editor
This commit is contained in:
Chris Collins 2016-03-18 09:33:17 -07:00
commit 5ca1598572
3 changed files with 38 additions and 3 deletions

View file

@ -223,21 +223,31 @@ bool ScriptEditorWidget::questionSave() {
void ScriptEditorWidget::onWindowActivated() {
if (!_isReloading) {
_isReloading = true;
if (QFileInfo(_currentScript).lastModified() > _currentScriptModified) {
if (static_cast<ScriptEditorWindow*>(this->parent()->parent()->parent())->autoReloadScripts()
QDateTime fileStamp = QFileInfo(_currentScript).lastModified();
if (fileStamp > _currentScriptModified) {
bool doReload = false;
auto window = static_cast<ScriptEditorWindow*>(this->parent()->parent()->parent());
window->inModalDialog = true;
if (window->autoReloadScripts()
|| OffscreenUi::question(this, tr("Reload Script"),
tr("The following file has been modified outside of the Interface editor:") + "\n" + _currentScript + "\n"
+ (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);
if (_scriptEditorWidgetUI->onTheFlyCheckBox->isChecked() && isRunning()) {
_isRestarting = true;
setRunning(false);
// Script is restarted once current script instance finishes.
}
} else {
_currentScriptModified = fileStamp; // Asked and answered. Don't ask again until the external file is changed again.
}
}
_isReloading = false;

View file

@ -171,6 +171,9 @@ void ScriptEditorWindow::tabSwitched(int tabIndex) {
}
void ScriptEditorWindow::tabCloseRequested(int tabIndex) {
if (ignoreCloseForModal(nullptr)) {
return;
}
ScriptEditorWidget* closingScriptWidget = static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget
->widget(tabIndex));
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) {
if (ignoreCloseForModal(event)) {
return;
}
bool unsaved_docs_warning = false;
for (int i = 0; i < _ScriptEditorWindowUI->tabWidget->count(); i++){
if(static_cast<ScriptEditorWidget*>(_ScriptEditorWindowUI->tabWidget->widget(i))->isModified()){

View file

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