diff --git a/src/gui/EditWidget.cpp b/src/gui/EditWidget.cpp index 65c6306e1..7950fe987 100644 --- a/src/gui/EditWidget.cpp +++ b/src/gui/EditWidget.cpp @@ -97,18 +97,14 @@ QLabel* EditWidget::headlineLabel() return m_ui->headerLabel; } -void EditWidget::setReadOnly(bool readOnly) +void EditWidget::setReadOnly(bool readOnly, bool applyEnabled) { m_readOnly = readOnly; if (readOnly) { m_ui->buttonBox->setStandardButtons(QDialogButtonBox::Close); - } - else { - m_ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply); - // Find and connect the apply button - QPushButton* applyButton = m_ui->buttonBox->button(QDialogButtonBox::Apply); - connect(applyButton, SIGNAL(clicked()), SIGNAL(apply())); + } else { + setupButtons(applyEnabled); } } @@ -117,6 +113,19 @@ bool EditWidget::readOnly() const return m_readOnly; } +void EditWidget::setupButtons(bool applyEnabled) +{ + if (applyEnabled) { + m_ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply); + // Find and connect the apply button + QPushButton* applyButton = m_ui->buttonBox->button(QDialogButtonBox::Apply); + connect(applyButton, SIGNAL(clicked()), SIGNAL(apply())); + } else { + m_ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + disconnect(SIGNAL(apply())); + } +} + void EditWidget::showMessage(const QString& text, MessageWidget::MessageType type) { m_ui->messageWidget->setCloseButtonVisible(false); diff --git a/src/gui/EditWidget.h b/src/gui/EditWidget.h index 442365b96..8b89f1f8f 100644 --- a/src/gui/EditWidget.h +++ b/src/gui/EditWidget.h @@ -45,7 +45,7 @@ public: void setCurrentPage(int index); void setHeadline(const QString& text); QLabel* headlineLabel(); - void setReadOnly(bool readOnly); + void setReadOnly(bool readOnly, bool applyEnabled = true); bool readOnly() const; signals: @@ -58,6 +58,8 @@ protected slots: void hideMessage(); private: + void setupButtons(bool applyEnabled); + const QScopedPointer m_ui; bool m_readOnly; diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index 6fd65c1a3..2e03eb3c8 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -597,7 +597,8 @@ void EditEntryWidget::loadEntry(Entry* entry, bool create, bool history, const Q } setForms(entry); - setReadOnly(m_history); + // Disable apply button if creating new entry (#2191) + setReadOnly(m_history, !m_create); setCurrentPage(0); setPageHidden(m_historyWidget, m_history || m_entry->historyItems().count() < 1); @@ -802,7 +803,6 @@ void EditEntryWidget::acceptEntry() { if (commitEntry()) { clear(); - hideMessage(); emit editFinished(true); } } diff --git a/src/gui/group/EditGroupWidget.cpp b/src/gui/group/EditGroupWidget.cpp index 9ffd31a5e..46b0ae5bc 100644 --- a/src/gui/group/EditGroupWidget.cpp +++ b/src/gui/group/EditGroupWidget.cpp @@ -61,8 +61,7 @@ void EditGroupWidget::loadGroup(Group* group, bool create, Database* database) if (create) { setHeadline(tr("Add group")); - } - else { + } else { setHeadline(tr("Edit group")); } @@ -99,6 +98,9 @@ void EditGroupWidget::loadGroup(Group* group, bool create, Database* database) setCurrentPage(0); + // Disable apply button if creating new group + setReadOnly(false, create); + m_mainUi->editName->setFocus(); } diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index 54203c284..d0b530028 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -477,6 +477,9 @@ void TestGui::testAddEntry() QTest::keyClicks(passwordRepeatEdit, "something 2"); QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton); +/* All apply tests disabled due to data loss workaround + * that disables apply button on new entry creation + * // Add entry "something 3" using the apply button then click ok QTest::mouseClick(entryNewWidget, Qt::LeftButton); QTest::keyClicks(titleEdit, "something 3"); @@ -488,6 +491,7 @@ void TestGui::testAddEntry() QTest::keyClicks(titleEdit, "something 4"); QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Apply), Qt::LeftButton); QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Cancel), Qt::LeftButton); +*/ // Add entry "something 5" but click cancel button (does NOT add entry) QTest::mouseClick(entryNewWidget, Qt::LeftButton); @@ -496,8 +500,8 @@ void TestGui::testAddEntry() QApplication::processEvents(); - // Confirm that 5 entries now exist - QTRY_COMPARE(entryView->model()->rowCount(), 5); + // Confirm entry count + QTRY_COMPARE(entryView->model()->rowCount(), 3); } void TestGui::testPasswordEntryEntropy()