From 34af3bf7e9cde06894a1dcedb761fa4ccf2a19c2 Mon Sep 17 00:00:00 2001 From: samamou Date: Fri, 27 Dec 2024 17:16:42 -0500 Subject: [PATCH] Test with hardcoded editor path --- .../Process/Script/ScriptEditor.cpp | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/plugins/score-lib-process/Process/Script/ScriptEditor.cpp b/src/plugins/score-lib-process/Process/Script/ScriptEditor.cpp index 425ee0c34b..b7f926e128 100644 --- a/src/plugins/score-lib-process/Process/Script/ScriptEditor.cpp +++ b/src/plugins/score-lib-process/Process/Script/ScriptEditor.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -54,7 +55,8 @@ ScriptDialog::ScriptDialog( &QDialog::close); auto openExternalBtn = new QPushButton{tr("Open in external editor.."), this}; - connect(openExternalBtn, &QPushButton::clicked, this, [this] {}); + connect( + openExternalBtn, &QPushButton::clicked, this, [this] { openInExternalEditor(); }); lay->addWidget(openExternalBtn); } @@ -156,4 +158,30 @@ void MultiScriptDialog::clearError() m_error->clear(); } -void ScriptDialog::openInExternalEditor() { } +void ScriptDialog::openInExternalEditor() +{ + QString editorPath + = "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"; + + if(editorPath.isEmpty()) + { + QMessageBox::warning( + this, tr("Error"), tr("no 'Default editor' configured in score settings")); + return; + } + + QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation); + QString tempFile = tempDir + "/ossia_script_temp.js"; + + QFile file(tempFile); + + QTextStream stream(&file); + stream << "Temporary file content for testing."; + file.close(); + + if(!QProcess::startDetached(editorPath, QStringList() << tempFile)) + { + QMessageBox::warning(this, tr("Error"), tr("Failed to launch external editor")); + } +} +}