diff --git a/src/CommitDialog.cpp b/src/CommitDialog.cpp index e05bdf1..6505303 100644 --- a/src/CommitDialog.cpp +++ b/src/CommitDialog.cpp @@ -169,10 +169,14 @@ void CommitDialog::on_pushButton_generate_with_ai_clicked() dlg.show(); dlg.generate(diff_); if (dlg.exec() == QDialog::Accepted) { - QString text = dlg.message(); - if (!text.isEmpty()) { + QStringList list = dlg.message(); + if (!list.isEmpty()) { + QString text; + for (QString const &line : list) { + text.append(line); + text.append('\n'); + } setText(text); - QString diff = dlg.diffText(); } } ui->plainTextEdit->setFocus(); diff --git a/src/GenerateCommitMessageDialog.cpp b/src/GenerateCommitMessageDialog.cpp index 43130fb..9cff79c 100644 --- a/src/GenerateCommitMessageDialog.cpp +++ b/src/GenerateCommitMessageDialog.cpp @@ -9,6 +9,7 @@ struct GenerateCommitMessageDialog::Private { QString diff; GenerateCommitMessageThread generator; + QStringList checked_items; }; GenerateCommitMessageDialog::GenerateCommitMessageDialog(QWidget *parent, QString const &model_name) @@ -38,7 +39,18 @@ void GenerateCommitMessageDialog::generate(QString const &diff) QApplication::setOverrideCursor(Qt::WaitCursor); + m->checked_items = message(); + ui->listWidget->clear(); + + ui->listWidget->addItems(m->checked_items); + for (int i = 0; i < ui->listWidget->count(); i++) { + auto *item = ui->listWidget->item(i); + if (m->checked_items.contains(item->text())) { + item->setCheckState(Qt::Checked); + } + } + ui->pushButton_regenerate->setEnabled(false); m->generator.request(CommitMessageGenerator::CommitMessage, diff); @@ -49,9 +61,17 @@ QString GenerateCommitMessageDialog::diffText() const return m->diff; } -QString GenerateCommitMessageDialog::message() const +QStringList GenerateCommitMessageDialog::message() const { - return ui->listWidget->currentItem()->text(); + QStringList list; + int n = ui->listWidget->count(); + for (int i = 0; i < n; i++) { + auto *item = ui->listWidget->item(i); + if (item->checkState() == Qt::Checked) { + list.append(item->text()); + } + } + return list; } void GenerateCommitMessageDialog::on_pushButton_regenerate_clicked() @@ -65,7 +85,13 @@ void GenerateCommitMessageDialog::onReady(const GeneratedCommitMessage &result) QApplication::restoreOverrideCursor(); if (result) { + int i = ui->listWidget->count(); ui->listWidget->addItems(result.messages); + int n = ui->listWidget->count();; + while (i < n) { + ui->listWidget->item(i)->setCheckState(Qt::Unchecked); + i++; + } ui->listWidget->setCurrentRow(0); } else { QString text = result.error_status + "\n\n" + result.error_message; @@ -75,5 +101,23 @@ void GenerateCommitMessageDialog::onReady(const GeneratedCommitMessage &result) ui->pushButton_regenerate->setEnabled(true); } +void GenerateCommitMessageDialog::on_listWidget_itemDoubleClicked(QListWidgetItem *item) +{ + item->setCheckState(Qt::Checked); + done(QDialog::Accepted); +} +void GenerateCommitMessageDialog::done(int stat) +{ + if (stat == QDialog::Accepted) { + QStringList list = message(); + if (list.empty()) { + auto *item = ui->listWidget->currentItem(); + if (item) { + item->setCheckState(Qt::Checked); + } + } + } + QDialog::done(stat); +} diff --git a/src/GenerateCommitMessageDialog.h b/src/GenerateCommitMessageDialog.h index 5620624..d9700d1 100644 --- a/src/GenerateCommitMessageDialog.h +++ b/src/GenerateCommitMessageDialog.h @@ -9,6 +9,8 @@ namespace Ui { class GenerateCommitMessageDialog; } +class QListWidgetItem; + class GenerateCommitMessageDialog : public QDialog { Q_OBJECT private: @@ -20,10 +22,15 @@ class GenerateCommitMessageDialog : public QDialog { ~GenerateCommitMessageDialog(); void generate(QString const &diff); QString diffText() const; - QString message() const; + QStringList message() const; private slots: void on_pushButton_regenerate_clicked(); void onReady(GeneratedCommitMessage const &list); + void on_listWidget_itemDoubleClicked(QListWidgetItem *item); + + // QDialog interface +public slots: + void done(int stat); }; #endif // GENERATECOMMITMESSAGEDIALOG_H diff --git a/src/GenerateCommitMessageDialog.ui b/src/GenerateCommitMessageDialog.ui index eae1090..67e8159 100644 --- a/src/GenerateCommitMessageDialog.ui +++ b/src/GenerateCommitMessageDialog.ui @@ -110,21 +110,5 @@ - - listWidget - doubleClicked(QModelIndex) - GenerateCommitMessageDialog - accept() - - - 219 - 84 - - - 225 - 169 - - -