Files
ResInsight/ApplicationLibCode/Commands/ApplicationCommands/RicSaveProjectAsFeature.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

88 lines
3.2 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016 Statoil 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 "RicSaveProjectAsFeature.h"
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include "RicSaveProjectFeature.h"
#include "Riu3DMainWindowTools.h"
#include "RiuMessageDialog.h"
#include "cafPdmFieldScriptingCapability.h"
#include <QAction>
RICF_SOURCE_INIT( RicSaveProjectAsFeature, "RicSaveProjectAsFeature", "saveProjectAs" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicSaveProjectAsFeature::RicSaveProjectAsFeature()
{
CAF_PDM_InitScriptableFieldNoDefault( &m_filePath, "filePath", "" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmScriptResponse RicSaveProjectAsFeature::execute()
{
disableModelChangeContribution();
QString errorMessage;
if ( !RiaApplication::instance()->saveProjectAs( m_filePath(), &errorMessage ) )
{
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, errorMessage );
}
return caf::PdmScriptResponse();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveProjectAsFeature::onActionTriggered( bool isChecked )
{
RiaGuiApplication* app = RiaGuiApplication::instance();
if ( app )
{
m_filePath = app->promptForProjectSaveAsFileName();
if ( m_filePath().isEmpty() )
{
return;
}
auto response = execute();
if ( response.status() != caf::PdmScriptResponse::COMMAND_OK )
{
QString displayMessage = response.messages().join( "\n" );
RiuMessageDialog::showError( nullptr, "Error when saving project file", displayMessage );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveProjectAsFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Save Project &As..." );
actionToSetup->setIcon( QIcon( ":/SaveAs.svg" ) );
applyShortcutWithHintToAction( actionToSetup, QKeySequence::SaveAs );
}