improve process selection

This commit is contained in:
Akash Mozumdar 2022-01-29 12:49:48 -07:00
parent 6ba4f9c909
commit c9240d9e68
4 changed files with 10 additions and 23 deletions

View File

@ -4,14 +4,13 @@
extern const char* SELECT_PROCESS; extern const char* SELECT_PROCESS;
extern const char* ATTACH_INFO; extern const char* ATTACH_INFO;
AttachProcessDialog::AttachProcessDialog(QWidget *parent, std::vector<std::pair<QString, HICON>> processIcons) : AttachProcessDialog::AttachProcessDialog(QWidget* parent, std::vector<std::pair<QString, HICON>> processIcons) :
QDialog(parent, Qt::WindowCloseButtonHint), QDialog(parent, Qt::WindowCloseButtonHint),
model(this) model(this)
{ {
ui.setupUi(this); ui.setupUi(this);
setWindowTitle(SELECT_PROCESS); setWindowTitle(SELECT_PROCESS);
ui.label->setText(ATTACH_INFO); ui.label->setText(ATTACH_INFO);
ui.processIdEdit->setValidator(new QIntValidator(0, INT_MAX, this));
ui.processList->setModel(&model); ui.processList->setModel(&model);
QPixmap transparent(100, 100); QPixmap transparent(100, 100);
@ -25,24 +24,16 @@ AttachProcessDialog::AttachProcessDialog(QWidget *parent, std::vector<std::pair<
connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(ui.processList, &QListView::clicked, [this](QModelIndex index) connect(ui.processList, &QListView::clicked, [this](QModelIndex index) { ui.processEdit->setText(model.item(index.row())->text()); });
connect(ui.processList, &QListView::doubleClicked, this, &QDialog::accept);
connect(ui.processEdit, &QLineEdit::textEdited, [this](QString process)
{ {
selectedProcess = model.item(index.row())->text(); for (int i = 0; i < model.rowCount(); ++i) ui.processList->setRowHidden(i, !model.item(i)->text().contains(process, Qt::CaseInsensitive));
}); });
connect(ui.processList, &QListView::doubleClicked, [this](QModelIndex index) connect(ui.processEdit, &QLineEdit::returnPressed, this, &QDialog::accept);
{
selectedProcess = model.item(index.row())->text();
accept();
});
connect(ui.processIdEdit, &QLineEdit::returnPressed, [this]
{
selectedProcess = ui.processIdEdit->text();
accept();
});
} }
QString AttachProcessDialog::SelectedProcess() QString AttachProcessDialog::SelectedProcess()
{ {
return selectedProcess.isEmpty() ? ui.processIdEdit->text() : selectedProcess; return ui.processEdit->text();
} }

View File

@ -7,7 +7,7 @@
class AttachProcessDialog : public QDialog class AttachProcessDialog : public QDialog
{ {
public: public:
explicit AttachProcessDialog(QWidget *parent, std::vector<std::pair<QString, HICON>> processIcons); explicit AttachProcessDialog(QWidget* parent, std::vector<std::pair<QString, HICON>> processIcons);
QString SelectedProcess(); QString SelectedProcess();
private: private:

View File

@ -18,11 +18,7 @@
<widget class="QLabel" name="label"/> <widget class="QLabel" name="label"/>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="processIdEdit"> <widget class="QLineEdit" name="processEdit"/>
<property name="placeholderText">
<string>Process id</string>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QListView" name="processList"/> <widget class="QListView" name="processList"/>

View File

@ -34,7 +34,7 @@ const char* EXTENSIONS = u8"Extensions";
const char* SELECT_PROCESS = u8"Select process"; const char* SELECT_PROCESS = u8"Select process";
const char* ATTACH_INFO = u8R"(If you don't see the process you want to attach, try running with admin rights const char* ATTACH_INFO = u8R"(If you don't see the process you want to attach, try running with admin rights
You can also type in the process ID)"; You can also type in the process ID)";
const char* SELECT_PROCESS_INFO = u8"If you manually type in the process file name, please use the absolute path"; const char* SELECT_PROCESS_INFO = u8"If you manually type in the process file name, use the absolute path";
const char* FROM_COMPUTER = u8"Select from computer"; const char* FROM_COMPUTER = u8"Select from computer";
const char* PROCESSES = u8"Processes (*.exe)"; const char* PROCESSES = u8"Processes (*.exe)";
const char* CODE_INFODUMP = u8R"(Enter read code const char* CODE_INFODUMP = u8R"(Enter read code