[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45051] trunk/blender/source/blender/ windowmanager: wm/operator code:
Campbell Barton
ideasman42 at gmail.com
Wed Mar 21 07:33:42 CET 2012
Revision: 45051
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45051
Author: campbellbarton
Date: 2012-03-21 06:33:31 +0000 (Wed, 21 Mar 2012)
Log Message:
-----------
wm/operator code:
Change operator previous settings initialization not to use the redo stack since this gets cleared and it means only redo operators can re-use last settings.
now this works for import/export as well.
Modified Paths:
--------------
trunk/blender/source/blender/windowmanager/WM_api.h
trunk/blender/source/blender/windowmanager/WM_types.h
trunk/blender/source/blender/windowmanager/intern/wm_event_system.c
trunk/blender/source/blender/windowmanager/intern/wm_operators.c
Modified: trunk/blender/source/blender/windowmanager/WM_api.h
===================================================================
--- trunk/blender/source/blender/windowmanager/WM_api.h 2012-03-21 05:33:37 UTC (rev 45050)
+++ trunk/blender/source/blender/windowmanager/WM_api.h 2012-03-21 06:33:31 UTC (rev 45051)
@@ -214,6 +214,9 @@
int WM_operator_check_ui_enabled(const struct bContext *C, const char *idname);
wmOperator *WM_operator_last_redo(const struct bContext *C);
+int WM_operator_last_properties_init(struct wmOperator *op);
+int WM_operator_last_properties_store(struct wmOperator *op);
+
/* MOVE THIS SOMEWHERE ELSE */
#define SEL_TOGGLE 0
#define SEL_SELECT 1
Modified: trunk/blender/source/blender/windowmanager/WM_types.h
===================================================================
--- trunk/blender/source/blender/windowmanager/WM_types.h 2012-03-21 05:33:37 UTC (rev 45050)
+++ trunk/blender/source/blender/windowmanager/WM_types.h 2012-03-21 06:33:31 UTC (rev 45051)
@@ -466,6 +466,9 @@
/* rna for properties */
struct StructRNA *srna;
+ /* previous settings - for initializing on re-use */
+ struct IDProperty *last_properties;
+
/* rna property to use for generic invoke functions.
* menus, enum search... etc */
PropertyRNA *prop;
Modified: trunk/blender/source/blender/windowmanager/intern/wm_event_system.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_event_system.c 2012-03-21 05:33:37 UTC (rev 45050)
+++ trunk/blender/source/blender/windowmanager/intern/wm_event_system.c 2012-03-21 06:33:31 UTC (rev 45051)
@@ -585,10 +585,17 @@
if (retval & (OPERATOR_FINISHED|OPERATOR_CANCELLED) && repeat == 0)
wm_operator_reports(C, op, retval, FALSE);
- if(retval & OPERATOR_FINISHED)
+ if(retval & OPERATOR_FINISHED) {
+ if (repeat) {
+ if (wm->op_undo_depth == 0) { /* not called by py script */
+ WM_operator_last_properties_store(op);
+ }
+ }
wm_operator_finished(C, op, repeat);
- else if(repeat==0)
+ }
+ else if(repeat==0) {
WM_operator_free(op);
+ }
return retval | OPERATOR_HANDLED;
@@ -738,19 +745,11 @@
}
}
-static int wm_operator_init_from_last(wmWindowManager *wm, wmOperator *op)
+int WM_operator_last_properties_init(wmOperator *op)
{
int change= FALSE;
- wmOperator *lastop;
- for(lastop= wm->operators.last; lastop; lastop= lastop->prev) {
- /* equality check is a bit paranoid but just in case */
- if((op != lastop) && (op->type == (lastop->type))) {
- break;
- }
- }
-
- if (lastop && op != lastop) {
+ if (op->type->last_properties) {
PropertyRNA *iterprop;
iterprop= RNA_struct_iterator_property(op->type->srna);
@@ -759,7 +758,7 @@
if((RNA_property_flag(prop) & PROP_SKIP_SAVE) == 0) {
if (!RNA_property_is_set(op->ptr, prop)) { /* don't override a setting already set */
const char *identifier= RNA_property_identifier(prop);
- IDProperty *idp_src= IDP_GetPropertyFromGroup(lastop->properties, identifier);
+ IDProperty *idp_src= IDP_GetPropertyFromGroup(op->type->last_properties, identifier);
if(idp_src) {
IDProperty *idp_dst = IDP_CopyProperty(idp_src);
@@ -779,6 +778,23 @@
return change;
}
+int WM_operator_last_properties_store(wmOperator *op)
+{
+ if (op->type->last_properties) {
+ IDP_FreeProperty(op->type->last_properties);
+ MEM_freeN(op->type->last_properties);
+ op->type->last_properties = NULL;
+ }
+
+ if (op->properties) {
+ op->type->last_properties = IDP_CopyProperty(op->properties);
+ return TRUE;
+ }
+ else {
+ return FALSE;
+ }
+}
+
static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, PointerRNA *properties, ReportList *reports, short poll_only)
{
wmWindowManager *wm= CTX_wm_manager(C);
@@ -792,8 +808,8 @@
wmOperator *op= wm_operator_create(wm, ot, properties, reports); /* if reports==NULL, theyll be initialized */
/* initialize setting from previous run */
- if(wm->op_undo_depth == 0 && (ot->flag & OPTYPE_REGISTER)) { /* not called by py script */
- wm_operator_init_from_last(wm, op);
+ if(wm->op_undo_depth == 0) { /* not called by py script */
+ WM_operator_last_properties_init(op);
}
if((G.f & G_DEBUG) && event && event->type!=MOUSEMOVE)
@@ -836,6 +852,9 @@
if(retval & OPERATOR_HANDLED)
; /* do nothing, wm_operator_exec() has been called somewhere */
else if(retval & OPERATOR_FINISHED) {
+ if (wm->op_undo_depth == 0) { /* not called by py script */
+ WM_operator_last_properties_store(op);
+ }
wm_operator_finished(C, op, 0);
}
else if(retval & OPERATOR_RUNNING_MODAL) {
@@ -1535,6 +1554,10 @@
CTX_wm_region_set(C, ar_prev);
}
+ if (retval & OPERATOR_FINISHED) {
+ WM_operator_last_properties_store(handler->op);
+ }
+
WM_operator_free(handler->op);
}
}
Modified: trunk/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_operators.c 2012-03-21 05:33:37 UTC (rev 45050)
+++ trunk/blender/source/blender/windowmanager/intern/wm_operators.c 2012-03-21 06:33:31 UTC (rev 45051)
@@ -449,7 +449,12 @@
return 0;
RNA_struct_free(&BLENDER_RNA, ot->srna);
-
+
+ if (ot->last_properties) {
+ IDP_FreeProperty(ot->last_properties);
+ MEM_freeN(ot->last_properties);
+ }
+
if(ot->macro.first)
wm_operatortype_free_macro(ot);
@@ -3618,6 +3623,11 @@
static void operatortype_ghash_free_cb(wmOperatorType *ot)
{
+ if (ot->last_properties) {
+ IDP_FreeProperty(ot->last_properties);
+ MEM_freeN(ot->last_properties);
+ }
+
if(ot->macro.first)
wm_operatortype_free_macro(ot);
More information about the Bf-blender-cvs
mailing list