From a595b6c88fd96be5d28cb54666ed6ae7bb6c8e44 Mon Sep 17 00:00:00 2001 From: Gordon Crone Date: Wed, 11 Sep 2024 17:12:26 +0100 Subject: [PATCH] Only save schema files that have been modified and list modified files in the exiting dialog --- apps/SchemaEditor/SchemaKernelWrapper.cpp | 22 +++++++++++++++++++ apps/SchemaEditor/SchemaMainWindow.cpp | 26 ++++++++++++++++++----- include/dbe/SchemaKernelWrapper.hpp | 2 ++ 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/apps/SchemaEditor/SchemaKernelWrapper.cpp b/apps/SchemaEditor/SchemaKernelWrapper.cpp index 820739d..db46c3a 100644 --- a/apps/SchemaEditor/SchemaKernelWrapper.cpp +++ b/apps/SchemaEditor/SchemaKernelWrapper.cpp @@ -97,6 +97,28 @@ void dbse::KernelWrapper::SaveAllSchema() const Kernel->save_all_schema(); } +std::string dbse::KernelWrapper::ModifiedSchemaFiles() const +{ + std::string modified{""}; + for (auto [name, file] : Kernel->schema_files()) { + if (file->is_updated()) { + modified += file->get_full_file_name() + "\n\n"; + } + } + return modified; +} +int dbse::KernelWrapper::SaveModifiedSchema() const +{ + int nsaved = 0; + for (auto [name, file] : Kernel->schema_files()) { + if (file->is_updated()) { + Kernel->save_schema(file); + nsaved++; + } + } + return nsaved; +} + void dbse::KernelWrapper::CloseAllSchema() const { Kernel->close_all_schema(); diff --git a/apps/SchemaEditor/SchemaMainWindow.cpp b/apps/SchemaEditor/SchemaMainWindow.cpp index b454f15..d360ade 100644 --- a/apps/SchemaEditor/SchemaMainWindow.cpp +++ b/apps/SchemaEditor/SchemaMainWindow.cpp @@ -17,6 +17,9 @@ #include #include +//#include +#include + using namespace dunedaq; using namespace dunedaq::oks; @@ -140,14 +143,18 @@ void dbse::SchemaMainWindow::BuildTableModel() int dbse::SchemaMainWindow::ShouldSaveChanges() const { - if ( KernelWrapper::GetInstance().GetUndoStack()->isClean() ) + // if ( KernelWrapper::GetInstance().GetUndoStack()->isClean() ) + auto modified = KernelWrapper::GetInstance().ModifiedSchemaFiles(); + if (modified.empty()) { return QMessageBox::Discard; } + std::string msg = "There are unsaved changes in the following files:\n\n" + + modified + "Do you want to save the changes in the schema?\n"; return QMessageBox::question ( 0, tr ( "DBE" ), - QString ( "There are unsaved changes.\n\nDo you want to save the changes in the schema?\n" ), + QString ( msg.c_str() ), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save ); } @@ -217,7 +224,12 @@ void dbse::SchemaMainWindow::closeEvent ( QCloseEvent * event ) { try { - KernelWrapper::GetInstance().SaveAllSchema(); + int nsaved = KernelWrapper::GetInstance().SaveModifiedSchema(); + std::ostringstream ostream; + ostream << nsaved << " schema files successfully saved"; + std::string msg = ostream.str(); + QMessageBox::information ( 0, "Schema editor", + QString ( msg.c_str() ) ); KernelWrapper::GetInstance().CloseAllSchema(); } catch ( oks::exception & Ex ) @@ -292,9 +304,13 @@ void dbse::SchemaMainWindow::SaveSchema() { try { - KernelWrapper::GetInstance().SaveAllSchema(); + int nsaved = KernelWrapper::GetInstance().SaveModifiedSchema(); + //std::format msg("{} schema files successfully saved", nsaved) + std::ostringstream ostream; + ostream << nsaved << " schema files successfully saved"; + std::string msg = ostream.str(); QMessageBox::information ( 0, "Schema editor", - QString ( "Schema successfully saved" ) ); + QString ( msg.c_str() ) ); } catch ( oks::exception & Ex ) diff --git a/include/dbe/SchemaKernelWrapper.hpp b/include/dbe/SchemaKernelWrapper.hpp index a9d78b5..b77ad1a 100644 --- a/include/dbe/SchemaKernelWrapper.hpp +++ b/include/dbe/SchemaKernelWrapper.hpp @@ -43,6 +43,8 @@ class KernelWrapper: public QObject dunedaq::oks::OksClass * FindClass ( std::string ClassName ) const; void LoadSchema ( const std::string & SchemaName ) const; void SaveAllSchema() const; + std::string ModifiedSchemaFiles() const; + int SaveModifiedSchema() const; void CloseAllSchema() const; void CreateNewSchema ( const std::string & SchemaName ) const; bool AnyClassReferenceThis ( dunedaq::oks::OksClass * SchemaClass );