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:
authorCampbell Barton <ideasman42@gmail.com>2012-12-19 06:08:58 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-12-19 06:08:58 +0400
commitacfe74351bc33ad11448c3acc18a0d3a88ff4059 (patch)
tree7f546ba28f0019b48a5bd73d855f6ac07515cb6b
parent0ddc77f9137e014bf22ea9a240c3a4ca0d239cd2 (diff)
improve info view property output for properties.
- Include RNA properties when checking for matches. - Don't include the context's property store (these are normally set by the UI code and not accessible by a script author) Note: added CTX_data_dir_get_ex() which has options for returning different members from the context.
-rw-r--r--source/blender/blenkernel/BKE_context.h1
-rw-r--r--source/blender/blenkernel/intern/context.c49
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c24
3 files changed, 50 insertions, 24 deletions
diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h
index 22b8f474cca..285077f258c 100644
--- a/source/blender/blenkernel/BKE_context.h
+++ b/source/blender/blenkernel/BKE_context.h
@@ -185,6 +185,7 @@ enum {
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member);
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type);
ListBase CTX_data_collection_get(const bContext *C, const char *member);
+ListBase CTX_data_dir_get_ex(const bContext *C, const short use_store, const short use_rna, const short use_all);
ListBase CTX_data_dir_get(const bContext *C);
int CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, ListBase *r_lb, short *r_type);
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index ffb93139358..7009f1235c9 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -427,11 +427,11 @@ int CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, ListB
return ret;
}
-static void data_dir_add(ListBase *lb, const char *member)
+static void data_dir_add(ListBase *lb, const char *member, const short use_all)
{
LinkData *link;
- if (strcmp(member, "scene") == 0) /* exception */
+ if ((use_all == FALSE) && strcmp(member, "scene") == 0) /* exception */
return;
if (BLI_findstring(lb, member, offsetof(LinkData, data)))
@@ -442,7 +442,13 @@ static void data_dir_add(ListBase *lb, const char *member)
BLI_addtail(lb, link);
}
-ListBase CTX_data_dir_get(const bContext *C)
+/**
+ * \param C Context
+ * \param use_store Use 'C->wm.store'
+ * \param use_rna Use Include the properties from 'RNA_Context'
+ * \param use_all Don't skip values (currently only "scene")
+ */
+ListBase CTX_data_dir_get_ex(const bContext *C, const short use_store, const short use_rna, const short use_all)
{
bContextDataResult result;
ListBase lb;
@@ -453,11 +459,33 @@ ListBase CTX_data_dir_get(const bContext *C)
memset(&lb, 0, sizeof(lb));
- if (C->wm.store) {
+ if (use_rna) {
+ char name[256], *nameptr;
+ int namelen;
+
+ PropertyRNA *iterprop;
+ PointerRNA ctx_ptr;
+ RNA_pointer_create(NULL, &RNA_Context, (void *)C, &ctx_ptr);
+
+ iterprop = RNA_struct_iterator_property(ctx_ptr.type);
+
+ RNA_PROP_BEGIN (&ctx_ptr, itemptr, iterprop)
+ {
+ nameptr = RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen);
+ data_dir_add(&lb, name, use_all);
+ if (nameptr) {
+ if (name != nameptr) {
+ MEM_freeN(nameptr);
+ }
+ }
+ }
+ RNA_PROP_END;
+ }
+ if (use_store && C->wm.store) {
bContextStoreEntry *entry;
for (entry = C->wm.store->entries.first; entry; entry = entry->next)
- data_dir_add(&lb, entry->name);
+ data_dir_add(&lb, entry->name, use_all);
}
if ((ar = CTX_wm_region(C)) && ar->type && ar->type->context) {
memset(&result, 0, sizeof(result));
@@ -465,7 +493,7 @@ ListBase CTX_data_dir_get(const bContext *C)
if (result.dir)
for (a = 0; result.dir[a]; a++)
- data_dir_add(&lb, result.dir[a]);
+ data_dir_add(&lb, result.dir[a], use_all);
}
if ((sa = CTX_wm_area(C)) && sa->type && sa->type->context) {
memset(&result, 0, sizeof(result));
@@ -473,7 +501,7 @@ ListBase CTX_data_dir_get(const bContext *C)
if (result.dir)
for (a = 0; result.dir[a]; a++)
- data_dir_add(&lb, result.dir[a]);
+ data_dir_add(&lb, result.dir[a], use_all);
}
if ((sc = CTX_wm_screen(C)) && sc->context) {
bContextDataCallback cb = sc->context;
@@ -482,12 +510,17 @@ ListBase CTX_data_dir_get(const bContext *C)
if (result.dir)
for (a = 0; result.dir[a]; a++)
- data_dir_add(&lb, result.dir[a]);
+ data_dir_add(&lb, result.dir[a], use_all);
}
return lb;
}
+ListBase CTX_data_dir_get(const bContext *C)
+{
+ return CTX_data_dir_get_ex(C, TRUE, FALSE, FALSE);
+}
+
int CTX_data_equals(const char *member, const char *str)
{
return (strcmp(member, str) == 0);
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index cd3d5c97f99..05e949d781e 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -570,7 +570,8 @@ static char *wm_prop_pystring_from_context(bContext *C, PointerRNA *ptr, Propert
* - see if the pointers ID is in the context.
*/
- ListBase lb = CTX_data_dir_get(C);
+ /* don't get from the context store since this is normally set only for the UI and not usable elsewhere */
+ ListBase lb = CTX_data_dir_get_ex(C, FALSE, TRUE, TRUE);
LinkData *link;
const char *member_found = NULL;
@@ -582,21 +583,21 @@ static char *wm_prop_pystring_from_context(bContext *C, PointerRNA *ptr, Propert
for (link = lb.first; link; link = link->next) {
const char *identifier = link->data;
- PointerRNA ctx_ptr = CTX_data_pointer_get(C, identifier);
+ PointerRNA ctx_item_ptr = CTX_data_pointer_get(C, identifier);
- if (ctx_ptr.type == NULL) {
+ if (ctx_item_ptr.type == NULL) {
continue;
}
- if (ptr->id.data == ctx_ptr.id.data) {
- if ((ptr->data == ctx_ptr.data) &&
- (ptr->type == ctx_ptr.type))
+ if (ptr->id.data == ctx_item_ptr.id.data) {
+ if ((ptr->data == ctx_item_ptr.data) &&
+ (ptr->type == ctx_item_ptr.type))
{
/* found! */
member_found = identifier;
break;
}
- else if (RNA_struct_is_ID(ctx_ptr.type)) {
+ else if (RNA_struct_is_ID(ctx_item_ptr.type)) {
/* we found a reference to this ID,
* so fallback to it if there is no direct reference */
member_id = identifier;
@@ -604,15 +605,6 @@ static char *wm_prop_pystring_from_context(bContext *C, PointerRNA *ptr, Propert
}
}
- /* grr, CTX_data_dir_get skips scene */
- if ((member_id == NULL) &&
- (ptr->id.data != NULL) &&
- (GS(((ID *)ptr->id.data)->name) == ID_SCE) &&
- (CTX_data_scene(C) == ptr->id.data))
- {
- member_id = "scene";
- }
-
if (member_found) {
prop_str = RNA_path_property_py(ptr, prop, index);
if (prop_str) {