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 <QProcess>
|
||||
#include <QMessageBox>
|
||||
#include <QSettings>
|
||||
|
||||
RunApplet::RunApplet(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
|
@ -11,6 +12,8 @@ RunApplet::RunApplet(QWidget *parent)
|
|||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
restoreState();
|
||||
|
||||
ui->label->setPixmap(QIcon::fromTheme("system-run-symbolic").pixmap(42, 42));
|
||||
// https://forum.qt.io/post/291563
|
||||
ui->cancelBtn->setIcon(style()->standardIcon(QStyle::SP_DialogCancelButton));
|
||||
|
@ -24,6 +27,11 @@ RunApplet::RunApplet(QWidget *parent)
|
|||
connect(ui->okBtn, &QPushButton::clicked, this, &RunApplet::runApp);
|
||||
}
|
||||
|
||||
RunApplet::~RunApplet()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void RunApplet::runApp() {
|
||||
QString command = ui->comboBox->currentText();
|
||||
QStringList args = command.split(" ");
|
||||
|
@ -37,14 +45,32 @@ void RunApplet::runApp() {
|
|||
qApp->quit();
|
||||
}
|
||||
|
||||
// QString errorMessage = process->errorString();
|
||||
|
||||
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.setFixedSize(500,200);
|
||||
}
|
||||
|
||||
RunApplet::~RunApplet()
|
||||
{
|
||||
delete ui;
|
||||
void RunApplet::closeEvent(QCloseEvent* evt) {
|
||||
saveState();
|
||||
|
||||
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;
|
||||
|
||||
void runApp();
|
||||
|
||||
void saveState();
|
||||
void restoreState();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent*) override;
|
||||
};
|
||||
#endif // RUNAPPLET_H
|
||||
|
|
|
@ -11,7 +11,10 @@
|
|||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>RunApplet</string>
|
||||
<string>Run</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset theme="system-run-symbolic"/>
|
||||
</property>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
|
|
Loading…
Add table
Reference in a new issue