UI: support operator enums in Quick Favorites #107616

Merged
Philipp Oeser merged 5 commits from lichtwerk/blender:59244 into main 2023-05-08 09:14:52 +02:00
Member

Part of #59244

This was heavily requested since there are a lot of usages of
operator_menu_enum around in our UI [and these menus all cannot be
added to Quick Favorites atm.].

The following are just a small sample from the 3D viewport menus (object
mode), but there are many more.

  • Object
    -- Set Origin
    -- Relations >> Make Local...
    -- Convert To
  • Add
    -- Grease Pencil
    -- Empty
    -- Force Field
    -- Collection Instance
  • Select
    -- Select All by Type
    -- Select Grouped
    -- Select Linked
  • ...

So in order to make this work, USER_MENU_TYPE_OPERATOR /
bUserMenuItem_Op is reused (but extended with a string to the property
in question). (Alternatively, a new type could be introduced -- but
would share most of the code with the type that is reused in this
patch).

Depending on being used with an enum or not [detected by the usage of
that new string] we then either call uiItemFullO_ptr or
uiItemMenuEnumFullO_ptr in screen_user_menu_draw.

NOTE: we now also let uiItemMenuEnumFullO_ptr take an optional
wmOperatorCallContext (would always take the layouts root context
otherwise which is not what we always want for Quick Favorite menus).

NOTE: support for other enums (property enums such as pivot point or
transform orientations) will follow in a separate commit (building upon
6a13b6324b, trying to solve the way these draw as menus)

NOTE: opening User Preferences with such "new" Quick Favorites even
works (just not drawn with a menu)

Part of #59244 This was heavily requested since there are a lot of usages of `operator_menu_enum` around in our UI [and these menus all cannot be added to Quick Favorites atm.]. The following are just a small sample from the 3D viewport menus (object mode), but there are many more. - Object -- Set Origin -- Relations >> Make Local... -- Convert To - Add -- Grease Pencil -- Empty -- Force Field -- Collection Instance - Select -- Select All by Type -- Select Grouped -- Select Linked - ... So in order to make this work, `USER_MENU_TYPE_OPERATOR` / `bUserMenuItem_Op` is reused (but extended with a string to the property in question). (Alternatively, a new type could be introduced -- but would share most of the code with the type that is reused in this patch). Depending on being used with an enum or not [detected by the usage of that new string] we then either call `uiItemFullO_ptr` or `uiItemMenuEnumFullO_ptr` in `screen_user_menu_draw`. NOTE: we now also let `uiItemMenuEnumFullO_ptr` take an optional `wmOperatorCallContext` (would always take the layouts root context otherwise which is not what we always want for Quick Favorite menus). NOTE: support for other enums (property enums such as pivot point or transform orientations) will follow in a separate commit (building upon 6a13b6324b42, trying to solve the way these draw as menus) NOTE: opening User Preferences with such "new" Quick Favorites even works (just not drawn with a menu)
Philipp Oeser added 1 commit 2023-05-04 14:04:20 +02:00
54bb07d750 UI: support operator enums in Quick Favorites
Part of #59244

This was heavily requested since there are a lot of usages of
`operator_menu_enum` around in our UI [and these menus all cannot be
added to Quick Favorites atm.].

The following are just a small sample from the 3D viewport menus (object
mode), but there are many more.

- Object
-- Set Origin
-- Relations >> Make Local...
-- Convert To
- Add
-- Grease Pencil
-- Empty
-- Force Field
-- Collection Instance
- Select
-- Select All by Type
-- Select Grouped
-- Select Linked
- ...

So in order to make this work, `USER_MENU_TYPE_OPERATOR` /
`bUserMenuItem_Op` is reused (but extended with a string to the property
in question). (Alternatively, a new type could be introduced -- but
would share most of the code with the type that is reused in this
patch).

Depending on being used with an enum or not [detected by the usage of
that new string] we then either call `uiItemFullO_ptr` or
`uiItemMenuEnumFullO_ptr` in `screen_user_menu_draw`.

NOTE: we now also let `uiItemMenuEnumFullO_ptr` take an optional
`wmOperatorCallContext` (would always take the layouts root context
otherwise which is not what we always want for Quick Favorite menus).

NOTE: support for other enums (property enums such as pivot point or
transform orientations) will follow in a separate commit (building upon
6a13b6324b, trying to solve the way these draw as menus)

