-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Change back the run dialog widget to a dialog
The widget is not needed anymore now that we have interactive scripts. Note: need update of the photon scripts (later). Revert "Move RunScript widget as part of the main window" This reverts commit b2793ab. New features: - use a combobox to list the scripts (easier to find) - save/restore latest run script (useful particularly with IDE integration)
- Loading branch information
1 parent
e0aa6a3
commit 3257c14
Showing
10 changed files
with
204 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
This file is part of Knut. | ||
SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
SPDX-License-Identifier: GPL-3.0-only | ||
Contact KDAB at <[email protected]> for commercial licensing options. | ||
*/ | ||
|
||
#include "runscriptdialog.h" | ||
#include "core/scriptmanager.h" | ||
#include "ui_runscriptdialog.h" | ||
|
||
#include <QApplication> | ||
#include <QFileDialog> | ||
#include <QLineEdit> | ||
#include <QPushButton> | ||
#include <QSettings> | ||
#include <kdalgorithms.h> | ||
|
||
namespace Gui { | ||
|
||
constexpr char LastScript[] = "lastScriptRun"; | ||
|
||
RunScriptDialog::RunScriptDialog(QWidget *parent) | ||
: QDialog(parent) | ||
, ui(new Ui::RunScriptDialog) | ||
{ | ||
ui->setupUi(this); | ||
ui->comboBox->lineEdit()->setPlaceholderText("Name or path of a script"); | ||
setWindowTitle(QApplication::applicationName() + ' ' + QApplication::applicationVersion() + " - " + windowTitle()); | ||
|
||
connect(ui->toolButton, &QToolButton::clicked, this, &RunScriptDialog::chooseScript); | ||
auto okButton = ui->buttonBox->button(QDialogButtonBox::Ok); | ||
okButton->setEnabled(false); | ||
connect(ui->comboBox, &QComboBox::currentTextChanged, this, [okButton](const QString &str) { | ||
okButton->setEnabled(!str.trimmed().isEmpty()); | ||
}); | ||
|
||
const auto &list = Core::ScriptManager::instance()->scriptList(); | ||
QStringList scriptNames; | ||
scriptNames.reserve(static_cast<int>(list.size())); | ||
for (const auto &item : list) | ||
scriptNames.push_back(item.name); | ||
ui->comboBox->addItems(scriptNames); | ||
|
||
// Load the latest script name from the settings | ||
QSettings settings; | ||
const auto &lastScript = settings.value(LastScript).toString(); | ||
if (!lastScript.isEmpty()) | ||
ui->comboBox->setCurrentText(lastScript); | ||
} | ||
|
||
RunScriptDialog::~RunScriptDialog() = default; | ||
|
||
void RunScriptDialog::accept() | ||
{ | ||
if (ui->comboBox->currentText().isEmpty()) | ||
return; | ||
|
||
QString scriptName = ui->comboBox->currentText(); | ||
// Store the latest script run from the dialog | ||
QSettings settings; | ||
settings.setValue(LastScript, scriptName); | ||
|
||
QFileInfo fi(scriptName); | ||
if (!fi.exists()) { | ||
const auto &list = Core::ScriptManager::instance()->scriptList(); | ||
auto result = kdalgorithms::find_if(list, [&scriptName](const auto &item) { | ||
return item.name == scriptName; | ||
}); | ||
if (!result) | ||
return; | ||
scriptName = result->fileName; | ||
} | ||
|
||
Core::ScriptManager::instance()->runScript(scriptName); | ||
QDialog::accept(); | ||
} | ||
|
||
void RunScriptDialog::chooseScript() | ||
{ | ||
const QString fileName = | ||
QFileDialog::getOpenFileName(this, QString(), ui->comboBox->currentText(), tr("Scripts (*.js *.qml)")); | ||
if (fileName.isEmpty()) | ||
return; | ||
ui->comboBox->setCurrentText(fileName); | ||
} | ||
|
||
} // namespace Gui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Gui::RunScriptDialog</class> | ||
<widget class="QDialog" name="Gui::RunScriptDialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>390</width> | ||
<height>70</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Run Script Dialog</string> | ||
</property> | ||
<layout class="QGridLayout" name="gridLayout"> | ||
<item row="1" column="0" colspan="2"> | ||
<widget class="QDialogButtonBox" name="buttonBox"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="0"> | ||
<widget class="QComboBox" name="comboBox"> | ||
<property name="editable"> | ||
<bool>true</bool> | ||
</property> | ||
<property name="insertPolicy"> | ||
<enum>QComboBox::NoInsert</enum> | ||
</property> | ||
<property name="placeholderText"> | ||
<string>Name or path of a script</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="1"> | ||
<widget class="QToolButton" name="toolButton"> | ||
<property name="toolTip"> | ||
<string>Select Script</string> | ||
</property> | ||
<property name="text"> | ||
<string>...</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>accepted()</signal> | ||
<receiver>Gui::RunScriptDialog</receiver> | ||
<slot>accept()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>248</x> | ||
<y>254</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>157</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>rejected()</signal> | ||
<receiver>Gui::RunScriptDialog</receiver> | ||
<slot>reject()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>316</x> | ||
<y>260</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>286</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
</connections> | ||
</ui> |
Oops, something went wrong.