[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41669] trunk/blender: - operator presets now work in the 3D view as well as the file selector.

Campbell Barton ideasman42 at gmail.com
Tue Nov 8 17:59:06 CET 2011


Revision: 41669
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41669
Author:   campbellbarton
Date:     2011-11-08 16:59:06 +0000 (Tue, 08 Nov 2011)
Log Message:
-----------
- operator presets now work in the 3D view as well as the file selector.

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.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_operators/add_mesh_torus.py
    trunk/blender/release/scripts/startup/bl_operators/presets.py
    trunk/blender/source/blender/editors/screen/screen_context.c

Modified: trunk/blender/release/scripts/startup/bl_operators/add_mesh_torus.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/add_mesh_torus.py	2011-11-08 16:53:59 UTC (rev 41668)
+++ trunk/blender/release/scripts/startup/bl_operators/add_mesh_torus.py	2011-11-08 16:59:06 UTC (rev 41669)
@@ -86,7 +86,7 @@
     '''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",

Modified: trunk/blender/release/scripts/startup/bl_operators/presets.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/presets.py	2011-11-08 16:53:59 UTC (rev 41668)
+++ trunk/blender/release/scripts/startup/bl_operators/presets.py	2011-11-08 16:59:06 UTC (rev 41669)
@@ -395,9 +395,8 @@
             options={'HIDDEN'},
             )
 
-    # XXX, not ideal
     preset_defines = [
-        "op = bpy.context.space_data.operator",
+        "op = bpy.context.active_operator",
     ]
 
     @property
@@ -432,7 +431,7 @@
     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

Modified: trunk/blender/source/blender/editors/screen/screen_context.c
===================================================================
--- trunk/blender/source/blender/editors/screen/screen_context.c	2011-11-08 16:53:59 UTC (rev 41668)
+++ trunk/blender/source/blender/editors/screen/screen_context.c	2011-11-08 16:59:06 UTC (rev 41669)
@@ -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 @@
 	"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 @@
 			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 */
 	}




More information about the Bf-blender-cvs mailing list