NOTE: opening User Preferences with such "new" Quick Favorites even
works (just not drawn with a menu)
Philipp Oeser added this to the User Interface project 2023-05-04 14:04:30 +02:00
Philipp Oeser requested review from Campbell Barton 2023-05-04 14:04:43 +02:00
Philipp Oeser requested review from Harley Acheson 2023-05-04 14:04:59 +02:00
Philipp Oeser requested review from Pablo Vazquez 2023-05-04 14:05:09 +02:00
Campbell Barton requested changes 2023-05-04 16:40:49 +02:00
@ -612,6 +612,7 @@ struct bUserMenu *ED_screen_user_menu_ensure(struct bContext *C);
struct bUserMenuItem_Op *ED_screen_user_menu_item_find_operator(struct ListBase *lb,
const struct wmOperatorType *ot,
struct IDProperty *prop,
const char *op_prop_enum,

Doc-string should note this is to be an empty string when not set.

Doc-string should note this is to be an empty string when not set.
Author
Member

done

done
@ -2896,6 +2896,7 @@ void uiItemMenuEnumFullO_ptr(uiLayout *layout,
const char *propname,
const char *name,
int icon,
wmOperatorCallContext *opcontext,

Doc-string should note this is optional (use the layout's when NULL). Realize doc-strings in wide use here, but it's the kind of thing that's useful to include.

Doc-string should note this is optional (use the layout's when NULL). _Realize doc-strings in wide use here, but it's the kind of thing that's useful to include._
Author
Member

removed this completely, seems the roots opcontext is already fine here?

removed this completely, seems the roots opcontext is already fine here?
@ -3555,6 +3555,7 @@ void uiItemMenuEnumFullO_ptr(uiLayout *layout,
const char *propname,
const char *name,
int icon,
wmOperatorCallContext *opcontext,

This is awkward, it's using a pointer, for an enum, for the purpose of being able to set it to NULL and use the layout's value.

It's more straightforward to set the context temporarily in layout->root->opcontext using accessor functions as is done in Python. While setting temporary values isn't so nice - this is only done from screen_user_menu_draw and avoids an additional non-obvious argument everywhere else.

This is awkward, it's using a pointer, for an enum, for the purpose of being able to set it to NULL and use the layout's value. It's more straightforward to set the context temporarily in ` layout->root->opcontext` using accessor functions as is done in Python. While setting temporary values isn't so nice - this is only done from `screen_user_menu_draw` and avoids an additional non-obvious argument everywhere else.
Author
Member

see above

see above
@ -199,2 +206,3 @@
static void screen_user_menu_draw(const bContext *C, Menu *menu)
static void screen_user_menu_draw(const bContext *C_const, Menu *menu)
{
bContext *C = (bContext *)C_const;

Committed update to make uiItemMenuEnumFullO_ptr take a const context.

Committed update to make `uiItemMenuEnumFullO_ptr` take a `const` context.
Author
Member

thx, updated to this

thx, updated to this
@ -228,0 +237,4 @@
}
else {
uiItemMenuEnumFullO_ptr(menu->layout,
C,

It's possible we want to support assigning additional properties even with op_prop_enum set, although I'm not sure if there are practical cases which would use this of hand.

Nevertheless, it's worth adding a comment that umi_op->prop could be used to set other properties but it's currently unsupported.

It's possible we want to support assigning additional properties even with `op_prop_enum` set, although I'm not sure if there are practical cases which would use this of hand. Nevertheless, it's worth adding a comment that `umi_op->prop` could be used to set other properties but it's currently unsupported.
Author
Member

added that comment

added that comment
Member

This is great!

Not sure what needs to be approved from my side, since this wouldn't really change the looks of things other than add menus to the Quick Favorites list? If so I think it's okay. The Quick Favorites is not like pie menus where it is preferred to have speed so we avoid enums.

Thanks for working on this.

This is great! Not sure what needs to be approved from my side, since this wouldn't really change the looks of things other than add menus to the Quick Favorites list? If so I think it's okay. The Quick Favorites is not like pie menus where it is preferred to have speed so we avoid enums. Thanks for working on this.
Philipp Oeser added 4 commits 2023-05-05 12:20:56 +02:00
15593ab0d5 remove awkward setting of layouts opcontext
In fact, it looks like the root layout opcontext is fine already, so rely
on existing behavior of `uiItemMenuEnumFullO_ptr`.
Member

Works as advertised, which is awesomely!

Works as advertised, which is awesomely!
Harley Acheson approved these changes 2023-05-07 20:59:17 +02:00
Campbell Barton approved these changes 2023-05-08 01:54:36 +02:00
Philipp Oeser merged commit 04d50f4b23 into main 2023-05-08 09:14:52 +02:00
Philipp Oeser deleted branch 59244 2023-05-08 09:14:53 +02:00
Howard Trickey referenced this issue from a commit 2023-05-29 02:51:41 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
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, Assets & 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
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
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
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
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 project
No Assignees
4 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#107616
No description provided.