RNA
* Object has some more properties wrapped, mostly game related. * Scene frame changes now send a notifier. * Added functions to create/free operator properties for calling operators. This also simplifies some duplicated code that did this. Ideally though this kind of thing should use the properties pointer provided by buttons and keymap items. Example code: PointerRNA ptr; WM_operator_properties_create(&ptr, "SOME_OT_name"); RNA_int_set(&ptr, "value", 42); WM_operator_name_call(C, "SOME_OT_name", WM_OP_EXEC_DEFAULT, &ptr); WM_operator_properties_free(&ptr);
This commit is contained in:
@@ -48,21 +48,24 @@
|
||||
|
||||
#include "ED_screen.h"
|
||||
|
||||
#include "RNA_types.h"
|
||||
|
||||
/* ****************************************************** */
|
||||
|
||||
#define MAX_OP_REGISTERED 32
|
||||
|
||||
void WM_operator_free(wmOperator *op)
|
||||
{
|
||||
if(op->ptr) {
|
||||
op->properties= op->ptr->data;
|
||||
MEM_freeN(op->ptr);
|
||||
}
|
||||
|
||||
if(op->properties) {
|
||||
IDP_FreeProperty(op->properties);
|
||||
MEM_freeN(op->properties);
|
||||
op->properties= NULL;
|
||||
}
|
||||
|
||||
if(op->ptr)
|
||||
MEM_freeN(op->ptr);
|
||||
|
||||
if(op->reports) {
|
||||
BKE_reports_clear(op->reports);
|
||||
MEM_freeN(op->reports);
|
||||
@@ -77,6 +80,12 @@ void wm_operator_register(wmWindowManager *wm, wmOperator *op)
|
||||
{
|
||||
int tot;
|
||||
|
||||
if(op->ptr) {
|
||||
op->properties= op->ptr->data;
|
||||
MEM_freeN(op->ptr);
|
||||
op->ptr= NULL;
|
||||
}
|
||||
|
||||
BLI_addtail(&wm->operators, op);
|
||||
tot= BLI_countlist(&wm->operators);
|
||||
|
||||
@@ -152,12 +161,9 @@ void wm_close_and_free(bContext *C, wmWindowManager *wm)
|
||||
|
||||
while((km= wm->keymaps.first)) {
|
||||
for(kmi=km->keymap.first; kmi; kmi=kmi->next) {
|
||||
if(kmi->ptr)
|
||||
if(kmi->ptr) {
|
||||
WM_operator_properties_free(kmi->ptr);
|
||||
MEM_freeN(kmi->ptr);
|
||||
|
||||
if(kmi->properties) {
|
||||
IDP_FreeProperty(kmi->properties);
|
||||
MEM_freeN(kmi->properties);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -355,7 +355,7 @@ int WM_operator_call(bContext *C, wmOperator *op)
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, IDProperty *properties)
|
||||
static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, PointerRNA *properties)
|
||||
{
|
||||
wmWindowManager *wm= CTX_wm_manager(C);
|
||||
int retval= OPERATOR_PASS_THROUGH;
|
||||
@@ -363,15 +363,14 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, I
|
||||
if(ot->poll==NULL || ot->poll(C)) {
|
||||
wmOperator *op= MEM_callocN(sizeof(wmOperator), ot->idname); /* XXX operatortype names are static still. for debug */
|
||||
|
||||
if(properties)
|
||||
op->properties= IDP_CopyProperty(properties);
|
||||
|
||||
/* XXX adding new operator could be function, only happens here now */
|
||||
op->type= ot;
|
||||
BLI_strncpy(op->idname, ot->idname, OP_MAX_TYPENAME);
|
||||
|
||||
op->ptr= MEM_callocN(sizeof(PointerRNA), "wmOperatorPtrRNA");
|
||||
RNA_pointer_create(&RNA_WindowManager, &wm->id, ot->srna, &op->properties, op->ptr);
|
||||
if(properties && properties->data)
|
||||
op->ptr->data= IDP_CopyProperty(properties->data);
|
||||
RNA_pointer_create(&RNA_WindowManager, &wm->id, ot->srna, op->ptr->data, op->ptr);
|
||||
|
||||
op->reports= MEM_callocN(sizeof(ReportList), "wmOperatorReportList");
|
||||
BKE_reports_init(op->reports, RPT_STORE);
|
||||
@@ -402,7 +401,7 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, I
|
||||
}
|
||||
|
||||
/* invokes operator in context */
|
||||
int WM_operator_name_call(bContext *C, const char *opstring, int context, IDProperty *properties)
|
||||
int WM_operator_name_call(bContext *C, const char *opstring, int context, PointerRNA *properties)
|
||||
{
|
||||
wmOperatorType *ot= WM_operatortype_find(opstring);
|
||||
wmWindow *window= CTX_wm_window(C);
|
||||
@@ -605,7 +604,7 @@ static int wm_event_always_pass(wmEvent *event)
|
||||
}
|
||||
|
||||
/* Warning: this function removes a modal handler, when finished */
|
||||
static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHandler *handler, wmEvent *event, IDProperty *properties)
|
||||
static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHandler *handler, wmEvent *event, PointerRNA *properties)
|
||||
{
|
||||
int retval= OPERATOR_PASS_THROUGH;
|
||||
|
||||
@@ -746,7 +745,7 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
|
||||
|
||||
event->keymap_idname= kmi->idname; /* weak, but allows interactive callback to not use rawkey */
|
||||
|
||||
action= wm_handler_operator_call(C, handlers, handler, event, kmi->properties);
|
||||
action= wm_handler_operator_call(C, handlers, handler, event, kmi->ptr);
|
||||
if(action==WM_HANDLER_BREAK) /* not wm_event_always_pass(event) here, it denotes removed handler */
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -84,15 +84,9 @@ static void keymap_event_set(wmKeymapItem *kmi, short type, short val, int modif
|
||||
|
||||
static void keymap_properties_set(wmKeymapItem *kmi)
|
||||
{
|
||||
wmOperatorType *ot;
|
||||
|
||||
if(!kmi->ptr) {
|
||||
ot= WM_operatortype_find(kmi->idname);
|
||||
|
||||
if(ot) {
|
||||
kmi->ptr= MEM_callocN(sizeof(PointerRNA), "wmKeymapItemPtr");
|
||||
RNA_pointer_create(NULL, NULL, ot->srna, &kmi->properties, kmi->ptr);
|
||||
}
|
||||
kmi->ptr= MEM_callocN(sizeof(PointerRNA), "wmKeymapItemPtr");
|
||||
WM_operator_properties_create(kmi->ptr, kmi->idname);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -164,6 +164,26 @@ char *WM_operator_pystring(wmOperator *op)
|
||||
return cstring;
|
||||
}
|
||||
|
||||
void WM_operator_properties_create(PointerRNA *ptr, const char *opstring)
|
||||
{
|
||||
wmOperatorType *ot= WM_operatortype_find(opstring);
|
||||
|
||||
if(ot)
|
||||
RNA_pointer_create(NULL, NULL, ot->srna, NULL, ptr);
|
||||
else
|
||||
memset(ptr, 0, sizeof(*ptr));
|
||||
}
|
||||
|
||||
void WM_operator_properties_free(PointerRNA *ptr)
|
||||
{
|
||||
IDProperty *properties= ptr->data;
|
||||
|
||||
if(properties) {
|
||||
IDP_FreeProperty(properties);
|
||||
MEM_freeN(properties);
|
||||
}
|
||||
}
|
||||
|
||||
/* ************ default op callbacks, exported *********** */
|
||||
|
||||
/* invoke callback, uses enum property named "type" */
|
||||
|
||||
Reference in New Issue
Block a user