Skip to content

Commit

Permalink
Only save schema files that have been modified and list modified file…
Browse files Browse the repository at this point in the history
…s in the exiting dialog
  • Loading branch information
gcrone committed Sep 11, 2024
1 parent f35df97 commit a595b6c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
22 changes: 22 additions & 0 deletions apps/SchemaEditor/SchemaKernelWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
26 changes: 21 additions & 5 deletions apps/SchemaEditor/SchemaMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include <QPrinter>
#include <QPrintDialog>

//#include <format>
#include <sstream>

using namespace dunedaq;
using namespace dunedaq::oks;

Expand Down Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down
2 changes: 2 additions & 0 deletions include/dbe/SchemaKernelWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit a595b6c

Please sign in to comment.