From 876a75b572ea045ce119047a74b6c21db663b001 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Wed, 3 Dec 2014 23:26:42 +0100 Subject: [PATCH] Disable attachment buttons when none is selected. --- src/gui/entry/EditEntryWidget.cpp | 13 ++++++++++++- src/gui/entry/EditEntryWidget.h | 1 + src/gui/entry/EditEntryWidgetAdvanced.ui | 9 +++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index fcb53d6a0..b7e2fdbe5 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -108,6 +108,8 @@ void EditEntryWidget::setupAdvanced() m_attachmentsModel->setEntryAttachments(m_entryAttachments); m_advancedUi->attachmentsView->setModel(m_attachmentsModel); + connect(m_advancedUi->attachmentsView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), + SLOT(updateAttachmentButtonsEnabled(QModelIndex))); connect(m_advancedUi->attachmentsView, SIGNAL(doubleClicked(QModelIndex)), SLOT(openAttachment(QModelIndex))); connect(m_advancedUi->saveAttachmentButton, SIGNAL(clicked()), SLOT(saveCurrentAttachment())); connect(m_advancedUi->openAttachmentButton, SIGNAL(clicked()), SLOT(openCurrentAttachment())); @@ -235,6 +237,15 @@ void EditEntryWidget::useExpiryPreset(QAction* action) m_mainUi->expireDatePicker->setDateTime(expiryDateTime); } +void EditEntryWidget::updateAttachmentButtonsEnabled(const QModelIndex& current) +{ + bool enable = current.isValid(); + + m_advancedUi->saveAttachmentButton->setEnabled(enable); + m_advancedUi->openAttachmentButton->setEnabled(enable); + m_advancedUi->removeAttachmentButton->setEnabled(enable && !m_history); +} + QString EditEntryWidget::entryTitle() const { if (m_entry) { @@ -284,7 +295,7 @@ void EditEntryWidget::setForms(const Entry* entry, bool restore) m_mainUi->tooglePasswordGeneratorButton->setChecked(false); m_mainUi->passwordGenerator->reset(); m_advancedUi->addAttachmentButton->setEnabled(!m_history); - m_advancedUi->removeAttachmentButton->setEnabled(!m_history); + updateAttachmentButtonsEnabled(m_advancedUi->attachmentsView->currentIndex()); m_advancedUi->addAttributeButton->setEnabled(!m_history); m_advancedUi->editAttributeButton->setEnabled(false); m_advancedUi->removeAttributeButton->setEnabled(false); diff --git a/src/gui/entry/EditEntryWidget.h b/src/gui/entry/EditEntryWidget.h index 903029872..144347629 100644 --- a/src/gui/entry/EditEntryWidget.h +++ b/src/gui/entry/EditEntryWidget.h @@ -93,6 +93,7 @@ private Q_SLOTS: void histEntryActivated(const QModelIndex& index); void updateHistoryButtons(const QModelIndex& current, const QModelIndex& previous); void useExpiryPreset(QAction* action); + void updateAttachmentButtonsEnabled(const QModelIndex& current); private: void setupMain(); diff --git a/src/gui/entry/EditEntryWidgetAdvanced.ui b/src/gui/entry/EditEntryWidgetAdvanced.ui index 551ea4afe..93e15260a 100644 --- a/src/gui/entry/EditEntryWidgetAdvanced.ui +++ b/src/gui/entry/EditEntryWidgetAdvanced.ui @@ -101,6 +101,9 @@ + + false + Remove @@ -108,6 +111,9 @@ + + false + Open @@ -115,6 +121,9 @@ + + false + Save