Skip to content

Commit

Permalink
#2737 Command File Launcher : Add command for launching command file …
Browse files Browse the repository at this point in the history
…from UI
  • Loading branch information
magnesj committed Apr 13, 2018
1 parent 1d3bc68 commit dfa87b2
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
Original file line number Diff line number Diff line change
@@ -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;
};
2 changes: 2 additions & 0 deletions ApplicationCode/UserInterface/RiuMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dfa87b2

Please sign in to comment.