diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-11-29 10:13:01 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-11-29 10:17:08 +0300 |
commit | 301e3155ecbeed7c1a362a56edcb252a124a810e (patch) | |
tree | 98c75622676b0173d5c65c3d10b6fd6c203bb9da /source/blender | |
parent | 8055871e5be765958d11160e086c0e5589fefe48 (diff) |
Keymap: cycle space-subtypes on successive presses
Some space types are exposed as multiple space types,
previously the key binding to set the space type would use the last
used space-type.
Now pressing the key again cycles to the next space sub-type.
Without this, shortcut display is confusing since some space types share
a key. Keymap display will need to be updated to support this.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/screen/screen_ops.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index b2a86be2c3c..5df6b0c6f19 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -89,6 +89,7 @@ #include "RNA_access.h" #include "RNA_define.h" +#include "RNA_enum_types.h" #include "UI_interface.h" #include "UI_resources.h" @@ -4640,6 +4641,69 @@ static void SCREEN_OT_region_blend(wmOperatorType *ot) /** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Space Type Set or Cycle Operator + * \{ */ + +static int space_type_set_or_cycle_exec(bContext *C, wmOperator *op) +{ + const int space_type = RNA_enum_get(op->ptr, "space_type"); + + PointerRNA ptr; + ScrArea *sa = CTX_wm_area(C); + RNA_pointer_create((ID *)CTX_wm_screen(C), &RNA_Area, sa, &ptr); + PropertyRNA *prop_type = RNA_struct_find_property(&ptr, "type"); + PropertyRNA *prop_ui_type = RNA_struct_find_property(&ptr, "ui_type"); + + if (sa->spacetype != space_type) { + /* Set the type. */ + RNA_property_enum_set(&ptr, prop_type, space_type); + RNA_property_update(C, &ptr, prop_type); + } + else { + /* Types match, cycle the subtype. */ + const int space_type_ui = RNA_property_enum_get(&ptr, prop_ui_type); + const EnumPropertyItem *item; + int item_len; + bool free; + RNA_property_enum_items(C, &ptr, prop_ui_type, &item, &item_len, &free); + int index = RNA_enum_from_value(item, space_type_ui); + for (int i = 1; i < item_len; i++) { + const EnumPropertyItem *item_test = &item[(index + i) % item_len]; + if ((item_test->value >> 16) == space_type) { + RNA_property_enum_set(&ptr, prop_ui_type, item_test->value); + RNA_property_update(C, &ptr, prop_ui_type); + break; + } + } + if (free) { + MEM_freeN((void *)item); + } + } + + return OPERATOR_FINISHED; +} + +static void SCREEN_OT_space_type_set_or_cycle(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Cycle Space Type Set"; + ot->description = "Set the space type or cycle subtype"; + ot->idname = "SCREEN_OT_space_type_set_or_cycle"; + + /* api callbacks */ + ot->exec = space_type_set_or_cycle_exec; + ot->poll = ED_operator_areaactive; + + ot->flag = 0; + + RNA_def_enum(ot->srna, "space_type", rna_enum_space_type_items, SPACE_EMPTY, "Type", ""); +} + +/** \} */ + + /* -------------------------------------------------------------------- */ /** \name Space Context Cycle Operator * \{ */ @@ -4821,6 +4885,7 @@ void ED_operatortypes_screen(void) WM_operatortype_append(SCREEN_OT_userpref_show); WM_operatortype_append(SCREEN_OT_drivers_editor_show); WM_operatortype_append(SCREEN_OT_region_blend); + WM_operatortype_append(SCREEN_OT_space_type_set_or_cycle); WM_operatortype_append(SCREEN_OT_space_context_cycle); WM_operatortype_append(SCREEN_OT_workspace_cycle); |