Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTon Roosendaal <ton@blender.org>2009-07-29 21:56:38 +0400
committerTon Roosendaal <ton@blender.org>2009-07-29 21:56:38 +0400
commit4a1266baadf2251bf19ac8ebe15e334273b1f5a3 (patch)
treebfe8d1125ed33ab1732a718c7539d3be6081fa5f /source/blender/windowmanager
parentfa7a2091f1afb50e276730c5fdc0ff4b7141f327 (diff)
2.5
Operator goodies! --- Macro operators Operators now can consist of multiple operators. Such a macro operator is identical and behaves identical to other opererators. Macros can also be constructed of macros even! Currently only hardcoded macros are implemented, this to solve combined operators such as 'add duplicate' or 'extrude' (both want a transform appended). Usage is simple: - WM_operatortype_append_macro() : add new operatortype, name, flags - WM_operatortype_macro_define() : add existing operator to macro (Note: macro_define will also allow properties to be set, doesnt work right now) On converting the macro wmOperatorType to a real operator, it makes a list of all operators, and the standard macro callbacks (exec, invoke, modal, poll) just will use all. Important note; switching to a modal operator only works as last in the chain now! Macros implemented for duplicate, extrude and rip. Tool menu works fine for it, also the redo hotkey F4 works properly. --- Operator redo fix The operators use the undo system to switch back, but this could give errors if other actions added undo pushes (buttons, outliner). Now the redo for operator searches back for the correct undo level. This fixes issues with many redos. Note for brecht: removed the ED_undo_push for buttons... it was called on *every* button now, which is probably too much? For example, using the 'toolbar' redo also caused this...
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/WM_api.h4
-rw-r--r--source/blender/windowmanager/WM_types.h1
-rw-r--r--source/blender/windowmanager/intern/wm.c6
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c54
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c140
5 files changed, 200 insertions, 5 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 0d3ad96d8c3..f65e5b1b077 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -158,6 +158,10 @@ void WM_operatortype_append (void (*opfunc)(wmOperatorType*));
void WM_operatortype_append_ptr (void (*opfunc)(wmOperatorType*, void *), void *userdata);
int WM_operatortype_remove(const char *idname);
+wmOperatorType *WM_operatortype_append_macro(char *idname, char *name, int flag);
+wmOperatorTypeMacro *WM_operatortype_macro_define(wmOperatorType *ot, const char *idname);
+
+
int WM_operator_call (struct bContext *C, struct wmOperator *op);
int WM_operator_repeat (struct bContext *C, struct wmOperator *op);
int WM_operator_name_call (struct bContext *C, const char *opstring, int context, struct PointerRNA *properties);
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 3a646c5e799..a083d589d31 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -43,6 +43,7 @@ struct wmWindowManager;
#define OPTYPE_REGISTER 1 /* register operators in stack after finishing */
#define OPTYPE_UNDO 2 /* do undo push after after */
#define OPTYPE_BLOCKING 4 /* let blender grab all input from the WM (X11) */
+#define OPTYPE_MACRO 8
/* context to call operator in for WM_operator_name_call */
/* rna_ui.c contains EnumPropertyItem's of these, keep in sync */
diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c
index 863fb3ab4bd..c0ac7b06f5a 100644
--- a/source/blender/windowmanager/intern/wm.c
+++ b/source/blender/windowmanager/intern/wm.c
@@ -74,6 +74,12 @@ void WM_operator_free(wmOperator *op)
MEM_freeN(op->reports);
}
+ if(op->macro.first) {
+ wmOperator *opm;
+ for(opm= op->macro.first; opm; opm= opm->next)
+ WM_operator_free(opm);
+ }
+
MEM_freeN(op);
}
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index c75feafe623..33e8a392ba3 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -244,6 +244,23 @@ void wm_event_do_notifiers(bContext *C)
/* ********************* operators ******************* */
+static int wm_operator_poll(bContext *C, wmOperatorType *ot)
+{
+ wmOperatorTypeMacro *otmacro;
+
+ for(otmacro= ot->macro.first; otmacro; otmacro= otmacro->next) {
+ wmOperatorType *ot= WM_operatortype_find(otmacro->idname, 0);
+
+ if(0==wm_operator_poll(C, ot))
+ return 0;
+ }
+
+ if(ot->poll)
+ return ot->poll(C);
+
+ return 1;
+}
+
/* if repeat is true, it doesn't register again, nor does it free */
static int wm_operator_exec(bContext *C, wmOperator *op, int repeat)
{
@@ -252,7 +269,7 @@ static int wm_operator_exec(bContext *C, wmOperator *op, int repeat)
if(op==NULL || op->type==NULL)
return retval;
- if(op->type->poll && op->type->poll(C)==0)
+ if(0==wm_operator_poll(C, op->type))
return retval;
if(op->type->exec)
@@ -320,6 +337,26 @@ static wmOperator *wm_operator_create(wmWindowManager *wm, wmOperatorType *ot, P
BKE_reports_init(op->reports, RPT_STORE);
}
+ /* recursive filling of operator macro list */
+ if(ot->macro.first) {
+ static wmOperator *motherop= NULL;
+ wmOperatorTypeMacro *otmacro;
+
+ /* ensure all ops are in execution order in 1 list */
+ if(motherop==NULL)
+ motherop= op;
+
+ for(otmacro= ot->macro.first; otmacro; otmacro= otmacro->next) {
+ wmOperatorType *otm= WM_operatortype_find(otmacro->idname, 0);
+ wmOperator *opm= wm_operator_create(wm, otm, otmacro->ptr, NULL);
+
+ BLI_addtail(&motherop->macro, opm);
+ opm->opm= motherop; /* pointer to mom, for modal() */
+ }
+
+ motherop= NULL;
+ }
+
return op;
}
@@ -345,7 +382,7 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, P
wmWindowManager *wm= CTX_wm_manager(C);
int retval= OPERATOR_PASS_THROUGH;
- if(ot->poll==NULL || ot->poll(C)) {
+ if(wm_operator_poll(C, ot)) {
wmOperator *op= wm_operator_create(wm, ot, properties, NULL);
if((G.f & G_DEBUG) && event && event->type!=MOUSEMOVE)
@@ -809,7 +846,6 @@ static int wm_handler_fileselect_call(bContext *C, ListBase *handlers, wmEventHa
case EVT_FILESELECT_OPEN:
case EVT_FILESELECT_FULL_OPEN:
{
- short flag =0; short display =FILE_SHORTDISPLAY; short filter =0; short sort =FILE_SORT_ALPHA;
char *dir= NULL; char *path= RNA_string_get_alloc(handler->op->ptr, "filename", NULL, 0);
if(event->val==EVT_FILESELECT_OPEN)
@@ -1198,7 +1234,17 @@ void WM_event_set_handler_flag(wmEventHandler *handler, int flag)
wmEventHandler *WM_event_add_modal_handler(bContext *C, ListBase *handlers, wmOperator *op)
{
wmEventHandler *handler= MEM_callocN(sizeof(wmEventHandler), "event modal handler");
- handler->op= op;
+
+ /* operator was part of macro */
+ if(op->opm) {
+ /* give the mother macro to the handler */
+ handler->op= op->opm;
+ /* mother macro opm becomes the macro element */
+ handler->op->opm= op;
+ }
+ else
+ handler->op= op;
+
handler->op_area= CTX_wm_area(C); /* means frozen screen context for modal handlers! */
handler->op_region= CTX_wm_region(C);
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index e25c86ea2fd..2b7a18dc1cf 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -154,6 +154,134 @@ void WM_operatortype_append_ptr(void (*opfunc)(wmOperatorType*, void*), void *us
BLI_addtail(&global_ops, ot);
}
+/* ********************* macro operator ******************** */
+
+/* macro exec only runs exec calls */
+static int wm_macro_exec(bContext *C, wmOperator *op)
+{
+ wmOperator *opm;
+ int retval= OPERATOR_FINISHED;
+
+// printf("macro exec %s\n", op->type->idname);
+
+ for(opm= op->macro.first; opm; opm= opm->next) {
+
+ if(opm->type->exec) {
+// printf("macro exec %s\n", opm->type->idname);
+ retval= opm->type->exec(C, opm);
+
+ if(!(retval & OPERATOR_FINISHED))
+ break;
+ }
+ }
+// if(opm)
+// printf("macro ended not finished\n");
+// else
+// printf("macro end\n");
+
+ return retval;
+}
+
+static int wm_macro_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+ wmOperator *opm;
+ int retval= OPERATOR_FINISHED;
+
+// printf("macro invoke %s\n", op->type->idname);
+
+ for(opm= op->macro.first; opm; opm= opm->next) {
+
+ if(opm->type->invoke)
+ retval= opm->type->invoke(C, opm, event);
+ else if(opm->type->exec)
+ retval= opm->type->exec(C, opm);
+
+ if(!(retval & OPERATOR_FINISHED))
+ break;
+ }
+
+// if(opm)
+// printf("macro ended not finished\n");
+// else
+// printf("macro end\n");
+
+
+ return retval;
+}
+
+static int wm_macro_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+// printf("macro modal %s\n", op->type->idname);
+
+ if(op->opm==NULL)
+ printf("macro error, calling NULL modal()\n");
+ else {
+// printf("macro modal %s\n", op->opm->type->idname);
+ return op->opm->type->modal(C, op->opm, event);
+ }
+
+ return OPERATOR_FINISHED;
+}
+
+/* Names have to be static for now */
+wmOperatorType *WM_operatortype_append_macro(char *idname, char *name, int flag)
+{
+ wmOperatorType *ot;
+
+ if(WM_operatortype_exists(idname)) {
+ printf("Macro error: operator %s exists\n", idname);
+ return NULL;
+ }
+
+ ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
+ ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
+
+ ot->idname= idname;
+ ot->name= name;
+ ot->flag= OPTYPE_MACRO | flag;
+
+ ot->exec= wm_macro_exec;
+ ot->invoke= wm_macro_invoke;
+ ot->modal= wm_macro_modal;
+ ot->poll= NULL;
+
+ RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description:"(undocumented operator)"); // XXX All ops should have a description but for now allow them not to.
+ RNA_def_struct_identifier(ot->srna, ot->idname);
+
+ BLI_addtail(&global_ops, ot);
+
+ return ot;
+}
+
+wmOperatorTypeMacro *WM_operatortype_macro_define(wmOperatorType *ot, const char *idname)
+{
+ wmOperatorTypeMacro *otmacro= MEM_callocN(sizeof(wmOperatorTypeMacro), "wmOperatorTypeMacro");
+
+ BLI_strncpy(otmacro->idname, idname, OP_MAX_TYPENAME);
+
+ /* do this on first use, since operatordefinitions might have been not done yet */
+// otmacro->ptr= MEM_callocN(sizeof(PointerRNA), "optype macro ItemPtr");
+// WM_operator_properties_create(otmacro->ptr, idname);
+
+ BLI_addtail(&ot->macro, otmacro);
+
+ return otmacro;
+}
+
+static void wm_operatortype_free_macro(wmOperatorType *ot)
+{
+ wmOperatorTypeMacro *otmacro;
+
+ for(otmacro= ot->macro.first; otmacro; otmacro= otmacro->next) {
+ if(otmacro->ptr) {
+ WM_operator_properties_free(otmacro->ptr);
+ MEM_freeN(otmacro->ptr);
+ }
+ }
+ BLI_freelistN(&ot->macro);
+}
+
+
int WM_operatortype_remove(const char *idname)
{
wmOperatorType *ot = WM_operatortype_find(idname, 0);
@@ -163,6 +291,10 @@ int WM_operatortype_remove(const char *idname)
BLI_remlink(&global_ops, ot);
RNA_struct_free(&BLENDER_RNA, ot->srna);
+
+ if(ot->macro.first)
+ wm_operatortype_free_macro(ot);
+
MEM_freeN(ot);
return 1;
@@ -348,7 +480,7 @@ static void redo_cb(bContext *C, void *arg_op, void *arg2)
wmOperator *lastop= arg_op;
if(lastop) {
- ED_undo_pop(C);
+ ED_undo_pop_op(C, lastop);
WM_operator_repeat(C, lastop);
}
}
@@ -1677,6 +1809,12 @@ static void WM_OT_ten_timer(wmOperatorType *ot)
/* called on initialize WM_exit() */
void wm_operatortype_free(void)
{
+ wmOperatorType *ot;
+
+ for(ot= global_ops.first; ot; ot= ot->next)
+ if(ot->macro.first)
+ wm_operatortype_free_macro(ot);
+
BLI_freelistN(&global_ops);
}