diff --git a/src/gui/EditWidgetProperties.cpp b/src/gui/EditWidgetProperties.cpp index 670ec9beeb..a06928c469 100644 --- a/src/gui/EditWidgetProperties.cpp +++ b/src/gui/EditWidgetProperties.cpp @@ -17,6 +17,7 @@ #include "EditWidgetProperties.h" #include "ui_EditWidgetProperties.h" +#include "MessageBox.h" EditWidgetProperties::EditWidgetProperties(QWidget* parent) : QWidget(parent) @@ -25,8 +26,11 @@ EditWidgetProperties::EditWidgetProperties(QWidget* parent) , m_customDataModel(new QStandardItemModel(this)) { m_ui->setupUi(this); + m_ui->removeCustomDataButton->setEnabled(false); m_ui->customDataTable->setModel(m_customDataModel); + connect(m_ui->customDataTable->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), + SLOT(toggleRemoveButton(QItemSelection))); connect(m_ui->removeCustomDataButton, SIGNAL(clicked()), SLOT(removeSelectedPluginData())); } @@ -51,7 +55,7 @@ void EditWidgetProperties::setCustomData(const CustomData* customData) Q_ASSERT(customData); m_customData->copyDataFrom(customData); - this->updateModel(); + updateModel(); } const CustomData* EditWidgetProperties::customData() const @@ -61,6 +65,14 @@ const CustomData* EditWidgetProperties::customData() const void EditWidgetProperties::removeSelectedPluginData() { + if (QMessageBox::Yes != MessageBox::question(this, + tr("Delete plugin data?"), + tr("Do you really want to delete the selected plugin data?\n" + "This may cause the affected plugins to malfunction."), + QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel)) { + return; + } + const QItemSelectionModel* itemSelectionModel = m_ui->customDataTable->selectionModel(); if (itemSelectionModel) { for (const QModelIndex& index : itemSelectionModel->selectedRows(0)) { @@ -71,12 +83,22 @@ void EditWidgetProperties::removeSelectedPluginData() } } +void EditWidgetProperties::toggleRemoveButton(const QItemSelection& selected) +{ + m_ui->removeCustomDataButton->setEnabled(!selected.isEmpty()); +} + void EditWidgetProperties::updateModel() { m_customDataModel->clear(); + + m_customDataModel->setHorizontalHeaderLabels({tr("Key"), tr("Value")}); + for (const QString& key : m_customData->keys()) { m_customDataModel->appendRow(QList() << new QStandardItem(key) << new QStandardItem(m_customData->value(key))); } + + m_ui->removeCustomDataButton->setEnabled(false); } diff --git a/src/gui/EditWidgetProperties.h b/src/gui/EditWidgetProperties.h index 94f70a12c1..a1fd198d78 100644 --- a/src/gui/EditWidgetProperties.h +++ b/src/gui/EditWidgetProperties.h @@ -19,6 +19,7 @@ #define KEEPASSX_EDITWIDGETPROPERTIES_H #include +#include #include #include @@ -45,6 +46,7 @@ class EditWidgetProperties : public QWidget private slots: void removeSelectedPluginData(); + void toggleRemoveButton(const QItemSelection& selected); private: void updateModel(); diff --git a/src/gui/EditWidgetProperties.ui b/src/gui/EditWidgetProperties.ui index 269134f654..f975626619 100644 --- a/src/gui/EditWidgetProperties.ui +++ b/src/gui/EditWidgetProperties.ui @@ -112,8 +112,8 @@ QAbstractItemView::SelectRows - - false + + 200 true