feat: remember previous values for combobox
This commit is contained in:
parent
dd8798121d
commit
4db8bcff0e
3 changed files with 42 additions and 7 deletions
|
@ -4,6 +4,7 @@
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
RunApplet::RunApplet(QWidget *parent)
|
RunApplet::RunApplet(QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
|
@ -11,6 +12,8 @@ RunApplet::RunApplet(QWidget *parent)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
restoreState();
|
||||||
|
|
||||||
ui->label->setPixmap(QIcon::fromTheme("system-run-symbolic").pixmap(42, 42));
|
ui->label->setPixmap(QIcon::fromTheme("system-run-symbolic").pixmap(42, 42));
|
||||||
// https://forum.qt.io/post/291563
|
// https://forum.qt.io/post/291563
|
||||||
ui->cancelBtn->setIcon(style()->standardIcon(QStyle::SP_DialogCancelButton));
|
ui->cancelBtn->setIcon(style()->standardIcon(QStyle::SP_DialogCancelButton));
|
||||||
|
@ -24,6 +27,11 @@ RunApplet::RunApplet(QWidget *parent)
|
||||||
connect(ui->okBtn, &QPushButton::clicked, this, &RunApplet::runApp);
|
connect(ui->okBtn, &QPushButton::clicked, this, &RunApplet::runApp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RunApplet::~RunApplet()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
void RunApplet::runApp() {
|
void RunApplet::runApp() {
|
||||||
QString command = ui->comboBox->currentText();
|
QString command = ui->comboBox->currentText();
|
||||||
QStringList args = command.split(" ");
|
QStringList args = command.split(" ");
|
||||||
|
@ -37,14 +45,32 @@ void RunApplet::runApp() {
|
||||||
qApp->quit();
|
qApp->quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// QString errorMessage = process->errorString();
|
|
||||||
|
|
||||||
QMessageBox messageBox;
|
QMessageBox messageBox;
|
||||||
messageBox.critical(0, process->program(), QString(tr("Windows cannot find '%1'. Make sure you typed the name correctly, and then try again.")).arg(process->program()));
|
messageBox.critical(0, process->program(), QString(tr("Windows cannot find '%1'. Make sure you typed the name correctly, and then try again.")).arg(process->program()));
|
||||||
messageBox.setFixedSize(500,200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RunApplet::~RunApplet()
|
void RunApplet::closeEvent(QCloseEvent* evt) {
|
||||||
{
|
saveState();
|
||||||
delete ui;
|
|
||||||
|
return QDialog::closeEvent(evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RunApplet::saveState() {
|
||||||
|
// https://stackoverflow.com/a/33639884/16255372
|
||||||
|
QSettings settings("aero-applets", "run-applet");
|
||||||
|
|
||||||
|
QStringList commandHistory;
|
||||||
|
|
||||||
|
for (int i = 0; i < ui->comboBox->count(); i++) {
|
||||||
|
commandHistory.append(ui->comboBox->itemText(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.setValue("commandHistory", commandHistory);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RunApplet::restoreState() {
|
||||||
|
// https://stackoverflow.com/a/33639884/16255372
|
||||||
|
QSettings settings("aero-applets", "run-applet");
|
||||||
|
|
||||||
|
ui->comboBox->addItems(settings.value("commandHistory").toStringList());
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,5 +21,11 @@ private:
|
||||||
Ui::RunApplet *ui;
|
Ui::RunApplet *ui;
|
||||||
|
|
||||||
void runApp();
|
void runApp();
|
||||||
|
|
||||||
|
void saveState();
|
||||||
|
void restoreState();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void closeEvent(QCloseEvent*) override;
|
||||||
};
|
};
|
||||||
#endif // RUNAPPLET_H
|
#endif // RUNAPPLET_H
|
||||||
|
|
|
@ -11,7 +11,10 @@
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>RunApplet</string>
|
<string>Run</string>
|
||||||
|
</property>
|
||||||
|
<property name="windowIcon">
|
||||||
|
<iconset theme="system-run-symbolic"/>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
|
|
Loading…
Add table
Reference in a new issue