Proposed Custom Confirmation Dialogs #106691

Closed
opened 2023-04-07 21:52:17 +02:00 by Harley Acheson · 1 comment
Member

Although we try to avoid blocking operations there are times when we must pause in order to confirm with the user before proceeding with potentially harmful operations. For example when we load Defaults, Delete data, etc.

We currently have only two ways to allow an operator to have a user confirmation. One is using WM_operator_confirm which has no configurability. It simply opens a popup menu with "OK?" as the title and a single button that contains the operator name. It can contain no other information, like the operator description, and there is no obvious and visible way to cancel.

image

The other way is to create a bespoke popup dialog block like we have done for the dialog we get when closing Blender with unsaved changes. But that requires a lot of work. That "close" dialog requires about 280 lines of code.

I am proposing a third option. One that allows us to create a complex dialog containing multiple buttons and improved information in just a few lines of code.

This would involve adding an optional warning callback for operators. If not set calling WM_operator_confirm would result in behavior that is identical to today.

But if you create such a callback you are passed the context, operator, and a structure containing dialog information. Make changes to that passed struct and you change the contents, look, and behavior of the confirmation.

For the example above it could look like this:

static void save_homefile_warning(bContext * /*C*/, wmOperator * /*op*/, wmWarningDetails *warning)
{
  STRNCPY(warning->confirm_button, IFACE_("Save"));
  warning->size = WM_WARNING_SIZE_LARGE;
  warning->position = WM_WARNING_POSITION_CENTER;
}

The code above changes the "confirm" button to say "Save", shows it at a larger size, and in the center of the window. The contents are not changed here so it will just just use the operator's description:

image

But you can change the title, the content, the icon, the size, the behavior (like closing by moving your mouse away), position, and even if the "confirm" button should be red.

There is a PR that you can apply to test this proposal: #104670

Although we try to avoid blocking operations there are times when we must pause in order to confirm with the user before proceeding with potentially harmful operations. For example when we load Defaults, Delete data, etc. We currently have only two ways to allow an operator to have a user confirmation. One is using `WM_operator_confirm` which has no configurability. It simply opens a popup menu with "OK?" as the title and a single button that contains the operator name. It can contain no other information, like the operator description, and there is no obvious and visible way to cancel. ![image](/attachments/ce72c76e-daed-4bd1-be7c-a973e9f955cb) The other way is to create a bespoke popup dialog block like we have done for the dialog we get when closing Blender with unsaved changes. But that requires a lot of work. That "close" dialog requires about 280 lines of code. I am proposing a third option. One that allows us to create a complex dialog containing multiple buttons and improved information in just a few lines of code. This would involve adding an optional `warning` callback for operators. If not set calling `WM_operator_confirm` would result in behavior that is identical to today. But if you create such a callback you are passed the context, operator, and a structure containing dialog information. Make changes to that passed struct and you change the contents, look, and behavior of the confirmation. For the example above it could look like this: ``` static void save_homefile_warning(bContext * /*C*/, wmOperator * /*op*/, wmWarningDetails *warning) { STRNCPY(warning->confirm_button, IFACE_("Save")); warning->size = WM_WARNING_SIZE_LARGE; warning->position = WM_WARNING_POSITION_CENTER; } ``` The code above changes the "confirm" button to say "Save", shows it at a larger size, and in the center of the window. The contents are not changed here so it will just just use the operator's description: ![image](/attachments/706ed6bb-5c0b-4bee-b3aa-673df102aafb) But you can change the title, the content, the icon, the size, the behavior (like closing by moving your mouse away), position, and even if the "confirm" button should be red. There is a PR that you can apply to test this proposal: https://projects.blender.org/blender/blender/pulls/104670
Harley Acheson added the
Type
Design
label 2023-04-07 21:52:17 +02:00
Harley Acheson added this to the Module: User Interface project 2023-04-07 21:52:18 +02:00
Author
Member

Closing. Implemented in #104670, merged with commit f40d4e0bda

Closing. Implemented in #104670, merged with commit f40d4e0bda
Blender Bot added the
Status
Archived
label 2024-02-15 18:23:59 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Asset System
Module
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#106691
No description provided.