mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#649 New script feature : Create empty file before opening text editor
This commit is contained in:
parent
5ec9b9c568
commit
6e29bfe525
@ -29,7 +29,10 @@
|
|||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QLineEdit>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include "RicRefreshScriptsFeature.h"
|
||||||
|
|
||||||
CAF_CMD_SOURCE_INIT(RicNewScriptFeature, "RicNewScriptFeature");
|
CAF_CMD_SOURCE_INIT(RicNewScriptFeature, "RicNewScriptFeature");
|
||||||
|
|
||||||
@ -38,8 +41,7 @@ CAF_CMD_SOURCE_INIT(RicNewScriptFeature, "RicNewScriptFeature");
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
bool RicNewScriptFeature::isCommandEnabled()
|
bool RicNewScriptFeature::isCommandEnabled()
|
||||||
{
|
{
|
||||||
std::vector<RimCalcScript*> selection = RicScriptFeatureImpl::selectedScripts();
|
return true;
|
||||||
return selection.size() > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -55,7 +57,7 @@ void RicNewScriptFeature::onActionTriggered(bool isChecked)
|
|||||||
|
|
||||||
QString fullPathNewScript;
|
QString fullPathNewScript;
|
||||||
|
|
||||||
if (calcScript )
|
if (calcScript)
|
||||||
{
|
{
|
||||||
QFileInfo existingScriptFileInfo(calcScript->absolutePath());
|
QFileInfo existingScriptFileInfo(calcScript->absolutePath());
|
||||||
fullPathNewScript = existingScriptFileInfo.absolutePath();
|
fullPathNewScript = existingScriptFileInfo.absolutePath();
|
||||||
@ -79,19 +81,40 @@ void RicNewScriptFeature::onActionTriggered(bool isChecked)
|
|||||||
num++;
|
num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
RiaApplication* app = RiaApplication::instance();
|
bool ok;
|
||||||
QString scriptEditor = app->scriptEditorPath();
|
fullPathFilenameNewScript = QInputDialog::getText(NULL, "Specify new script file", "File name", QLineEdit::Normal, fullPathFilenameNewScript, &ok);
|
||||||
if (!scriptEditor.isEmpty())
|
|
||||||
|
if (ok && !fullPathFilenameNewScript.isEmpty())
|
||||||
{
|
{
|
||||||
QStringList arguments;
|
QFile file(fullPathFilenameNewScript);
|
||||||
arguments << fullPathFilenameNewScript;
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||||
|
|
||||||
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);
|
QMessageBox::warning(RiuMainWindow::instance(), "Script editor", "Failed to create file\n" + fullPathFilenameNewScript);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RicRefreshScriptsFeature::refreshScriptFolders();
|
||||||
|
|
||||||
|
if (calcScript)
|
||||||
|
{
|
||||||
|
RiuMainWindow::instance()->selectAsCurrentItem(calcScript);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,6 +216,7 @@ QStringList RimContextCommandBuilder::commandsFromSelection()
|
|||||||
{
|
{
|
||||||
commandIds << "RicAddScriptPathFeature";
|
commandIds << "RicAddScriptPathFeature";
|
||||||
commandIds << "RicDeleteScriptPathFeature";
|
commandIds << "RicDeleteScriptPathFeature";
|
||||||
|
commandIds << "RicNewScriptFeature";
|
||||||
commandIds << "Separator";
|
commandIds << "Separator";
|
||||||
commandIds << "RicRefreshScriptsFeature";
|
commandIds << "RicRefreshScriptsFeature";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user