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 <QFileInfo>
|
||||
#include <QInputDialog>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include "RicRefreshScriptsFeature.h"
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicNewScriptFeature, "RicNewScriptFeature");
|
||||
|
||||
@ -38,8 +41,7 @@ CAF_CMD_SOURCE_INIT(RicNewScriptFeature, "RicNewScriptFeature");
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicNewScriptFeature::isCommandEnabled()
|
||||
{
|
||||
std::vector<RimCalcScript*> selection = RicScriptFeatureImpl::selectedScripts();
|
||||
return selection.size() > 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -55,7 +57,7 @@ void RicNewScriptFeature::onActionTriggered(bool isChecked)
|
||||
|
||||
QString fullPathNewScript;
|
||||
|
||||
if (calcScript )
|
||||
if (calcScript)
|
||||
{
|
||||
QFileInfo existingScriptFileInfo(calcScript->absolutePath());
|
||||
fullPathNewScript = existingScriptFileInfo.absolutePath();
|
||||
@ -79,19 +81,40 @@ void RicNewScriptFeature::onActionTriggered(bool isChecked)
|
||||
num++;
|
||||
}
|
||||
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
QString scriptEditor = app->scriptEditorPath();
|
||||
if (!scriptEditor.isEmpty())
|
||||
bool ok;
|
||||
fullPathFilenameNewScript = QInputDialog::getText(NULL, "Specify new script file", "File name", QLineEdit::Normal, fullPathFilenameNewScript, &ok);
|
||||
|
||||
if (ok && !fullPathFilenameNewScript.isEmpty())
|
||||
{
|
||||
QStringList arguments;
|
||||
arguments << fullPathFilenameNewScript;
|
||||
|
||||
QProcess* myProcess = new QProcess(this);
|
||||
myProcess->start(scriptEditor, arguments);
|
||||
|
||||
if (!myProcess->waitForStarted(1000))
|
||||
QFile file(fullPathFilenameNewScript);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
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 << "RicDeleteScriptPathFeature";
|
||||
commandIds << "RicNewScriptFeature";
|
||||
commandIds << "Separator";
|
||||
commandIds << "RicRefreshScriptsFeature";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user