Commit: bb6af17799d9a7807e48d880fd49af52896d3502
Author: Julian Eisel
Date:   Wed Sep 21 14:43:11 2016 +0200
Branches: master
https://developer.blender.org/rBbb6af17799d9a7807e48d880fd49af52896d3502

Make space context cycling a proper screen-level OP

This is really more of a screen level operation, UI-level is more like button 
handling etc.

===================================================================

M       source/blender/editors/include/UI_interface.h
M       source/blender/editors/interface/interface_ops.c
M       source/blender/editors/screen/screen_ops.c

===================================================================

diff --git a/source/blender/editors/include/UI_interface.h 
b/source/blender/editors/include/UI_interface.h
index ad4066f..a7dfa4b 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1021,12 +1021,6 @@ void ED_keymap_ui(struct wmKeyConfig *keyconf);
 void UI_drop_color_copy(struct wmDrag *drag, struct wmDropBox *drop);
 int UI_drop_color_poll(struct bContext *C, struct wmDrag *drag, const struct 
wmEvent *event);
 
-/* UI_OT_space_context_cycle direction */
-enum {
-       SPACE_CONTEXT_CYCLE_PREV,
-       SPACE_CONTEXT_CYCLE_NEXT,
-};
-
 bool UI_context_copy_to_selected_list(
         struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop,
         struct ListBase *r_lb, bool *r_use_path_from_id, char **r_path);
diff --git a/source/blender/editors/interface/interface_ops.c 
b/source/blender/editors/interface/interface_ops.c
index 43b48db..fe41046 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -1082,79 +1082,6 @@ static void UI_OT_drop_color(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "gamma", 0, "Gamma Corrected", "The source 
color is gamma corrected ");
 }
 
-/* ------------------------------------------------------------------------- */
-
-static EnumPropertyItem space_context_cycle_direction[] = {
-       {SPACE_CONTEXT_CYCLE_PREV, "PREV", 0, "Previous", ""},
-       {SPACE_CONTEXT_CYCLE_NEXT, "NEXT", 0, "Next", ""},
-       {0, NULL, 0, NULL, NULL}
-};
-
-static int space_context_cycle_poll(bContext *C)
-{
-       ScrArea *sa = CTX_wm_area(C);
-       return ELEM(sa->spacetype, SPACE_BUTS, SPACE_USERPREF);
-}
-
-/**
- * Helper to get the correct RNA pointer/property pair for changing
- * the display context of active space type in \sa.
- */
-static void context_cycle_prop_get(
-        bScreen *screen, const ScrArea *sa,
-        PointerRNA *r_ptr, PropertyRNA **r_prop)
-{
-       const char *propname;
-
-       switch (sa->spacetype) {
-               case SPACE_BUTS:
-                       RNA_pointer_create(&screen->id, &RNA_SpaceProperties, 
sa->spacedata.first, r_ptr);
-                       propname = "context";
-                       break;
-               case SPACE_USERPREF:
-                       RNA_pointer_create(NULL, &RNA_UserPreferences, &U, 
r_ptr);
-                       propname = "active_section";
-                       break;
-       }
-
-       *r_prop = RNA_struct_find_property(r_ptr, propname);
-}
-
-static int space_context_cycle_invoke(bContext *C, wmOperator *op, const 
wmEvent *UNUSED(event))
-{
-       const int direction = RNA_enum_get(op->ptr, "direction");
-
-       PointerRNA ptr;
-       PropertyRNA *prop;
-       context_cycle_prop_get(CTX_wm_screen(C), CTX_wm_area(C), &ptr, &prop);
-
-       const int old_context = RNA_property_enum_get(&ptr, prop);
-       const int new_context = RNA_property_enum_step(
-                         C, &ptr, prop, old_context,
-                         direction == SPACE_CONTEXT_CYCLE_PREV ? -1 : 1);
-       RNA_property_enum_set(&ptr, prop, new_context);
-       RNA_property_update(C, &ptr, prop);
-
-       return OPERATOR_FINISHED;
-}
-
-static void UI_OT_space_context_cycle(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name = "Cycle Space Context";
-       ot->description = "Cycle through the editor context by activating the 
next/previous one";
-       ot->idname = "UI_OT_space_context_cycle";
-
-       /* api callbacks */
-       ot->invoke = space_context_cycle_invoke;
-       ot->poll = space_context_cycle_poll;
-
-       ot->flag = 0;
-
-       RNA_def_enum(ot->srna, "direction", space_context_cycle_direction, 
SPACE_CONTEXT_CYCLE_NEXT, "Direction",
-                    "Direction to cycle through");
-}
-
 
 /* ********************************************************* */
 /* Registration */
@@ -1174,7 +1101,6 @@ void ED_operatortypes_ui(void)
        WM_operatortype_append(UI_OT_edittranslation_init);
 #endif
        WM_operatortype_append(UI_OT_reloadtranslation);
-       WM_operatortype_append(UI_OT_space_context_cycle);
 
        /* external */
        WM_operatortype_append(UI_OT_eyedropper_color);
