-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2737 Command File Launcher : Add command for launching command file …
…from UI
- Loading branch information
Showing
4 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
ApplicationCode/Commands/ApplicationCommands/RicRunCommandFileFeature.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
34 changes: 34 additions & 0 deletions
34
ApplicationCode/Commands/ApplicationCommands/RicRunCommandFileFeature.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters