Page MenuHome

Add ability to create a keyboard shortcut for more mode settings.
ClosedPublic

Authored by Sebastian Parborg (zeddb) on May 6 2019, 1:03 PM.

Details

Summary

This is a request from the animators at BI.

Now you can easily assign shortcuts from "X-Axis Mirror" and other boolean settings in the UI.

However this patch needs more work as I'm unsure if this is the correct way to implement this.
I tried to assign operators to the buttons in question, but it seemed like this was not intended to happen and I ran into quite a few issues. So I opted for this simple approach instead.

Note that this patch introduces a memleak as there doesn't seem to be a easy way to free up the new shortcutData after the menu has been created.
(But I'm guessing I might be missing something obvious)

Diff Detail

Repository
rB Blender

Event Timeline

Brecht Van Lommel (brecht) requested changes to this revision.May 8 2019, 8:18 PM
Brecht Van Lommel (brecht) added inline comments.
source/blender/editors/interface/interface_context_menu.c
923–946

Most of this work should be done in the callback. If all the data comes from the button, you can just pass a pointer to the button to the callback, not need to do all this computation in advanced and deal with allocation/freeing.

985

You can use UI_but_funcN_set which will free the argument with MEM_freeN. Though it will do nothing beyond that if the struct contains things that need to be freed.

This revision now requires changes to proceed.May 8 2019, 8:18 PM
Sebastian Parborg (zeddb) updated this revision to Diff 15233.EditedMay 9 2019, 3:08 PM

I've rewritten the patch. (I overthought things as usual...)

Now there are no new custom data types and it doesn't leak memory anymore.

I also seems to work as intended in the tests I did, so that is a bonus. ;)

Brecht Van Lommel (brecht) requested changes to this revision.May 9 2019, 4:37 PM
Brecht Van Lommel (brecht) added inline comments.
source/blender/editors/interface/interface_context_menu.c
63–84

This duplicates code that is also in ui_but_user_menu_find and ui_but_user_menu_add. We should have a shared function that returns final_data_path as a string, and use it for all 3 cases.

110

WM_OT_context_toggle only works for booleans, so we should detect if but->rnaprop is a boolean. For enums we can use WM_OT_context_menu_enum.

For other data types this does not make as much sense, we could do nothing for those.

143–150

This code is duplicated a few times and becomes more complicated if we check for property types. It should be moved into a function.

This revision now requires changes to proceed.May 9 2019, 4:37 PM
Sebastian Parborg (zeddb) marked 2 inline comments as done.May 9 2019, 4:57 PM
Sebastian Parborg (zeddb) marked 3 inline comments as done.May 9 2019, 5:16 PM
Sebastian Parborg (zeddb) updated this revision to Diff 15239.

Moved out the prop and idname creation to a function and also added support for enums!

  • Isolate logic for supported buttons and freeing.
  • More description function names.
Harbormaster completed remote builds in B3558: Diff 15250.
This revision is now accepted and ready to land.May 10 2019, 11:39 AM
This revision was automatically updated to reflect the committed changes.