diff --git a/source/blender/editors/screen/screen_ops.c 
b/source/blender/editors/screen/screen_ops.c
index e446194..7612dbc 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -4174,6 +4174,85 @@ static void SCREEN_OT_region_blend(wmOperatorType *ot)
        /* properties */
 }
 
+/* ******************** space context cycling operator ******************** */
+
+/* SCREEN_OT_space_context_cycle direction */
+enum {
+       SPACE_CONTEXT_CYCLE_PREV,
+       SPACE_CONTEXT_CYCLE_NEXT,
+};
+
+static EnumPropertyItem space_context_cycle_direction[] = {
+       {SPACE_CONTEXT_CYCLE_PREV, "PREV", 0, "Previous", ""},
+       {SPACE_CONTEXT_CYCLE_NEXT, "NEXT", 0, "Next", ""},
+       {0, NULL, 0, NULL, NULL}
+};
+
+static int space_context_cycle_poll(bContext *C)
+{
+       ScrArea *sa = CTX_wm_area(C);
+       return ELEM(sa->spacetype, SPACE_BUTS, SPACE_USERPREF);
+}
+
+/**
+ * Helper to get the correct RNA pointer/property pair for changing
+ * the display context of active space type in \sa.
+ */
+static void context_cycle_prop_get(
+        bScreen *screen, const ScrArea *sa,
+        PointerRNA *r_ptr, PropertyRNA **r_prop)
+{
+       const char *propname;
+
+       switch (sa->spacetype) {
+               case SPACE_BUTS:
+                       RNA_pointer_create(&screen->id, &RNA_SpaceProperties, 
sa->spacedata.first, r_ptr);
+                       propname = "context";
+                       break;
+               case SPACE_USERPREF:
+                       RNA_pointer_create(NULL, &RNA_UserPreferences, &U, 
r_ptr);
+                       propname = "active_section";
+                       break;
+       }
+
+       *r_prop = RNA_struct_find_property(r_ptr, propname);
+}
+
+static int space_context_cycle_invoke(bContext *C, wmOperator *op, const 
wmEvent *UNUSED(event))
+{
+       const int direction = RNA_enum_get(op->ptr, "direction");
+
+       PointerRNA ptr;
+       PropertyRNA *prop;
+       context_cycle_prop_get(CTX_wm_screen(C), CTX_wm_area(C), &ptr, &prop);
+
+       const int old_context = RNA_property_enum_get(&ptr, prop);
+       const int new_context = RNA_property_enum_step(
+                         C, &ptr, prop, old_context,
+                         direction == SPACE_CONTEXT_CYCLE_PREV ? -1 : 1);
+       RNA_property_enum_set(&ptr, prop, new_context);
+       RNA_property_update(C, &ptr, prop);
+
+       return OPERATOR_FINISHED;
+}
+
+static void SCREEN_OT_space_context_cycle(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Cycle Space Context";
+       ot->description = "Cycle through the editor context by activating the 
next/previous one";
+       ot->idname = "SCREEN_OT_space_context_cycle";
+
+       /* api callbacks */
+       ot->invoke = space_context_cycle_invoke;
+       ot->poll = space_context_cycle_poll;
+
+       ot->flag = 0;
+
+       RNA_def_enum(ot->srna, "direction", space_context_cycle_direction, 
SPACE_CONTEXT_CYCLE_NEXT, "Direction",
+                    "Direction to cycle through");
+}
+
 
 /* ****************  Assigning operatortypes to global list, adding handlers 
**************** */
 
@@ -4209,6 +4288,7 @@ void ED_operatortypes_screen(void)
        WM_operatortype_append(SCREEN_OT_screencast);
        WM_operatortype_append(SCREEN_OT_userpref_show);
        WM_operatortype_append(SCREEN_OT_region_blend);
+       WM_operatortype_append(SCREEN_OT_space_context_cycle);
        
        /*frame changes*/
        WM_operatortype_append(SCREEN_OT_frame_offset);
@@ -4332,10 +4412,9 @@ void ED_keymap_screen(wmKeyConfig *keyconf)
        WM_keymap_add_item(keymap, "SCREEN_OT_screenshot", F3KEY, KM_PRESS, 
KM_CTRL, 0);
        WM_keymap_add_item(keymap, "SCREEN_OT_screencast", F3KEY, KM_PRESS, 
KM_ALT, 0);
 
-       /* UI */
-       kmi = WM_keymap_add_item(keymap, "UI_OT_space_context_cycle", TABKEY, 
KM_PRESS, KM_CTRL, 0);
+       kmi = WM_keymap_add_item(keymap, "SCREEN_OT_space_context_cycle", 
TABKEY, KM_PRESS, KM_CTRL, 0);
        RNA_enum_set(kmi->ptr, "direction", SPACE_CONTEXT_CYCLE_NEXT);
-       kmi = WM_keymap_add_item(keymap, "UI_OT_space_context_cycle", TABKEY, 
KM_PRESS, KM_CTRL | KM_SHIFT, 0);
+       kmi = WM_keymap_add_item(keymap, "SCREEN_OT_space_context_cycle", 
TABKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
        RNA_enum_set(kmi->ptr, "direction", SPACE_CONTEXT_CYCLE_PREV);
 
        /* tests */

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to