Correct issues with apply button
* Don't show apply button when creating new entries or groups (Fix #2191) * Don't mark entry/group as dirty when first creating a new one (prevents unnecessary discard dialog on cancel) * Properly enable/disable apply button when changes are made to entries and groups * Don't show discard change warning when locking database unless their are actual changes made NOTE: Extra pages in the group edit widget are not watched for changes yet. Requires a major refactor.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "core/Metadata.h"
|
||||
#include "gui/EditWidgetIcons.h"
|
||||
#include "gui/EditWidgetProperties.h"
|
||||
#include "gui/MessageBox.h"
|
||||
|
||||
#if defined(WITH_XC_KEESHARE)
|
||||
#include "keeshare/group/EditGroupPageKeeShare.h"
|
||||
@@ -46,6 +47,11 @@ public:
|
||||
editPage->assign(widget);
|
||||
}
|
||||
|
||||
QWidget* getWidget()
|
||||
{
|
||||
return widget;
|
||||
}
|
||||
|
||||
private:
|
||||
QSharedPointer<IEditGroupPage> editPage;
|
||||
QWidget* widget;
|
||||
@@ -85,18 +91,38 @@ EditGroupWidget::EditGroupWidget(QWidget* parent)
|
||||
// clang-format on
|
||||
|
||||
connect(m_editGroupWidgetIcons, SIGNAL(messageEditEntryDismiss()), SLOT(hideMessage()));
|
||||
|
||||
setupModifiedTracking();
|
||||
}
|
||||
|
||||
EditGroupWidget::~EditGroupWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void EditGroupWidget::setupModifiedTracking()
|
||||
{
|
||||
// Group tab
|
||||
connect(m_mainUi->editName, SIGNAL(textChanged(QString)), SLOT(setModified()));
|
||||
connect(m_mainUi->editNotes, SIGNAL(textChanged()), SLOT(setModified()));
|
||||
connect(m_mainUi->expireCheck, SIGNAL(stateChanged(int)), SLOT(setModified()));
|
||||
connect(m_mainUi->expireDatePicker, SIGNAL(dateTimeChanged(QDateTime)), SLOT(setModified()));
|
||||
connect(m_mainUi->searchComboBox, SIGNAL(currentIndexChanged(int)), SLOT(setModified()));
|
||||
connect(m_mainUi->autotypeComboBox, SIGNAL(currentIndexChanged(int)), SLOT(setModified()));
|
||||
connect(m_mainUi->autoTypeSequenceInherit, SIGNAL(toggled(bool)), SLOT(setModified()));
|
||||
connect(m_mainUi->autoTypeSequenceCustomRadio, SIGNAL(toggled(bool)), SLOT(setModified()));
|
||||
connect(m_mainUi->autoTypeSequenceCustomEdit, SIGNAL(textChanged(QString)), SLOT(setModified()));
|
||||
|
||||
// Icon tab
|
||||
connect(m_editGroupWidgetIcons, SIGNAL(widgetUpdated()), SLOT(setModified()));
|
||||
}
|
||||
|
||||
void EditGroupWidget::loadGroup(Group* group, bool create, const QSharedPointer<Database>& database)
|
||||
{
|
||||
m_group = group;
|
||||
m_db = database;
|
||||
|
||||
m_temporaryGroup.reset(group->clone(Entry::CloneNoFlags, Group::CloneNoFlags));
|
||||
connect(m_temporaryGroup->customData(), SIGNAL(customDataModified()), SLOT(setModified()));
|
||||
|
||||
if (create) {
|
||||
setHeadline(tr("Add group"));
|
||||
@@ -139,6 +165,11 @@ void EditGroupWidget::loadGroup(Group* group, bool create, const QSharedPointer<
|
||||
setCurrentPage(0);
|
||||
|
||||
m_mainUi->editName->setFocus();
|
||||
|
||||
// Force the user to Save/Discard new groups
|
||||
showApplyButton(!create);
|
||||
|
||||
setModified(false);
|
||||
}
|
||||
|
||||
void EditGroupWidget::save()
|
||||
@@ -180,6 +211,8 @@ void EditGroupWidget::apply()
|
||||
|
||||
// Icons add/remove are applied globally outside the transaction!
|
||||
m_group->copyDataFrom(m_temporaryGroup.data());
|
||||
|
||||
setModified(false);
|
||||
}
|
||||
|
||||
void EditGroupWidget::cancel()
|
||||
@@ -188,6 +221,18 @@ void EditGroupWidget::cancel()
|
||||
m_group->setIcon(Entry::DefaultIconNumber);
|
||||
}
|
||||
|
||||
if (isModified()) {
|
||||
auto result = MessageBox::question(this,
|
||||
QString(),
|
||||
tr("Entry has unsaved changes"),
|
||||
MessageBox::Cancel | MessageBox::Save | MessageBox::Discard,
|
||||
MessageBox::Cancel);
|
||||
if (result == MessageBox::Save) {
|
||||
apply();
|
||||
setModified(false);
|
||||
}
|
||||
}
|
||||
|
||||
clear();
|
||||
emit editFinished(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user