mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-23 15:03:27 -06:00
(#339) Added RicNewScriptFeature
This commit is contained in:
parent
f0ee19d8f7
commit
ac529b77da
@ -7,6 +7,7 @@ endif()
|
||||
set (SOURCE_GROUP_HEADER_FILES
|
||||
${CEE_CURRENT_LIST_DIR}RicCloseCaseFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicEditScriptFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicNewScriptFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicExecuteScriptFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicExecuteScriptForCasesFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicEclipseCaseNewGroupFeature.h
|
||||
@ -51,6 +52,7 @@ ${CEE_CURRENT_LIST_DIR}RicDeleteItemFeature.h
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
${CEE_CURRENT_LIST_DIR}RicCloseCaseFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicEditScriptFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicNewScriptFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicExecuteScriptFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicExecuteScriptForCasesFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicEclipseCaseNewGroupFeature.cpp
|
||||
|
127
ApplicationCode/Commands/RicNewScriptFeature.cpp
Normal file
127
ApplicationCode/Commands/RicNewScriptFeature.cpp
Normal file
@ -0,0 +1,127 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RimCalcScript.h"
|
||||
#include "RimScriptCollection.h"
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "RiuMainWindow.h"
|
||||
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicNewScriptFeature, "RicNewScriptFeature");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicNewScriptFeature::isCommandEnabled()
|
||||
{
|
||||
std::vector<RimCalcScript*> selection = selectedScripts();
|
||||
return selection.size() > 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicNewScriptFeature::onActionTriggered(bool isChecked)
|
||||
{
|
||||
std::vector<RimCalcScript*> calcScripts = selectedScripts();
|
||||
std::vector<RimScriptCollection*> calcScriptCollections = 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");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RimCalcScript*> RicNewScriptFeature::selectedScripts()
|
||||
{
|
||||
std::vector<RimCalcScript*> selection;
|
||||
caf::SelectionManager::instance()->objectsByType(&selection);
|
||||
|
||||
return selection;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RimScriptCollection*> RicNewScriptFeature::selectedScriptCollections()
|
||||
{
|
||||
std::vector<RimScriptCollection*> selection;
|
||||
caf::SelectionManager::instance()->objectsByType(&selection);
|
||||
|
||||
return selection;
|
||||
}
|
47
ApplicationCode/Commands/RicNewScriptFeature.h
Normal file
47
ApplicationCode/Commands/RicNewScriptFeature.h
Normal file
@ -0,0 +1,47 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafCmdFeature.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class RimCalcScript;
|
||||
class RimScriptCollection;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicNewScriptFeature : public caf::CmdFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
protected:
|
||||
// Overrides
|
||||
virtual bool isCommandEnabled();
|
||||
virtual void onActionTriggered( bool isChecked );
|
||||
virtual void setupActionLook( QAction* actionToSetup );
|
||||
|
||||
private:
|
||||
std::vector<RimCalcScript*> selectedScripts();
|
||||
std::vector<RimScriptCollection*> selectedScriptCollections();
|
||||
};
|
||||
|
||||
|
@ -657,6 +657,8 @@ void RimProject::actionsBasedOnSelection(QMenu& contextMenu)
|
||||
else if (dynamic_cast<RimCalcScript*>(uiItem))
|
||||
{
|
||||
commandIds << "RicEditScriptFeature";
|
||||
commandIds << "RicNewScriptFeature";
|
||||
commandIds << "Separator";
|
||||
commandIds << "RicExecuteScriptFeature";
|
||||
}
|
||||
}
|
||||
|
@ -540,6 +540,7 @@ void RimUiTreeView::slotEditScript()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// OBSOLETE - see RicNewScriptFeature
|
||||
void RimUiTreeView::slotNewScript()
|
||||
{
|
||||
QModelIndex index = currentIndex();
|
||||
|
Loading…
Reference in New Issue
Block a user