- operator presets now work in the 3D view as well as the file selector.
authorCampbell Barton <ideasman42@gmail.com>
Tue, 8 Nov 2011 16:59:06 +0000 (16:59 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 8 Nov 2011 16:59:06 +0000 (16:59 +0000)
to enable from python:
  bl_options = {'REGISTER', 'UNDO', 'PRESET'}

from C:
  ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_PRESET;

- added context member 'active_operator'
- enable this for 'Add Torus' for testing.

release/scripts/startup/bl_operators/add_mesh_torus.py
release/scripts/startup/bl_operators/presets.py
source/blender/editors/screen/screen_context.c

index 056b3478c2b49c17e1562c7df516b606d2c37c01..5b28cdf44aea1be25c502c3e5f676398dcc347cc 100644 (file)
@@ -86,7 +86,7 @@ class AddTorus(Operator):
     '''Add a torus mesh'''
     bl_idname = "mesh.primitive_torus_add"
     bl_label = "Add Torus"
-    bl_options = {'REGISTER', 'UNDO'}
+    bl_options = {'REGISTER', 'UNDO', 'PRESET'}
 
     major_radius = FloatProperty(
             name="Major Radius",
index ac19bab4c6686baeb7b2cc82e031c4ccbd04b755..dca96b302fbf2f3a1818d7bea7eb339845885449 100644 (file)
@@ -395,9 +395,8 @@ class AddPresetOperator(AddPresetBase, Operator):
             options={'HIDDEN'},
             )
 
-    # XXX, not ideal
     preset_defines = [
-        "op = bpy.context.space_data.operator",
+        "op = bpy.context.active_operator",
     ]
 
     @property
@@ -432,7 +431,7 @@ class WM_MT_operator_presets(Menu):
     bl_label = "Operator Presets"
 
     def draw(self, context):
-        self.operator = context.space_data.operator.bl_idname
+        self.operator = context.active_operator.bl_idname
         Menu.draw_preset(self, context)
 
     @property
index cb42cd786ed7dcca6b8e56bf68730cabafe2c09d..581c1e3597b87243b58b177ab510923f9d24004e 100644 (file)
@@ -35,6 +35,8 @@
 #include "DNA_sequence_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+#include "DNA_windowmanager_types.h"
 
 #include "BLI_utildefines.h"
 
@@ -50,6 +52,8 @@
 #include "ED_object.h"
 #include "ED_armature.h"
 
+#include "WM_api.h"
+
 #include "screen_intern.h"
 
 const char *screen_context_dir[] = {
@@ -62,6 +66,7 @@ const char *screen_context_dir[] = {
        "sculpt_object", "vertex_paint_object", "weight_paint_object",
        "image_paint_object", "particle_edit_object",
        "sequences", "selected_sequences", "selected_editable_sequences", /* sequencer */
+       "active_operator",
        NULL};
 
 int ed_screen_context(const bContext *C, const char *member, bContextDataResult *result)
@@ -387,6 +392,25 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
                        return 1;
                }
        }
+       else if(CTX_data_equals(member, "active_operator")) {
+               wmOperator *op= NULL;
+
+               SpaceFile *sfile= CTX_wm_space_file(C);
+               if(sfile) {
+                       op= sfile->op;
+               }
+               else {
+                       /* note, this checks poll, could be a problem, but this also
+                        * happens for the toolbar */
+                       op= WM_operator_last_redo(C);
+               }
+               /* TODO, get the operator from popup's */
+
+               if (op && op->ptr) {
+                       CTX_data_pointer_set(result, NULL, &RNA_Operator, op);
+                       return 1;
+               }
+       }
        else {
                return 0; /* not found */
        }