Skip to content

Grey out Apply button when there are no changes#1702

Merged
phoerious merged 2 commits intokeepassxreboot:developfrom
dwilches:hotfix/1313-grey-out-apply-button
Mar 31, 2018
Merged

Grey out Apply button when there are no changes#1702
phoerious merged 2 commits intokeepassxreboot:developfrom
dwilches:hotfix/1313-grey-out-apply-button

Conversation

@dwilches
Copy link
Copy Markdown
Contributor

@dwilches dwilches commented Mar 11, 2018

When the user clicks on the Apply button, it will get disabled. When changes are made, it's enabled again.

Description

  • Whenever the Apply button is pressed, and if the save was successful, then the Apply button is disabled.
  • Each subwidget used by EditEntryWidget has now a signal called widgetUpdated that is emitted when the widgets' internal content changes. The EditEntryWidget subscribes to that signal to know when to enable the Apply button (by calling entryUpdated()).
  • There are some views that are not isolated in their own widgets (m_advancedUi, for example) so in those cases I invoked entryUpdated() directly whenever I detected an update:
    • some updates occur directly in a Qt widget like when editing the text of a QLineItem, so in that case I connected the widget's signals directly to the entryUpdated() slot.
    • some updates occur in EditEntryWidget, so in those cases the invocation to entryUpdated() is made as soon as the change is detected (for example when the user has confirmed an action in a dialog).

Motivation and context

Resolves #1313
Resolves #1181

How has this been tested?

I tested it manually, not sure if I need to write an automated test.

Types of changes

  • ✅ New feature (non-breaking change which adds functionality)

Checklist:

  • ✅ I have read the CONTRIBUTING document. [REQUIRED]
  • ✅ My code follows the code style of this project. [REQUIRED]
  • ✅ All new and existing tests passed. [REQUIRED]
  • ✅ I have compiled and verified my code with -DWITH_ASAN=ON. [REQUIRED]

@droidmonkey droidmonkey added this to the v2.4.0 milestone Mar 11, 2018
@droidmonkey
Copy link
Copy Markdown
Member

droidmonkey commented Mar 11, 2018

The base functionality of #1181 (warn when unsaved changes exist) should be ported into this PR. I like this implementation better for detecting when something is changed.

@phoerious
Copy link
Copy Markdown
Member

You can block signals for trivial updates. The button shouldn't be enabled for non-modifying changes.

@dwilches
Copy link
Copy Markdown
Contributor Author

@droidmonkey What do you mean by "porting functionality"? Should I create a merge commit between my branch and frostasm's branch request-confirmation-to-discard-unsaved-changes and then make my PR include that merge commit?
Or should I copy&paste code from frostasm's branch into a new commmit in my PR?

@dwilches
Copy link
Copy Markdown
Contributor Author

@phoerious Is it ok to use classes from Qt 5.3? Asking because of QSignalBlocker.
Otherwise I would use QObject::blockSignals which is available also in Qt 5.2

@droidmonkey
Copy link
Copy Markdown
Member

You could copy paste the relevant dialog code or implement your own variant. Definitely don't merge the branches.

@dwilches dwilches force-pushed the hotfix/1313-grey-out-apply-button branch 3 times, most recently from 64f78ef to 7e927e0 Compare March 17, 2018 22:18
@dwilches
Copy link
Copy Markdown
Contributor Author

@droidmonkey @phoerious Changes implemented. This PR is now composed of 3 commits:

  1. Solves Grey out Apply button once clicked by user #1313 but missing signal blocking
  2. Implement signal blocking
  3. Shows confirmation dialog before closing unsaved entries (Unsaved changes in the entry view silently get discarded if escape is pressed #1181)

Let me know what you think!

@dwilches dwilches force-pushed the hotfix/1313-grey-out-apply-button branch from 7e927e0 to 8c3c9aa Compare March 17, 2018 22:27
@dwilches
Copy link
Copy Markdown
Contributor Author

BTW: Amended the commits to change to my personal email.

Copy link
Copy Markdown
Member

@phoerious phoerious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few style nitpicks, rest looks good to me.

connect(m_ui->defaultIconsRadio, SIGNAL(toggled(bool)), this, SIGNAL(widgetUpdated()));
connect(m_ui->defaultIconsRadio, SIGNAL(toggled(bool)), this, SIGNAL(widgetUpdated()));
connect(m_ui->defaultIconsView->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No space before (please change that everywhere)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the newline? So should it be like:

    connect(m_ui->defaultIconsView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
            this, SIGNAL(widgetUpdated()));

or like this:

    connect(m_ui->defaultIconsView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SIGNAL(widgetUpdated()));

#ifdef WITH_XC_SSHAGENT
// SSH Agent tab
if (config()->get("SSHAgent", false).toBool())
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No space before {

}

if (!m_saved)
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

}
}

void EditEntryWidget::setUnsavedChanges(bool anyUnsaved)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call the parameter hasUnsaved

@phoerious
Copy link
Copy Markdown
Member

I think ultimately we should change the button state based on the actual entry data, not based on widget edits. But for now it's okay IMHO.

@phoerious
Copy link
Copy Markdown
Member

Hmm. The changes seem to hang the GUI tests. Please check what's wrong there. I would assume it's not finishing, because it can't click the button or so.

@phoerious
Copy link
Copy Markdown
Member

phoerious commented Mar 17, 2018

I restarted the builds. Second rounds seems to go through, but it's quite slow. One build with tests takes 5-6 minutes now instead of 2.

@dwilches
Copy link
Copy Markdown
Contributor Author

