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:
authorDiego Borghetti <bdiego@gmail.com>2008-01-14 22:44:20 +0300
committerDiego Borghetti <bdiego@gmail.com>2008-01-14 22:44:20 +0300
commit2a0055401e86bd2344564184cd7a48170d984367 (patch)
tree6ce393d7a983b410a3c5d99943742a6336f6eb0b /source/blender/windowmanager
parent49eb7a3eed225f8ff109a5b10b1a3192bcdd4f1b (diff)
New API to access Operator properties.
This is a simple API around IDProperty to store properties in the Operator, it is really simple and this first commit just add support for IDP_INT data type. Take care that this "properties" are not save yet and you get some "Error totblock" more with this. I add some notes to the WM_api.h file, please check this, comment and ideas are welcome.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/WM_api.h16
-rw-r--r--source/blender/windowmanager/intern/wm.c15
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c42
3 files changed, 73 insertions, 0 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 915c55f4cf7..727b228405b 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -81,6 +81,22 @@ int WM_operator_winactive (struct bContext *C);
wmOperatorType *WM_operatortype_find(const char *idname);
void WM_operatortypelist_append(ListBase *lb);
+/*
+ * Operator property api
+ *
+ * Some notes to take care:
+ *
+ * OP_set_int try to append a new property to the operator,
+ * if the property already exist, just replace it with the
+ * value in other case make a new property and append it.
+ *
+ * OP_get_int return 0 on success (found the property) or
+ * != 0 if can't found the property in the operator.
+ * The property value are store in the "value" pointer.
+ */
+void OP_set_int(wmOperator *op, char *name, int value);
+int OP_get_int(wmOperator *op, char *name, int *value);
+
/* OpenGL wrappers, mimicing opengl syntax */
void wmLoadMatrix (wmWindow *win, float mat[][4]);
void wmGetMatrix (wmWindow *win, float mat[][4]);
diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c
index 19bf8e67db7..d0319da593b 100644
--- a/source/blender/windowmanager/intern/wm.c
+++ b/source/blender/windowmanager/intern/wm.c
@@ -36,6 +36,7 @@
#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_main.h"
+#include "BKE_idprop.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -124,6 +125,7 @@ void wm_add_default(bContext *C)
/* context is allowed to be NULL, do net free wm itself (library.c) */
void wm_close_and_free(bContext *C, wmWindowManager *wm)
{
+ wmOperator *op;
wmWindow *win;
while((win= wm->windows.first)) {
@@ -131,6 +133,19 @@ void wm_close_and_free(bContext *C, wmWindowManager *wm)
wm_window_free(C, win);
}
+ op= wm->operators.first;
+ while(op) {
+ /*
+ * Need this, because if the operator don't have
+ * properties also don't have group.
+ */
+ if(op->properties) {
+ IDP_FreeGroup(op->properties);
+ op->properties= NULL;
+ }
+ op= op->next;
+ }
+
BLI_freelistN(&wm->operators);
BLI_freelistN(&wm->windowkeymap);
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 27f8b48451a..4c26ef4b115 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -28,6 +28,7 @@
#include <string.h>
+#include "DNA_ID.h"
#include "DNA_windowmanager_types.h"
#include "MEM_guardedalloc.h"
@@ -38,6 +39,7 @@
#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_main.h"
+#include "BKE_idprop.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -136,7 +138,47 @@ void wm_operatortype_init(void)
ADD_OPTYPE(WM_OT_window_fullscreen_toggle);
}
+/* wrapped to get property from a operator. */
+IDProperty *op_get_property(wmOperator *op, char *name)
+{
+ IDProperty *prop= IDP_GetPropertyFromGroup(op->properties, name);
+ return(prop);
+}
+
+/*
+ * We need create a "group" to store the operator properties.
+ * We don't have a WM_operator_new or some thing like that,
+ * so this function is called by all the OP_set_* function
+ * in case that op->properties is equal to NULL.
+ */
+void op_init_property(wmOperator *op)
+{
+ IDPropertyTemplate val;
+ op->properties= IDP_New(IDP_GROUP, val, "property");
+}
+/* ***** Property API, exported ***** */
+void OP_set_int(wmOperator *op, char *name, int value)
+{
+ IDPropertyTemplate val;
+ IDProperty *prop;
+
+ if(!op->properties)
+ op_init_property(op);
+ val.i= value;
+ prop= IDP_New(IDP_INT, val, name);
+ IDP_ReplaceInGroup(op->properties, prop);
+}
+int OP_get_int(wmOperator *op, char *name, int *value)
+{
+ IDProperty *prop= op_get_property(op, name);
+ int status= 1;
+ if ((prop) && (prop->type == IDP_INT)) {
+ (*value)= prop->data.val;
+ status= 0;
+ }
+ return (status);
+}