#2737 Command File Launcher : Add command for launching command file from UI

This commit is contained in:
Magne Sjaastad 2018-04-13 09:44:34 +02:00
parent 1d3bc6887e
commit dfa87b218f
4 changed files with 113 additions and 0 deletions

View File

@ -14,6 +14,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicHelpFeatures.h
${CMAKE_CURRENT_LIST_DIR}/RicEditPreferencesFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicShowPlotDataFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicLaunchRegressionTestsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicRunCommandFileFeature.h
)
set (SOURCE_GROUP_SOURCE_FILES
@ -31,6 +32,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicHelpFeatures.cpp
${CMAKE_CURRENT_LIST_DIR}/RicEditPreferencesFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicShowPlotDataFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicLaunchRegressionTestsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicRunCommandFileFeature.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@ -0,0 +1,75 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018 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 "RicRunCommandFileFeature.h"
#include "RiaApplication.h"
#include "RicfCommandFileExecutor.h"
#include <QAction>
#include <QDir>
#include <QFileDialog>
CAF_CMD_SOURCE_INIT(RicRunCommandFileFeature, "RicRunCommandFileFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicRunCommandFileFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicRunCommandFileFeature::onActionTriggered(bool isChecked)
{
RiaApplication* app = RiaApplication::instance();
QString defaultDir = app->lastUsedDialogDirectory("COMMAND_FILE");
QString fileName = QFileDialog::getOpenFileName(nullptr, "Open ResInsight Command File", defaultDir, "ResInsight Command File (*.txt);;All files(*.*)");
if (!fileName.isEmpty())
{
QFile file(fileName);
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream in(&file);
QString applicationPath = QDir::currentPath();
QFileInfo fi(fileName);
QDir::setCurrent(fi.absolutePath());
RicfCommandFileExecutor::instance()->executeCommands(in);
QDir::setCurrent(applicationPath);
app->setLastUsedDialogDirectory("COMMAND_FILE", QFileInfo(fileName).absolutePath());
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicRunCommandFileFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setText("Run Command File");
}

View File

@ -0,0 +1,34 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicRunCommandFileFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
private:
bool isCommandEnabled() override;
void onActionTriggered(bool isChecked) override;
void setupActionLook(QAction* actionToSetup) override;
};

View File

@ -452,6 +452,7 @@ void RiuMainWindow::createMenus()
testMenu->addAction(m_showRegressionTestDialog);
testMenu->addAction(m_executePaintEventPerformanceTest);
testMenu->addAction(cmdFeatureMgr->action("RicLaunchUnitTestsFeature"));
testMenu->addAction(cmdFeatureMgr->action("RicRunCommandFileFeature"));
// Windows menu
m_windowMenu = menuBar()->addMenu("&Windows");
@ -544,6 +545,7 @@ void RiuMainWindow::createToolBars()
toolbar->setObjectName(toolbar->windowTitle());
toolbar->addAction(cmdFeatureMgr->action("RicLaunchUnitTestsFeature"));
toolbar->addAction(cmdFeatureMgr->action("RicLaunchRegressionTestsFeature"));
toolbar->addAction(cmdFeatureMgr->action("RicRunCommandFileFeature"));
}
// Create animation toolbar