@phoerious Pushed the format and space changes (and added a comment as I'm not sure I got one of your comments right). About the tests, I could run make test with no issue. The compilation is slow though when using -DWITH_ASAN, but could the changes on this PR be affecting something related to test/compilation speed?

@dwilches
Copy link
Copy Markdown
Contributor Author

Just pushed another commit for a problem I noticed a moment ago. Do you use squash&merge or you want me to squash my commits in my branch before merging the PR?

@droidmonkey
Copy link
Copy Markdown
Member

I would do a merge commit for this since there are multiple fixes.

@dwilches
Copy link
Copy Markdown
Contributor Author

dwilches commented Mar 18, 2018

Ok, if it's ok for you, I'd like to squash some of the commits in my branch to clean a bit the story of the repository when the PR gets merged, instead of 5 commits I can leave 2 commits, one per fix.

@droidmonkey
Copy link
Copy Markdown
Member

Yah you can squash the intermediate ones

@dwilches dwilches force-pushed the hotfix/1313-grey-out-apply-button branch from eeeb60c to dbfc6eb Compare March 18, 2018 02:30
@dwilches
Copy link
Copy Markdown
Contributor Author

Done 👍

@phoerious
Copy link
Copy Markdown
Member

phoerious commented Mar 18, 2018

I meant no space before &. Github swallowed my unescaped ampersand.

Compile and run tests with -DWITH_GUI_TESTS=ON. They don't finish on TC.

@dwilches
Copy link
Copy Markdown
Contributor Author

I found two problems:

  1. Some times the "Entry has been modified" dialog popups up and hangs the test because it keeps waiting for input. I'll solve that one in a moment. It's strange it only fails some times, will look into that.
  2. I found another test that fails every time, but it also fails with a fresh clone in the master branch:
FAIL!  : TestGui::testDeleteEntry() Compared values are not the same
   Actual   (entryView->selectionModel()->selectedRows().size()): 1
   Expected (2)                                                 : 2
   Loc: [/home/dwilches/Repos/tmp/keepassxc/tests/gui/TestGui.cpp(807)]

Not sure if it fails for you too or it's because I'm in Ubuntu+KDE Plasma (the test fails when clicking an entry, and then pressing Ctrl + clicking another entry, then expects 2 entries to be selected, but finds only 1 is selected).

@droidmonkey
Copy link
Copy Markdown
Member

@dwilches dwilches force-pushed the hotfix/1313-grey-out-apply-button branch 2 times, most recently from 938c5b6 to 301649f Compare March 18, 2018 21:26
@dwilches
Copy link
Copy Markdown
Contributor Author

dwilches commented Mar 18, 2018

Fixed test that had broken by the new functionality. And fixed the extra spaces before the & too.

About the other test that fails, should be something in my machine then. If I follow by myself the same steps that the test case does, they work as expected.

@phoerious
Copy link
Copy Markdown
Member

phoerious commented Mar 18, 2018

I stopped the old tests. They were jamming the queue.
A blocking dialog was pretty much what I suspected.

@dwilches
Copy link
Copy Markdown
Contributor Author

Noticed this PR status says "Changes requested", but there is no pending change, so letting you know in case there is still something needed.

@phoerious
Copy link
Copy Markdown
Member

No, you just need to rebase to the current branch head.

Resolves keepassxreboot#1313

What this commit does:
* Whenever the Apply button is pressed, and if the save was successful, then the Apply button is disabled.
* Each subwidget used by EditEntryWidget has now a signal called `widgetUpdated` that is emitted when the widgets' internal content changes. The EditEntryWidget subscribes to that signal to know when to enable the Apply button (by calling `entryUpdated()`).
* There are some views that are not isolated in their own widgets (`m_advancedUi`, for example) so in those cases I invoked `entryUpdated()` directly whenever I detected an update:
  * some updates occur directly in a Qt widget like when editing the text of a QLineItem, so in that case I connected the widget's signals directly to the `entryUpdated()` slot.
  * some updates occur in EditEntryWidget, so in those cases the invocation to `entryUpdated()` is made as soon as the change is detected (for example when the user has confirmed an action in a dialog).

A known problem: there are some situations when the Apply button will get enabled even if there are no changes, this is because the app changes the value of a field by itself so it's considered an update (for example, clicking on the "Reveal" button changes the text shown in a text field).
The solution to this can be a bit complicated: disabling temporarily the `entryUpdated()` whenever the app is going to do an action with such side-effects.
So I preferred to let the Apply button get enabled in those cases.
@dwilches dwilches force-pushed the hotfix/1313-grey-out-apply-button branch from 301649f to 240939c Compare March 30, 2018 01:38
@dwilches
Copy link
Copy Markdown
Contributor Author

@phoerious Done, rebased on top of the current develop branch.

@phoerious
Copy link
Copy Markdown
Member

Thanks!

@phoerious phoerious merged commit bd654ea into keepassxreboot:develop Mar 31, 2018
@TheZ3ro TheZ3ro mentioned this pull request Mar 31, 2018
@haridsv
Copy link
Copy Markdown

haridsv commented Mar 30, 2019

Just checking... this change is not yet in the latest release, right?

@droidmonkey
Copy link
Copy Markdown
Member

It is, but I think its broken because as soon as you open an entry it determines there are unsaved changes.

@haridsv
Copy link
Copy Markdown

haridsv commented Apr 1, 2019

Thanks @droidmonkey! I didn't realize there is a newer version until I saw your response. I got the new version via Brew and now I can see that the Apply button is working as expected. I don't see the erroneous behavior that you are describing. Perhaps it is a corner case bug? Is it happening for you for all entries?

@droidmonkey
Copy link
Copy Markdown
Member

droidmonkey commented Apr 1, 2019

The case I am describing is if you try to lock the database with the entry edit view open, it asks if you want to save the entry before closing instead of properly determining if it is "dirty" or not. I thought that applied to the apply button as well, but it does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants