mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-24 14:59:44 -05:00
Disable apply button when creating new entry/group
* Workaround to prevent data loss if apply is hit but not OK or Cancel * Refactor required to fix this issue
This commit is contained in:
parent
d70a474bac
commit
3b1e15ea1a
@ -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);
|
||||
|
@ -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<Ui::EditWidget> m_ui;
|
||||
bool m_readOnly;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user