Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

Add support for optional "Cancel" confirmation on wizard #712

Closed
SackCastellon opened this issue Apr 29, 2018 · 2 comments
Closed

Add support for optional "Cancel" confirmation on wizard #712

SackCastellon opened this issue Apr 29, 2018 · 2 comments

Comments

@SackCastellon
Copy link
Contributor

SackCastellon commented Apr 29, 2018

Problem

I think that support for a custom cancellation confirmation in the wizard is something necessary. Imagine you have a 5+ pages wizard and you filled all the information, but on the last page, you misclick the cancel button and you lose all the data you inputted. You would wish you were asked if you were sure.

Proposed solution

Add a isCanceled property and a onCancel() function:

/**
 * Specifies whether the wizard can be safely closed
 */
var isCanceled = true

/**
 * This function is called when the cancel button is pressed, but before closing the wizard.
 */
open fun onCancel() {
    isCanceled = true
}

The onCancel() function would be called before closing the wizard. Then the wizard will only be closed if isCanceled is true (Wizard.kt#L164-L167)

button(type = ButtonBar.ButtonData.CANCEL_CLOSE) {
    textProperty().bind(cancelButtonTextProperty)
    action {
        onCancel()
        if (isCanceled)
            close()
    }
}

Example

override fun onCancel() {
    confirmation(
        "Confirmation",
        "Do you really want to lose your progess?",
        ButtonType.YES, ButtonType.NO
    ) {
        isCanceled = it == ButtonType.YES
    }
}

Compatibility

This change should not break any existing code because by default the wizard is closed on pressing the cancel button as always.

edvin pushed a commit that referenced this issue Apr 30, 2018
@edvin
Copy link
Owner

edvin commented Apr 30, 2018

Good suggestion, thanks. I've implemented it slightly different. When the cancel button is clicked, the onCancel function is called. The default implementation calls cancel(), which closes the wizard. In the future the cancel function might do more things to clean up on cancel.

You would now override onCancel like this:

override fun onCancel() {
    confirm("Confirm cancel", "Do you really want to loose your progress?") {
        cancel()
    }
}

edvin pushed a commit that referenced this issue Apr 30, 2018
#712 Improvement: `onCancel` callback when pressing the X (close) button
@SackCastellon
Copy link
Contributor Author

Perfect, good work 👌

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants