Fix #28202: (only) modifying keymap item properties did not save properly, the
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 4 Oct 2011 13:24:48 +0000 (13:24 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 4 Oct 2011 13:24:48 +0000 (13:24 +0000)
update signal for this was missing. Problem is that the operator properties
RNA update callback doesn't know the associated keymap item, worked around it
with UI template now.

release/scripts/startup/bl_ui/space_userpref_keymap.py
source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface_templates.c
source/blender/makesrna/intern/rna_ui_api.c

index 25f9550..c2e3a14 100644 (file)
@@ -121,19 +121,6 @@ class InputKeyMapPanel:
                 for entry in children:
                     self.draw_entry(display_keymaps, entry, col, level + 1)
 
-    @staticmethod
-    def draw_kmi_properties(box, properties, title=None):
-        box.separator()
-        if title:
-            box.label(text=title)
-        flow = box.column_flow(columns=2)
-        for pname, value in properties.bl_rna.properties.items():
-            if pname != "rna_type" and not properties.is_property_hidden(pname):
-                if isinstance(value, OperatorProperties):
-                    InputKeyMapPanel.draw_kmi_properties(box, value, title=pname)
-                else:
-                    flow.prop(properties, pname)
-
     def draw_kmi(self, display_keymaps, kc, km, kmi, layout, level):
         map_type = kmi.map_type
 
@@ -218,9 +205,7 @@ class InputKeyMapPanel:
                 subrow.prop(kmi, "key_modifier", text="", event=True)
 
             # Operator properties
-            props = kmi.properties
-            if props is not None:
-                InputKeyMapPanel.draw_kmi_properties(box, props)
+            box.template_keymap_item_properties(kmi)
 
             # Modal key maps attached to this operator
             if not km.is_modal:
index a5781ab..a064978 100644 (file)
@@ -749,6 +749,7 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C);
 void uiTemplateEditModeSelection(uiLayout *layout, struct bContext *C);
 void uiTemplateTextureImage(uiLayout *layout, struct bContext *C, struct Tex *tex);
 void uiTemplateReportsBanner(uiLayout *layout, struct bContext *C);
+void uiTemplateKeymapItemProperties(uiLayout *layout, struct PointerRNA *ptr);
 
 void uiTemplateList(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname, struct PointerRNA *activeptr, const char *activeprop, int rows, int maxrows, int type);
 
index ff6ef41..4dcdeab 100644 (file)
@@ -2542,3 +2542,61 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
        uiDefBut(block, LABEL, 0, report->message, UI_UNIT_X+10, 0, UI_UNIT_X+width, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "");
 }
 
+/********************************* Keymap *************************************/
+
+static void keymap_item_modified(bContext *UNUSED(C), void *kmi_p, void *UNUSED(unused))
+{
+       wmKeyMapItem *kmi= (wmKeyMapItem*)kmi_p;
+       WM_keyconfig_update_tag(NULL, kmi);
+}
+
+static void template_keymap_item_properties(uiLayout *layout, const char *title, PointerRNA *ptr)
+{
+       uiLayout *flow;
+
+       uiItemS(layout);
+
+       if(title)
+               uiItemL(layout, title, ICON_NONE);
+       
+       flow= uiLayoutColumnFlow(layout, 2, 0);
+
+       RNA_STRUCT_BEGIN(ptr, prop) {
+               int flag= RNA_property_flag(prop);
+
+               if(flag & PROP_HIDDEN)
+                       continue;
+
+               /* recurse for nested properties */
+               if(RNA_property_type(prop) == PROP_POINTER) {
+                       PointerRNA propptr= RNA_property_pointer_get(ptr, prop);
+                       const char *name= RNA_property_ui_name(prop);
+
+                       if(propptr.data && RNA_struct_is_a(propptr.type, &RNA_OperatorProperties)) {
+                               template_keymap_item_properties(layout, name, &propptr);
+                               continue;
+                       }
+               }
+
+               /* add property */
+               uiItemR(flow, ptr, RNA_property_identifier(prop), 0, NULL, ICON_NONE);
+       }
+       RNA_STRUCT_END;
+}
+
+void uiTemplateKeymapItemProperties(uiLayout *layout, PointerRNA *ptr)
+{
+       PointerRNA propptr= RNA_pointer_get(ptr, "properties");
+
+       if(propptr.data) {
+               uiBut *but= uiLayoutGetBlock(layout)->buttons.last;
+
+               template_keymap_item_properties(layout, NULL, &propptr);
+
+               /* attach callbacks to compensate for missing properties update,
+                  we don't know which keymap (item) is being modified there */
+               for(; but; but=but->next)
+                       uiButSetFunc(but, keymap_item_modified, ptr->data, NULL);
+       }
+}
+
index 85ad6b2..9e9e64a 100644 (file)
@@ -428,6 +428,10 @@ void RNA_api_ui_layout(StructRNA *srna)
        func= RNA_def_function(srna, "template_reports_banner", "uiTemplateReportsBanner");
        RNA_def_function_flag(func, FUNC_USE_CONTEXT);
 
+       func= RNA_def_function(srna, "template_keymap_item_properties", "uiTemplateKeymapItemProperties");
+       parm= RNA_def_pointer(func, "item", "KeyMapItem", "", "");
+       RNA_def_property_flag(parm, PROP_REQUIRED|PROP_RNAPTR|PROP_NEVER_NULL);
+
        func= RNA_def_function(srna, "introspect", "uiLayoutIntrospect");
        parm= RNA_def_string(func, "string", "", 1024*1024, "Descr", "DESCR");
        RNA_def_function_return(func, parm);