Files
ResInsight/ApplicationLibCode/Commands/ApplicationCommands/RicRestoreProjectVersionsFeature.cpp
T
Magne Sjaastad 56ff80c8e2 #13360: Integrate project version restore tool into GUI
Add a GUI feature for restoring previous versions of a project file from
its backup database, replacing the need for the external standalone tool.

- RiaProjectBackupTools: add extractVersionsToFolder() to read all stored
  revisions from a project's .rspdb backup database and write each one to
  a timestamped .rsp file in a destination folder.
- RicRestoreProjectVersionsUi: dialog for selecting the project file and
  export folder, defaulting to the currently open project. Adds a Recent
  Project Files dropdown (backed by RiuRecentFileActionProvider) that
  quickly populates the project file and export folder fields.
- RicRestoreProjectVersionsFeature: new command feature wired into the
  File menu as 'Restore Previous Project Versions...', using the
  OpenFolder icon and placed after a separator below Save Project / Save
  Project As.
- RiuRecentFileActionProvider: add recentProjectFiles() to expose the
  list of recently used project files.
- Added '...' suffix to Save Project As, consistent with other
  dialog-launching actions.
2026-10-21 22:23:38 +02:00

105 lines
4.0 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2026- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicRestoreProjectVersionsFeature.h"
#include "RicRestoreProjectVersionsUi.h"
#include "RiaApplication.h"
#include "RiaProjectBackupTools.h"
#include "RimProject.h"
#include "RiuMainWindow.h"
#include "RiuMessageDialog.h"
#include "RiuRecentFileActionProvider.h"
#include "cafPdmUiPropertyViewDialog.h"
#include <QAction>
#include <QFile>
#include <QFileInfo>
#include <QIcon>
#include <QMessageBox>
CAF_CMD_SOURCE_INIT( RicRestoreProjectVersionsFeature, "RicRestoreProjectVersionsFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicRestoreProjectVersionsFeature::onActionTriggered( bool isChecked )
{
RicRestoreProjectVersionsUi featureUi;
RimProject* project = RiaApplication::instance()->project();
QString projectFileName = ( project ) ? project->fileName() : QString();
if ( projectFileName.isEmpty() )
{
projectFileName = RiuRecentFileActionProvider::lastUsedProjectFileName();
}
if ( !projectFileName.isEmpty() )
{
featureUi.setProjectFile( projectFileName );
featureUi.setExportFolder( QFileInfo( projectFileName ).absolutePath() );
}
caf::PdmUiPropertyViewDialog propertyDialog( RiuMainWindow::instance(),
&featureUi,
"Restore Previous Project Versions",
"",
QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
propertyDialog.resize( QSize( 560, 260 ) );
if ( propertyDialog.exec() != QDialog::Accepted ) return;
QString projectFile = featureUi.projectFile();
QString exportFolder = featureUi.exportFolder();
if ( projectFile.isEmpty() || exportFolder.isEmpty() ) return;
QString databaseFilePath = projectFile + "db";
if ( !QFile::exists( databaseFilePath ) )
{
RiuMessageDialog::showError( RiuMainWindow::instance(),
"Restore Previous Project Versions",
"No backup database was found for the selected project file.\n\n" + databaseFilePath );
return;
}
int numberOfFilesWritten = 0;
QString errorMessage;
if ( !RiaProjectBackupTools::extractVersionsToFolder( databaseFilePath, exportFolder, &numberOfFilesWritten, &errorMessage ) )
{
RiuMessageDialog::showError( RiuMainWindow::instance(), "Restore Previous Project Versions", errorMessage );
return;
}
QMessageBox::information( RiuMainWindow::instance(),
"Restore Previous Project Versions",
QString( "Restored %1 project version(s) to:\n%2" ).arg( numberOfFilesWritten ).arg( exportFolder ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicRestoreProjectVersionsFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Restore Previous Project Versions..." );
actionToSetup->setIcon( QIcon( ":/OpenFolder.svg" ) );
}