[Bf-blender-cvs] [387bc54] workspaces: Make layout template only show layouts of current workspace
Julian Eisel
noreply at git.blender.org
Mon Dec 5 18:19:16 CET 2016
Commit: 387bc547cb781445e901f22fdcb684549eff5d5f
Author: Julian Eisel
Date: Mon Dec 5 18:14:38 2016 +0100
Branches: workspaces
https://developer.blender.org/rB387bc547cb781445e901f22fdcb684549eff5d5f
Make layout template only show layouts of current workspace
Mainly had to do some changes to template_ID to make this work. It now supports setting a custom RNA collection to search the ID's in.
===================================================================
M release/scripts/startup/bl_ui/space_info.py
M source/blender/editors/include/UI_interface.h
M source/blender/editors/interface/interface_intern.h
M source/blender/editors/interface/interface_layout.c
M source/blender/editors/interface/interface_templates.c
M source/blender/editors/interface/interface_utils.c
M source/blender/editors/space_clip/clip_buttons.c
M source/blender/editors/space_image/image_buttons.c
M source/blender/editors/space_logic/logic_window.c
M source/blender/editors/space_nla/nla_buttons.c
M source/blender/editors/space_node/drawnode.c
M source/blender/makesrna/intern/rna_ui_api.c
M source/blender/makesrna/intern/rna_workspace.c
M source/blenderplayer/bad_level_call_stubs/stubs.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_info.py b/release/scripts/startup/bl_ui/space_info.py
index ef3130f..c1b353e 100644
--- a/release/scripts/startup/bl_ui/space_info.py
+++ b/release/scripts/startup/bl_ui/space_info.py
@@ -42,7 +42,7 @@ class INFO_HT_header(Header):
layout.separator()
else:
layout.template_ID(window, "workspace", new="workspace.workspace_new", unlink="workspace.workspace_delete")
- layout.template_ID_preview(window.workspace, "screen", new="screen.new", unlink="screen.delete", rows=2, cols=6)
+ layout.template_ID_preview(context.workspace, "screen", workspace, "screens", new="screen.new", unlink="screen.delete", rows=2, cols=6)
layout.template_ID(screen, "scene", new="scene.new", unlink="scene.delete")
layout.separator()
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index d48cfbe..9c8055c 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -907,11 +907,14 @@ uiLayout *uiLayoutRadial(uiLayout *layout);
/* templates */
void uiTemplateHeader(uiLayout *layout, struct bContext *C);
void uiTemplateID(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname,
- const char *newop, const char *openop, const char *unlinkop);
+ struct PointerRNA *searchptr, const char *searchpropname, const char *newop,
+ const char *openop, const char *unlinkop);
void uiTemplateIDBrowse(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname,
- const char *newop, const char *openop, const char *unlinkop);
+ struct PointerRNA *searchptr, const char *searchpropname, const char *newop,
+ const char *openop, const char *unlinkop);
void uiTemplateIDPreview(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname,
- const char *newop, const char *openop, const char *unlinkop, int rows, int cols);
+ struct PointerRNA *searchptr, const char *searchpropname, const char *newop,
+ const char *openop, const char *unlinkop, int rows, int cols);
void uiTemplateAnyID(uiLayout *layout, struct PointerRNA *ptr, const char *propname,
const char *proptypename, const char *text);
void uiTemplatePathBuilder(uiLayout *layout, struct PointerRNA *ptr, const char *propname,
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 7529f60..808df1b 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -744,4 +744,20 @@ void UI_OT_eyedropper_id(struct wmOperatorType *ot);
void UI_OT_eyedropper_depth(struct wmOperatorType *ot);
void UI_OT_eyedropper_driver(struct wmOperatorType *ot);
+/* interface_util.c */
+
+/**
+ * For use with #ui_rna_collection_search_cb.
+ */
+struct uiRNACollectionSearch {
+ PointerRNA target_ptr;
+ PropertyRNA *target_prop;
+
+ PointerRNA search_ptr;
+ PropertyRNA *search_prop;
+
+ bool *but_changed; /* pointer to uiBut.changed */
+};
+void ui_rna_collection_search_cb(const struct bContext *C, void *arg, const char *str, uiSearchItems *items);
+
#endif /* __INTERFACE_INTERN_H__ */
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index b128bf4..c863be9 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -1524,94 +1524,6 @@ void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname
/* Pointer RNA button with search */
-typedef struct CollItemSearch {
- struct CollItemSearch *next, *prev;
- char *name;
- int index;
- int iconid;
-} CollItemSearch;
-
-static int sort_search_items_list(const void *a, const void *b)
-{
- const CollItemSearch *cis1 = a;
- const CollItemSearch *cis2 = b;
-
- if (BLI_strcasecmp(cis1->name, cis2->name) > 0)
- return 1;
- else
- return 0;
-}
-
-static void rna_search_cb(const struct bContext *C, void *arg_but, const char *str, uiSearchItems *items)
-{
- uiBut *but = arg_but;
- char *name;
- int i = 0, iconid = 0, flag = RNA_property_flag(but->rnaprop);
- ListBase *items_list = MEM_callocN(sizeof(ListBase), "items_list");
- CollItemSearch *cis;
- const bool skip_filter = !but->changed;
-
- /* build a temporary list of relevant items first */
- RNA_PROP_BEGIN (&but->rnasearchpoin, itemptr, but->rnasearchprop)
- {
- if (flag & PROP_ID_SELF_CHECK)
- if (itemptr.data == but->rnapoin.id.data)
- continue;
-
- /* use filter */
- if (RNA_property_type(but->rnaprop) == PROP_POINTER) {
- if (RNA_property_pointer_poll(&but->rnapoin, but->rnaprop, &itemptr) == 0)
- continue;
- }
-
- if (itemptr.type && RNA_struct_is_ID(itemptr.type)) {
- ID *id = itemptr.data;
- char name_ui[MAX_ID_NAME];
-
-#if 0 /* this name is used for a string comparison and can't be modified, TODO */
- /* if ever enabled, make name_ui be MAX_ID_NAME+1 */
- BKE_id_ui_prefix(name_ui, id);
-#else
- BLI_strncpy(name_ui, id->name + 2, sizeof(name_ui));
-#endif
- name = BLI_strdup(name_ui);
- iconid = ui_id_icon_get(C, id, false);
- }
- else {
- name = RNA_struct_name_get_alloc(&itemptr, NULL, 0, NULL); /* could use the string length here */
- iconid = 0;
- }
-
- if (name) {
- if (skip_filter || BLI_strcasestr(name, str)) {
- cis = MEM_callocN(sizeof(CollItemSearch), "CollectionItemSearch");
- cis->name = MEM_dupallocN(name);
- cis->index = i;
- cis->iconid = iconid;
- BLI_addtail(items_list, cis);
- }
- MEM_freeN(name);
- }
-
- i++;
- }
- RNA_PROP_END;
-
- BLI_listbase_sort(items_list, sort_search_items_list);
-
- /* add search items from temporary list */
- for (cis = items_list->first; cis; cis = cis->next) {
- if (false == UI_search_item_add(items, cis->name, SET_INT_IN_POINTER(cis->index), cis->iconid)) {
- break;
- }
- }
-
- for (cis = items_list->first; cis; cis = cis->next) {
- MEM_freeN(cis->name);
- }
- BLI_freelistN(items_list);
- MEM_freeN(items_list);
-}
static void search_id_collection(StructRNA *ptype, PointerRNA *ptr, PropertyRNA **prop)
{
@@ -1653,6 +1565,8 @@ void ui_but_add_search(uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRN
/* turn button into search button */
if (searchprop) {
+ static struct uiRNACollectionSearch coll_search;
+
but->type = UI_BTYPE_SEARCH_MENU;
but->hardmax = MAX2(but->hardmax, 256.0f);
but->rnasearchpoin = *searchptr;
@@ -1662,13 +1576,20 @@ void ui_but_add_search(uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRN
but->flag |= UI_BUT_VALUE_CLEAR;
}
+ coll_search.target_ptr = *ptr;
+ coll_search.target_prop = prop;
+ coll_search.search_ptr = *searchptr;
+ coll_search.search_prop = searchprop;
+ coll_search.but_changed = SET_INT_IN_POINTER(but->changed);
+
if (RNA_property_type(prop) == PROP_ENUM) {
/* XXX, this will have a menu string,
* but in this case we just want the text */
but->str[0] = 0;
}
- UI_but_func_search_set(but, ui_searchbox_create_generic, rna_search_cb, but, NULL, NULL);
+ UI_but_func_search_set(but, ui_searchbox_create_generic, ui_rna_collection_search_cb,
+ &coll_search, NULL, NULL);
}
}
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index f96964d..1045fd5 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -106,7 +106,20 @@ typedef struct TemplateID {
PointerRNA ptr;
PropertyRNA *prop;
- ListBase *idlb;
+ /**
+ * The collection to search in. By default this is the main listbase of
+ * an ID type but it's also possible to use a custom RNA collection.
+ */
+ union {
+ ListBase *idlb;
+
+ /* optional RNA collection property to search IDs in */
+ struct {
+ PointerRNA searchptr;
+ PropertyRNA *searchprop;
+ } custom;
+ } collection;
+
int prv_rows, prv_cols;
bool preview;
} TemplateID;
@@ -127,10 +140,10 @@ static void id_search_call_cb(bContext *C, void *arg_template, void *item)
}
/* ID Search browse menu, do the search */
-static void id_search_cb(const bContext *C, void *arg_template, const char *str, uiSearchItems *items)
+static void id_search_listbase_cb(const bContext *C, void *arg_template, const char *str, uiSearchItems *items)
{
TemplateID *template = (TemplateID *)arg_template;
- ListBase *lb = template->idlb;
+ ListBase *lb = template->collection.idlb;
ID *id, *id_from = template->ptr.id.data;
int iconid;
int flag = RNA_property_flag(template->prop);
@@ -168,6 +181,28 @@ static void id_search_cb(const bContext *C, void *arg_template, const char *str,
}
}
+static void id_search_cb(const bContext *C, void *arg_template, const char *str, uiSearchItems *items)
+{
+ TemplateID *template = (TemplateID *)arg_template;
+
+ if (template->collection.custom.searchprop) {
+ struct uiRNACollectionSearch coll_search;
+
+ coll_search.target_ptr = template->ptr;
+ coll_search.target_prop = template->prop;
+ coll_search.search_ptr = template->collection.custom.searchptr;
+ coll_search.search_prop = template->collection.custom.searchprop;
+ coll_search.but_changed = SET_INT_IN_POINTER(false);
+
+ /* add search items from custom RNA collection property */
+ ui_rna_collection_search_cb(C, &coll_search, str, items);
+ }
+ else {
+ /* add search items from listbase */
+ id_search_listbase_cb(C, template, str, items);
+ }
+}
+
/* ID Search browse menu, open */
static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_litem)
{
@@ -219,7 +254,7 @@ static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_litem)
UI_block_bounds_set_normal(block, 0.3f * U.widget_unit);
UI_block_direction_set(block, UI_DIR_DOWN);
-
+
/* give search-field focus */
UI_but_focus_on_enter_event(win, but);
/* this type of search
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list