mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-23 23:13:39 -06:00
4d1f98c138
Did some additional refactoring - added code common to script related features to RicScriptFeatureImpl.
106 lines
3.6 KiB
C++
106 lines
3.6 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2015- Statoil ASA
|
|
// Copyright (C) 2015- Ceetron Solutions AS
|
|
//
|
|
// 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 "RicNewScriptFeature.h"
|
|
|
|
#include "RicScriptFeatureImpl.h"
|
|
|
|
#include "RimCalcScript.h"
|
|
#include "RimScriptCollection.h"
|
|
#include "RiaApplication.h"
|
|
|
|
#include "RiuMainWindow.h"
|
|
|
|
#include <QAction>
|
|
#include <QFileInfo>
|
|
#include <QMessageBox>
|
|
|
|
CAF_CMD_SOURCE_INIT(RicNewScriptFeature, "RicNewScriptFeature");
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool RicNewScriptFeature::isCommandEnabled()
|
|
{
|
|
std::vector<RimCalcScript*> selection = RicScriptFeatureImpl::selectedScripts();
|
|
return selection.size() > 0;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RicNewScriptFeature::onActionTriggered(bool isChecked)
|
|
{
|
|
std::vector<RimCalcScript*> calcScripts = RicScriptFeatureImpl::selectedScripts();
|
|
std::vector<RimScriptCollection*> calcScriptCollections = RicScriptFeatureImpl::selectedScriptCollections();
|
|
|
|
RimCalcScript* calcScript = calcScripts.size() > 0 ? calcScripts[0] : NULL;
|
|
RimScriptCollection* scriptColl = calcScriptCollections.size() > 0 ? calcScriptCollections[0] : NULL;
|
|
|
|
QString fullPathNewScript;
|
|
|
|
if (calcScript )
|
|
{
|
|
QFileInfo existingScriptFileInfo(calcScript->absolutePath());
|
|
fullPathNewScript = existingScriptFileInfo.absolutePath();
|
|
}
|
|
else if (scriptColl)
|
|
{
|
|
fullPathNewScript = scriptColl->directory();
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
|
|
QString fullPathFilenameNewScript;
|
|
|
|
fullPathFilenameNewScript = fullPathNewScript + "/untitled.m";
|
|
int num= 1;
|
|
while (QFileInfo(fullPathFilenameNewScript).exists())
|
|
{
|
|
fullPathFilenameNewScript = fullPathNewScript + "/untitled" + QString::number(num) + ".m";
|
|
num++;
|
|
}
|
|
|
|
RiaApplication* app = RiaApplication::instance();
|
|
QString scriptEditor = app->scriptEditorPath();
|
|
if (!scriptEditor.isEmpty())
|
|
{
|
|
QStringList arguments;
|
|
arguments << fullPathFilenameNewScript;
|
|
|
|
QProcess* myProcess = new QProcess(this);
|
|
myProcess->start(scriptEditor, arguments);
|
|
|
|
if (!myProcess->waitForStarted(1000))
|
|
{
|
|
QMessageBox::warning(RiuMainWindow::instance(), "Script editor", "Failed to start script editor executable\n" + scriptEditor);
|
|
}
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RicNewScriptFeature::setupActionLook(QAction* actionToSetup)
|
|
{
|
|
actionToSetup->setText("New");
|
|
}
|