mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-07-26 00:05:34 -04: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
5 changed files with 31 additions and 14 deletions
|
@ -97,18 +97,14 @@ QLabel* EditWidget::headlineLabel()
|
||||||
return m_ui->headerLabel;
|
return m_ui->headerLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditWidget::setReadOnly(bool readOnly)
|
void EditWidget::setReadOnly(bool readOnly, bool applyEnabled)
|
||||||
{
|
{
|
||||||
m_readOnly = readOnly;
|
m_readOnly = readOnly;
|
||||||
|
|
||||||
if (readOnly) {
|
if (readOnly) {
|
||||||
m_ui->buttonBox->setStandardButtons(QDialogButtonBox::Close);
|
m_ui->buttonBox->setStandardButtons(QDialogButtonBox::Close);
|
||||||
}
|
} else {
|
||||||
else {
|
setupButtons(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()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,6 +113,19 @@ bool EditWidget::readOnly() const
|
||||||
return m_readOnly;
|
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)
|
void EditWidget::showMessage(const QString& text, MessageWidget::MessageType type)
|
||||||
{
|
{
|
||||||
m_ui->messageWidget->setCloseButtonVisible(false);
|
m_ui->messageWidget->setCloseButtonVisible(false);
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
void setCurrentPage(int index);
|
void setCurrentPage(int index);
|
||||||
void setHeadline(const QString& text);
|
void setHeadline(const QString& text);
|
||||||
QLabel* headlineLabel();
|
QLabel* headlineLabel();
|
||||||
void setReadOnly(bool readOnly);
|
void setReadOnly(bool readOnly, bool applyEnabled = true);
|
||||||
bool readOnly() const;
|
bool readOnly() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -58,6 +58,8 @@ protected slots:
|
||||||
void hideMessage();
|
void hideMessage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setupButtons(bool applyEnabled);
|
||||||
|
|
||||||
const QScopedPointer<Ui::EditWidget> m_ui;
|
const QScopedPointer<Ui::EditWidget> m_ui;
|
||||||
bool m_readOnly;
|
bool m_readOnly;
|
||||||
|
|
||||||
|
|
|
@ -597,7 +597,8 @@ void EditEntryWidget::loadEntry(Entry* entry, bool create, bool history, const Q
|
||||||
}
|
}
|
||||||
|
|
||||||
setForms(entry);
|
setForms(entry);
|
||||||
setReadOnly(m_history);
|
// Disable apply button if creating new entry (#2191)
|
||||||
|
setReadOnly(m_history, !m_create);
|
||||||
|
|
||||||
setCurrentPage(0);
|
setCurrentPage(0);
|
||||||
setPageHidden(m_historyWidget, m_history || m_entry->historyItems().count() < 1);
|
setPageHidden(m_historyWidget, m_history || m_entry->historyItems().count() < 1);
|
||||||
|
@ -802,7 +803,6 @@ void EditEntryWidget::acceptEntry()
|
||||||
{
|
{
|
||||||
if (commitEntry()) {
|
if (commitEntry()) {
|
||||||
clear();
|
clear();
|
||||||
hideMessage();
|
|
||||||
emit editFinished(true);
|
emit editFinished(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,8 +61,7 @@ void EditGroupWidget::loadGroup(Group* group, bool create, Database* database)
|
||||||
|
|
||||||
if (create) {
|
if (create) {
|
||||||
setHeadline(tr("Add group"));
|
setHeadline(tr("Add group"));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
setHeadline(tr("Edit group"));
|
setHeadline(tr("Edit group"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +98,9 @@ void EditGroupWidget::loadGroup(Group* group, bool create, Database* database)
|
||||||
|
|
||||||
setCurrentPage(0);
|
setCurrentPage(0);
|
||||||
|
|
||||||
|
// Disable apply button if creating new group
|
||||||
|
setReadOnly(false, create);
|
||||||
|
|
||||||
m_mainUi->editName->setFocus();
|
m_mainUi->editName->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -477,6 +477,9 @@ void TestGui::testAddEntry()
|
||||||
QTest::keyClicks(passwordRepeatEdit, "something 2");
|
QTest::keyClicks(passwordRepeatEdit, "something 2");
|
||||||
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
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
|
// Add entry "something 3" using the apply button then click ok
|
||||||
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
||||||
QTest::keyClicks(titleEdit, "something 3");
|
QTest::keyClicks(titleEdit, "something 3");
|
||||||
|
@ -488,6 +491,7 @@ void TestGui::testAddEntry()
|
||||||
QTest::keyClicks(titleEdit, "something 4");
|
QTest::keyClicks(titleEdit, "something 4");
|
||||||
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Apply), Qt::LeftButton);
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Apply), Qt::LeftButton);
|
||||||
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Cancel), Qt::LeftButton);
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Cancel), Qt::LeftButton);
|
||||||
|
*/
|
||||||
|
|
||||||
// Add entry "something 5" but click cancel button (does NOT add entry)
|
// Add entry "something 5" but click cancel button (does NOT add entry)
|
||||||
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
||||||
|
@ -496,8 +500,8 @@ void TestGui::testAddEntry()
|
||||||
|
|
||||||
QApplication::processEvents();
|
QApplication::processEvents();
|
||||||
|
|
||||||
// Confirm that 5 entries now exist
|
// Confirm entry count
|
||||||
QTRY_COMPARE(entryView->model()->rowCount(), 5);
|
QTRY_COMPARE(entryView->model()->rowCount(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestGui::testPasswordEntryEntropy()
|
void TestGui::testPasswordEntryEntropy()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue