mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
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:
commit
5ca1598572
3 changed files with 38 additions and 3 deletions
|
@ -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;
|
||||
|
|
|
@ -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()){
|
||||
|
|
|
@ -28,6 +28,9 @@ public:
|
|||
void terminateCurrentTab();
|
||||
bool autoReloadScripts();
|
||||
|
||||
bool inModalDialog { false };
|
||||
bool ignoreCloseForModal(QCloseEvent* event);
|
||||
|
||||
signals:
|
||||
void windowActivated();
|
||||
|
||||
|
|
Loading…
Reference in a new issue