Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #72 (Prompt for confirmation before exiting dialog) #127

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

5hir0kur0
Copy link
Contributor

Description

Fixes #72.

The confirmation popup is shown in some cases where I don't think it's necessary. If the user adds occlusions, clicks on one of the buttons to create the cards and then closes the editor dialog they are
prompted for confirmation.
The only way I can think of to prevent this is to reset the svg-edit undo stack when the user clicks on the button, but I'm not sure if that's acceptable.
I changed the way the popup opens from directly calling the constructor to opening it via aqt.dialogs.open(...) so it behaves more like the other dialogs in Anki.
I used the askUser(...) function from aqt.utils to show the popup as you can see in the following screenshot:
image

Checklist:

  • I've read and understood the contribution guidelines
  • I've tested my changes against at least one of the following Anki builds:
    • Latest standard Anki 2.1 binary build [required for Anki-compatible 2.1 add-ons]
    • Latest alternative Anki 2.1 binary build
    • Latest Anki 2.0 binary build [required for Anki 2.0-compatible add-ons]
  • I've tested my changes on at least one of the following platforms:
    • Linux, version:
    • Windows, version:
    • macOS, version:
  • My changes potentially affect non-desktop platforms, of which I've tested:
    • AnkiMobile, version:
    • AnkiDroid, version:
    • AnkiWeb

Fixes glutanimate#72.
Note that this confirmation popup is shown in some cases where I don't
think it's necessary. If the user adds occlusions, clicks on one of the
buttons to create the cards and then closes the editor dialog they are
prompted for confirmation.
The only way I can think of to prevent this is to reset the svg-edit
undo stack when the user clicks on the button, but I'm not sure if
that's acceptable.
The condition for asking for confirmation is now simply that the element
on top of the undo stack is different from the one from the last time
when cards were created.
@5hir0kur0
Copy link
Contributor Author

I thought of a new way to check whether or not to ask for confirmation:
Compare the element on top of the undo stack to the element that was on top when the user clicked on the button to create the cards. If it's not the same (comparison by reference), ask for confirmation.

Now it should hopefully only ask for confirmation if there are actually changes that could be lost.

@glutanimate
Copy link
Owner

Thanks for yet another thoughtful contribution, @5hir0kur0! Same here as with the other PR, will revisit this as soon as SVG-Edit is upgraded.

@glutanimate glutanimate self-requested a review April 13, 2020 15:11
@glutanimate glutanimate self-assigned this Apr 13, 2020
@glutanimate glutanimate added the enhancement New feature or request label Apr 13, 2020
@glutanimate
Copy link
Owner

glutanimate commented Apr 9, 2022

Hey 5hir0kur0, just wanted to let you know that I pushed a slightly different solution in e1e10e7, primarily because I forgot about your PR here 😅. The solution there also takes field content into account, but doesn't take into consideration whether the current masks were already used to create cards (which I really love about your solution).

So leaving this PR open in order to hopefully merge both approaches in the next IO release (since 2.1.50 is at the doorstep and there's need to get the current release out quickly).

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prompt for confirmation before exiting dialog
2 participants