2018-04-13 02:44:34 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-01-09 08:21:38 -06:00
|
|
|
// Copyright (C) 2018- Equinor ASA
|
2018-04-13 02:44:34 -05:00
|
|
|
//
|
|
|
|
// 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 "RicRunCommandFileFeature.h"
|
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
|
|
|
#include "RicfCommandFileExecutor.h"
|
2020-08-21 11:56:44 -05:00
|
|
|
#include "RiuFileDialogTools.h"
|
2018-04-13 02:44:34 -05:00
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
#include <QDir>
|
2020-08-21 11:56:44 -05:00
|
|
|
#include <QFileInfo>
|
2018-04-13 02:44:34 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_CMD_SOURCE_INIT( RicRunCommandFileFeature, "RicRunCommandFileFeature" );
|
2018-04-13 02:44:34 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicRunCommandFileFeature::onActionTriggered( bool isChecked )
|
2018-04-13 02:44:34 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
RiaApplication* app = RiaApplication::instance();
|
|
|
|
QString defaultDir = app->lastUsedDialogDirectoryWithFallbackToProjectFolder( "COMMAND_FILE" );
|
2018-04-13 02:44:34 -05:00
|
|
|
|
2020-08-21 11:56:44 -05:00
|
|
|
QString fileName = RiuFileDialogTools::getOpenFileName( nullptr,
|
|
|
|
"Open ResInsight Command File",
|
|
|
|
defaultDir,
|
|
|
|
"ResInsight Command File (*.txt);;All files(*.*)" );
|
2018-04-13 02:44:34 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !fileName.isEmpty() )
|
2018-04-13 02:44:34 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QFile file( fileName );
|
|
|
|
if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
2018-04-13 02:44:34 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QTextStream in( &file );
|
2018-04-13 02:44:34 -05:00
|
|
|
|
|
|
|
QString applicationPath = QDir::currentPath();
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
QFileInfo fi( fileName );
|
|
|
|
QDir::setCurrent( fi.absolutePath() );
|
2018-04-13 02:44:34 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
RicfCommandFileExecutor::instance()->executeCommands( in );
|
2018-04-13 02:44:34 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
QDir::setCurrent( applicationPath );
|
|
|
|
|
|
|
|
app->setLastUsedDialogDirectory( "COMMAND_FILE", QFileInfo( fileName ).absolutePath() );
|
2018-04-13 02:44:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicRunCommandFileFeature::setupActionLook( QAction* actionToSetup )
|
2018-04-13 02:44:34 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
actionToSetup->setText( "Run Command File" );
|
2018-04-13 02:44:34 -05:00
|
|
|
}
|