Skip to content

Commit

Permalink
Merge branch 'feature/#279' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
HuguesDelorme committed Jul 30, 2024
2 parents 4135cf4 + 4d2be7f commit 97627a0
Show file tree
Hide file tree
Showing 8 changed files with 587 additions and 503 deletions.
Binary file modified i18n/mayo_en.qm
Binary file not shown.
489 changes: 247 additions & 242 deletions i18n/mayo_en.ts

Large diffs are not rendered by default.

Binary file modified i18n/mayo_fr.qm
Binary file not shown.
509 changes: 277 additions & 232 deletions i18n/mayo_fr.ts

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions i18n/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ static void messages() {
Mayo::AppModuleProperties::textId("VeryPrecise");
Mayo::AppModuleProperties::textId("UserDefined");

Mayo::AppModuleProperties::textId("None");
Mayo::AppModuleProperties::textId("ReloadIfUserConfirm");
Mayo::AppModuleProperties::textId("ReloadSilently");

Mayo::WidgetModelTreeBuilder_Xde::textId("Instance");
Mayo::WidgetModelTreeBuilder_Xde::textId("Product");
Mayo::WidgetModelTreeBuilder_Xde::textId("Both");
Expand Down
21 changes: 15 additions & 6 deletions src/app/app_module_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "../base/unit_system.h"
#include "../graphics/graphics_mesh_object_driver.h"

#include <fmt/format.h>

namespace Mayo {

AppModuleProperties::AppModuleProperties(Settings* settings)
Expand All @@ -40,11 +42,12 @@ AppModuleProperties::AppModuleProperties(Settings* settings)
this->unitSystemDecimals.setConstraintsEnabled(true);

// Application
this->actionOnDocumentFileChange.mutableEnumeration().changeTrContext(AppModuleProperties::textIdContext());
settings->addSetting(&this->language, groupId_application);
settings->addSetting(&this->recentFiles, groupId_application);
settings->addSetting(&this->lastOpenDir, groupId_application);
settings->addSetting(&this->lastSelectedFormatFilter, groupId_application);
settings->addSetting(&this->reloadDocumentOnFileChange, groupId_application);
settings->addSetting(&this->actionOnDocumentFileChange, groupId_application);
settings->addSetting(&this->linkWithDocumentSelector, groupId_application);
settings->addSetting(&this->forceOpenGlFallbackWidget, groupId_application);
this->recentFiles.setUserVisible(false);
Expand Down Expand Up @@ -83,7 +86,7 @@ AppModuleProperties::AppModuleProperties(Settings* settings)
this->recentFiles.setValue({});
this->lastOpenDir.setValue({});
this->lastSelectedFormatFilter.setValue({});
this->reloadDocumentOnFileChange.setValue(true);
this->actionOnDocumentFileChange.setValue(ActionOnDocumentFileChange::None);
this->linkWithDocumentSelector.setValue(true);
#ifndef MAYO_OS_MAC
this->forceOpenGlFallbackWidget.setValue(false);
Expand Down Expand Up @@ -163,10 +166,16 @@ void AppModuleProperties::retranslate()
this->language.setDescription(
textIdTr("Language used for the application. Change will take effect after application restart")
);
this->reloadDocumentOnFileChange.setDescription(
textIdTr("Monitors the file system for changes to documents opened in the application\n\n"
"When such a file change is detected then the application proposes to reload(open again) the document")
);
const auto& enumActionOnDocumentFileChange = this->actionOnDocumentFileChange.enumeration();
this->actionOnDocumentFileChange.setDescription(
fmt::format(textIdTr("Action to be done after some opened document file is changed(modified) externally\n\n"
"Select options `{0}` or `{1}` so the application monitors changes made to opened files\n\n"
"When such a change is detected then the application proposes to reload(open again) the document\n\n"
"Select `{1}` to automatically reload documents without any user interaction"
),
enumActionOnDocumentFileChange.findItemByValue(ActionOnDocumentFileChange::ReloadIfUserConfirm)->name.tr(),
enumActionOnDocumentFileChange.findItemByValue(ActionOnDocumentFileChange::ReloadSilently)->name.tr()
));
this->linkWithDocumentSelector.setDescription(
textIdTr("In case where multiple documents are opened, make sure the document displayed in "
"the 3D view corresponds to what is selected in the model tree")
Expand Down
8 changes: 7 additions & 1 deletion src/app/app_module_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ namespace Mayo {
namespace IO { class System; }
class Settings;

enum class ActionOnDocumentFileChange {
None,
ReloadIfUserConfirm,
ReloadSilently
};

// Provides a container of all the application properties(settings)
// Properties are structured into predefined Settings groups/sections
class AppModuleProperties : public PropertyGroup {
Expand All @@ -51,7 +57,7 @@ class AppModuleProperties : public PropertyGroup {
PropertyRecentFiles recentFiles{ this, textId("recentFiles") };
PropertyFilePath lastOpenDir{ this, textId("lastOpenFolder") };
PropertyString lastSelectedFormatFilter{ this, textId("lastSelectedFormatFilter") };
PropertyBool reloadDocumentOnFileChange{ this, textId("reloadDocumentOnFileChange") };
PropertyEnum<ActionOnDocumentFileChange> actionOnDocumentFileChange{ this, textId("actionOnDocumentFileChange") };
PropertyBool linkWithDocumentSelector{ this, textId("linkWithDocumentSelector") };
PropertyBool forceOpenGlFallbackWidget{ this, textId("forceOpenGlFallbackWidget") };
// Meshing
Expand Down
59 changes: 37 additions & 22 deletions src/app/widget_main_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ WidgetMainControl::WidgetMainControl(GuiApplication* guiApp, QWidget* parent)

// Document files monitoring
auto appModule = AppModule::get();
const auto& propReloadDocOnFileChange = appModule->properties()->reloadDocumentOnFileChange;
m_docFilesWatcher->enable(propReloadDocOnFileChange);
const auto& propActionOnDocumentFileChange = appModule->properties()->actionOnDocumentFileChange;
m_docFilesWatcher->enable(propActionOnDocumentFileChange != ActionOnDocumentFileChange::None);
appModule->settings()->signalChanged.connectSlot([&](const Property* property) {
if (property == &propReloadDocOnFileChange) {
m_docFilesWatcher->enable(propReloadDocOnFileChange);
if (property == &propActionOnDocumentFileChange) {
m_docFilesWatcher->enable(propActionOnDocumentFileChange != ActionOnDocumentFileChange::None);
m_pendingDocsToReload.clear();
}
});
Expand Down Expand Up @@ -329,26 +329,41 @@ QWidget* WidgetMainControl::recreateLeftHeaderPlaceHolder()

void WidgetMainControl::reloadDocumentAfterChange(const DocumentPtr& doc)
{
const QString strQuestion =
tr("Document file `%1` has been changed since it was opened\n\n"
"Do you want to reload that document?\n\n"
"File: `%2`")
.arg(to_QString(doc->name()))
.arg(QDir::toNativeSeparators(filepathTo<QString>(doc->filePath())))
;
const auto msgBtns = QMessageBox::Yes | QMessageBox::No;
auto msgBox = new QMessageBox(QMessageBox::Question, tr("Question"), strQuestion, msgBtns, this);
msgBox->setTextFormat(Qt::MarkdownText);
QtWidgetsUtils::asyncDialogExec(msgBox);
QObject::connect(msgBox, &QMessageBox::buttonClicked, this, [=](QAbstractButton* btn) {
// Helper function to reload document
auto fnReloadDoc = [this](const DocumentPtr& doc) {
while (doc->entityCount() > 0)
doc->destroyEntity(doc->entityTreeNodeId(0));
FileCommandTools::importInDocument(m_appContext, doc, doc->filePath());
};

// Shortcut on "action" property
const auto& propActionOnDocumentFileChange = AppModule::get()->properties()->actionOnDocumentFileChange;

// Option: silent reloading
if (propActionOnDocumentFileChange == ActionOnDocumentFileChange::ReloadSilently) {
m_docFilesWatcher->acknowledgeDocumentFileChange(doc);
if (btn == msgBox->button(QMessageBox::Yes)) {
while (doc->entityCount() > 0)
doc->destroyEntity(doc->entityTreeNodeId(0));
fnReloadDoc(doc);
}

FileCommandTools::importInDocument(m_appContext, doc, doc->filePath());
}
});
// Option: ask user to confirm reloading
if (propActionOnDocumentFileChange == ActionOnDocumentFileChange::ReloadIfUserConfirm) {
const QString strQuestion =
tr("Document file `%1` has been changed since it was opened\n\n"
"Do you want to reload that document?\n\n"
"File: `%2`")
.arg(to_QString(doc->name()))
.arg(QDir::toNativeSeparators(filepathTo<QString>(doc->filePath())))
;
const auto msgBtns = QMessageBox::Yes | QMessageBox::No;
auto msgBox = new QMessageBox(QMessageBox::Question, tr("Question"), strQuestion, msgBtns, this);
msgBox->setTextFormat(Qt::MarkdownText);
QtWidgetsUtils::asyncDialogExec(msgBox);
QObject::connect(msgBox, &QMessageBox::buttonClicked, this, [=](QAbstractButton* btn) {
m_docFilesWatcher->acknowledgeDocumentFileChange(doc);
if (btn == msgBox->button(QMessageBox::Yes))
fnReloadDoc(doc);
});
}
}

WidgetGuiDocument* WidgetMainControl::widgetGuiDocument(int idx) const
Expand Down

0 comments on commit 97627a0

Please sign in to comment.