godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Add `Window`'s built-in `close confirmation` dialog #6832

Open me2beats opened 1 year ago

me2beats commented 1 year ago

Describe the project you are working on

a plugin that uses Window nodes

Describe the problem or limitation you are having in your project

this is related to https://github.com/godotengine/godot-proposals/issues/6830 Sometimes when the user presses a Window close button, we want to popup a confirmation dialog like do you really want to close the window?. The problem is you have to create it every time yourself The idea is Window can have built-in logic to open such close confirmation dialog when needed

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Adding Window's built-in close confirmation dialog logic would solve the problem and would save some time especially when prototyping UIs.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

add Window boolean property show close confirmation or ask then closing (not a native speaker so the naming may be clearer). It is false by default (this is how it works now)

If it is true that it waits for close_requested signal and then close confirmation dialog is opened with title like confirm closing This dialog has 2 buttons like close and cancel. If you press cancel then this dialog is closes and the window does not close. Then you press close then you confirm that the Window will be closed.

Also maybe there should be some new signals like close confirmation accepted and close confirmation cancelled; properties like close_confirmation_title, close_confirmation_text, close_confirmation_accept_text, close_confirmation_cancel_text.

The close confirmation dialog theming support also would be useful

Also I think it is better to create the close confirmation dialog each time when close_requested is emitted instead of having it as a child all the time, for performance reasons.

If this enhancement will not be used often, can it be worked around with a few lines of script?

It can but it is not so handy

Is there a reason why this should be core and not an add-on in the asset library?

A plugin can add custom node but again it is not so handy

Calinou commented 1 year ago

I think this is too game/app-specific to be done in an universal manner. In polished apps, close confirmation dialogs often need to have some kind of custom behavior such as listing files that have unsaved changes:

image

The ConfirmationDialog node already makes creating these dialogs fairly straightforward, so I don't see much point in adding more stuff to Window which is already a heavyweight class.

me2beats commented 1 year ago

I think this is too game/app-specific to be done in an universal manner. In polished apps, close confirmation dialogs often need to have some kind of custom behavior such as listing files that have unsaved changes:

True but there are still many cases where you need to just ask to close. Godot itself often only asks if the user really want to close the window, for example the editor window