[Bf-blender-cvs] [dbd766f] asset-experiments: Nearly finished 'UIList for bookmarks'.

Bastien Montagne noreply at git.blender.org
Mon Jan 5 21:15:59 CET 2015


Commit: dbd766f827f025aa3cb67e96b11d1137cf856109
Author: Bastien Montagne
Date:   Mon Jan 5 21:12:23 2015 +0100
Branches: asset-experiments
https://developer.blender.org/rBdbd766f827f025aa3cb67e96b11d1137cf856109

Nearly finished 'UIList for bookmarks'.

Got completely rid of C code for those panels.

Added full path in ttips of each 'bookmark' entry, as in current master.
Note this forced me to make tip in uiBut dynamic (like label). Not so sure
about this, but seems to me forcing tooltips to be static is actually quite
bad and limitating? we'll see...

Only remaining TODO (new feature) is reordering of bookmarks, should be easy now.

Also fixed some stupid (again!) mistake with RNA access to paths of bookmark entries.

===================================================================

M	source/blender/editors/include/ED_fileselect.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/space_file/file_panels.c
M	source/blender/editors/space_file/fsmenu.c
M	source/blender/makesrna/intern/rna_space.c
M	source/blenderplayer/bad_level_call_stubs/stubs.c

===================================================================

diff --git a/source/blender/editors/include/ED_fileselect.h b/source/blender/editors/include/ED_fileselect.h
index 171b5c9..4abfb65 100644
--- a/source/blender/editors/include/ED_fileselect.h
+++ b/source/blender/editors/include/ED_fileselect.h
@@ -137,7 +137,9 @@ struct FSMenuEntry *fsmenu_get_entry(struct FSMenu *fsmenu, FSMenuCategory categ
 
 /** Returns the fsmenu entry (path) at \a index (or NULL if a bad index) or a separator.
  */
+char *fsmenu_entry_get_path(struct FSMenuEntry *fsentry);
 char *fsmenu_get_entry_path(struct FSMenu *fsmenu, FSMenuCategory category, int index);
+void fsmenu_entry_set_path(struct FSMenuEntry *fsentry, const char *path);
 
 /** Returns the fsmenu name at \a index (or NULL if a bad index) or a separator.
  */
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 38e331e..c80d474 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -751,6 +751,23 @@ static bool ui_but_update_from_old_block(const bContext *C, uiBlock *block, uiBu
 			BLI_strncpy(oldbut->strdata, but->strdata, sizeof(oldbut->strdata));
 		}
 
+		if (but->tip != but->tipdata) {
+			if (oldbut->tip != oldbut->tipdata) {
+				SWAP(char *, but->tip, oldbut->tip);
+			}
+			else {
+				oldbut->tip = but->tip;
+				but->tip = but->tipdata;
+			}
+		}
+		else {
+			if (oldbut->tip != oldbut->tipdata) {
+				MEM_SAFE_FREE(oldbut->tip);
+				oldbut->tip = oldbut->tipdata;
+			}
+			BLI_strncpy(oldbut->tipdata, but->tipdata, sizeof(oldbut->tipdata));
+		}
+
 		BLI_remlink(&block->buttons, but);
 		ui_but_free(C, but);
 
@@ -2430,6 +2447,9 @@ static void ui_but_free(const bContext *C, uiBut *but)
 	if (but->str && but->str != but->strdata) {
 		MEM_freeN(but->str);
 	}
+	if (but->tip && but->tip != but->tipdata) {
+		MEM_freeN(but->tip);
+	}
 	ui_free_link(but->link);
 
 	if ((but->type == UI_BTYPE_IMAGE) && but->poin) {
@@ -3059,6 +3079,20 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str,
 	}
 	memcpy(but->str, str, slen + 1);
 
+	if (tip) {
+		slen = strlen(tip);
+		if (slen >= UI_MAX_NAME_STR) {
+			but->tip = MEM_mallocN(slen + 1, "ui_def_but tip");
+		}
+		else {
+			but->tip = but->tipdata;
+		}
+		memcpy(but->tip, tip, slen + 1);
+	}
+	else {
+		but->tip = NULL;
+	}
+
 	but->rect.xmin = x;
 	but->rect.ymin = y;
 	but->rect.xmax = but->rect.xmin + width;
@@ -3069,7 +3103,6 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str,
 	but->hardmax = but->softmax = max;
 	but->a1 = a1;
 	but->a2 = a2;
-	but->tip = tip;
 
 	but->lock = block->lock;
 	but->lockstr = block->lockstr;
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 7a217e5..65b6021 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -254,7 +254,9 @@ struct uiBut {
 	uiLink *link;
 	short linkto[2];  /* region relative coords */
 	
-	const char *tip, *lockstr;
+	char tipdata[UI_MAX_NAME_STR];
+	char *tip;
+	const char *lockstr;
 
 	BIFIconID icon;
 	bool lock;
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 31d51e8..6316ec6 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -2833,6 +2833,30 @@ static void uilist_resize_update_cb(bContext *UNUSED(C), void *arg1, void *UNUSE
 	}
 }
 
+#define UILIST_RENAME_TOOLTIP N_("Double click to rename")
+#define UILIST_TOOLTIP_LEN FILE_MAXDIR + 100
+
+static const char *uilist_generate_advanced_tooltip(char *tooltip_buff, size_t tooltip_len, PointerRNA *itemptr)
+{
+	PropertyRNA *prop = RNA_struct_find_property(itemptr, "uilist_dynamic_tooltip");
+
+	if (prop && (RNA_property_type(prop) == PROP_STRING)) {
+		char dyn_tooltip_buff[UILIST_TOOLTIP_LEN];
+		char *dyn_tooltip = RNA_property_string_get_alloc(itemptr, prop, dyn_tooltip_buff, sizeof(dyn_tooltip_buff), NULL);
+
+		BLI_snprintf(tooltip_buff, tooltip_len, "%s - %s", TIP_(UILIST_RENAME_TOOLTIP), dyn_tooltip);
+
+		if (dyn_tooltip != dyn_tooltip_buff) {
+			MEM_freeN(dyn_tooltip);
+		}
+
+		return tooltip_buff;
+
+	}
+
+	return TIP_(UILIST_RENAME_TOOLTIP);
+}
+
 void uiTemplateList(uiLayout *layout, bContext *C, const char *listtype_name, const char *list_id,
                     PointerRNA *dataptr, const char *propname, PointerRNA *active_dataptr, const char *active_propname,
                     int rows, int maxrows, int layout_type, int columns)
@@ -3049,6 +3073,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, const char *listtype_name, co
 				/* create list items */
 				for (i = layoutdata.start_idx; i < layoutdata.end_idx; i++) {
 					PointerRNA *itemptr = &items_ptr[i].item;
+					char tooltip_buff[UILIST_TOOLTIP_LEN];
 					int org_i = items_ptr[i].org_idx;
 					int flt_flag = items_ptr[i].flt_flag;
 					subblock = uiLayoutGetBlock(col);
@@ -3061,7 +3086,8 @@ void uiTemplateList(uiLayout *layout, bContext *C, const char *listtype_name, co
 					sub = uiLayoutRow(overlap, false);
 
 					but = uiDefButR_prop(subblock, UI_BTYPE_LISTROW, 0, "", 0, 0, UI_UNIT_X * 10, UI_UNIT_Y,
-					                     active_dataptr, activeprop, 0, 0, org_i, 0, 0, TIP_("Double click to rename"));
+					                     active_dataptr, activeprop, 0, 0, org_i, 0, 0,
+					                     uilist_generate_advanced_tooltip(tooltip_buff, sizeof(tooltip_buff), itemptr));
 
 					sub = uiLayoutRow(overlap, false);
 
@@ -3238,6 +3264,9 @@ void uiTemplateList(uiLayout *layout, bContext *C, const char *listtype_name, co
 	}
 }
 
+#undef UILIST_RENAME_TOOLTIP
+#undef UILIST_TOOLTIP_LEN
+
 /************************* Operator Search Template **************************/
 
 static void operator_call_cb(bContext *C, void *UNUSED(arg1), void *arg2)
diff --git a/source/blender/editors/space_file/file_panels.c b/source/blender/editors/space_file/file_panels.c
index 062ac2d..9a7ee93 100644
--- a/source/blender/editors/space_file/file_panels.c
+++ b/source/blender/editors/space_file/file_panels.c
@@ -57,140 +57,6 @@
 
 #include <string.h>
 
-static void file_panel_cb(bContext *C, void *arg_entry, void *UNUSED(arg_v))
-{
-	wmOperatorType *ot = WM_operatortype_find("FILE_OT_select_bookmark", false);
-	PointerRNA ptr;
-	const char *entry = (char *)arg_entry;
-
-	WM_operator_properties_create_ptr(&ptr, ot);
-	RNA_string_set(&ptr, "dir", entry);
-	WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_REGION_WIN, &ptr);
-	WM_operator_properties_free(&ptr);
-}
-
-static void file_panel_category(const bContext *C, Panel *pa, FSMenuCategory category, short *nr, int icon, int allow_delete)
-{
-	SpaceFile *sfile = CTX_wm_space_file(C);
-	uiBlock *block;
-	uiBut *but;
-	uiLayout *box, *col;
-	struct FSMenu *fsmenu = fsmenu_get();
-	int i, nentries = fsmenu_get_nentries(fsmenu, category);
-
-	/* reset each time */
-	//~ *nr = -1;
-
-	/* hide if no entries */
-	if (nentries == 0)
-		return;
-
-	/* layout */
-	uiLayoutSetAlignment(pa->layout, UI_LAYOUT_ALIGN_LEFT);
-	block = uiLayoutGetBlock(pa->layout);
-	box = uiLayoutBox(pa->layout);
-	col = uiLayoutColumn(box, true);
-
-	for (i = 0; i < nentries; ++i) {
-		uiLayout *layout = uiLayoutRow(col, false);
-		char *entry_path;
-		char *entry_name;
-		
-		entry_path = fsmenu_get_entry_path(fsmenu, category, i);
-		entry_name = fsmenu_get_entry_name(fsmenu, category, i);
-		
-		/* set this list item as active if we have a match */
-		if (sfile->params) {
-			if (BLI_path_cmp(sfile->params->dir, entry_path) == 0) {
-				*nr = i;
-			}
-		}
-
-		/* create nice bookmark name, shows last directory in the full path currently */
-		//BLI_strncpy(temp, entry, FILE_MAX);
-		//BLI_add_slash(temp);
-		//BLI_getlastdir(temp, dir, FILE_MAX);
-		//BLI_del_slash(dir);
-
-		//if (dir[0] == 0)
-			//BLI_strncpy(dir, entry, FILE_MAX);
-
-		/* create list item */
-		but = uiDefIconTextButS(block, UI_BTYPE_LISTROW, 0, icon, entry_name, 0, 0, UI_UNIT_X * 10, UI_UNIT_Y, nr, 0, i, 0, 0, entry_path);
-		UI_but_func_set(but, file_panel_cb, entry_path, NULL);
-		UI_but_flag_disable(but, UI_BUT_UNDO); /* skip undo on screen buttons */
-		UI_but_drawflag_enable(but, UI_BUT_ICON_LEFT | UI_BUT_TEXT_LEFT);
-
-		/* create delete button */
-		if (allow_delete && fsmenu_can_save(fsmenu, category, i)) {
-			UI_block_emboss_set(block, UI_EMBOSS_NONE);
-			uiItemIntO(layout, "", ICON_X, "FILE_OT_bookmark_delete", "index", i);
-			UI_block_emboss_set(block, UI_EMBOSS);
-		}
-	}
-}
-
-static void file_panel_system(const bContext *C, Panel *pa)
-{
-	SpaceFile *sfile = CTX_wm_space_file(C);
-
-	//~ if (sfile)
-		//~ file_panel_category(C, pa, FS_CATEGORY_SYSTEM, &sfile->systemnr, ICON_DISK_DRIVE, 0);
-}
-
-static int file_panel_system_bookmarks_poll(const bContext *C, PanelType *UNUSED(pt))
-{
-	SpaceFile *sfile = CTX_wm_space_file(C);
-	return (sfile && !(U.uiflag & USER_HIDE_SYSTEM_BOOKMARKS));
-}
-
-static void file_panel_system_bookmarks(const bContext *C, Panel *pa)
-{
-	SpaceFile *sfile = CTX_wm_space_file(C);
-
-	//~ if (sfile && !(U.uiflag & USER_HIDE_SYSTEM_BOOKMARKS)) {
-		//~ file_panel_category(C, pa, FS_CATEGORY_SYSTEM_BOOKMARKS, &sfile->systemnr, ICON_BOOKMARKS, 0);
-	//~ }
-
-}
-
-static void file_panel_bookmarks(const bContext *C, Panel *pa)
-{
-	SpaceFile *sfile = CTX_wm_space_file(C);
-	uiLayout *row;
-
-	if (sfile) {
-		row = uiLayoutRow(pa->layout, false);
-		uiItemO(row, IFACE_("Add"), ICON_ZOOMIN, "file.bookmark_add");
-		uiItemL(row, NULL, ICON_NONE);
-
-		//~ file_panel_category(C, pa, FS_CATEGORY_BOOKMARKS, &sfile->bookmarknr, ICON_BOOKMARKS, 1);
-	}
-}
-
-static int file_panel_recent_poll(const bContext *C, PanelType *UNUSED(pt))
-{
-	SpaceFile *sfile = CTX_wm_space_file(C);
-	return (sfile && !(U.uiflag & USER_HIDE_RECENT));
-}
-
-static void file_panel_recent(const bContext *C, Panel *pa)
-{
-	SpaceFile *sfile = CTX_wm_space_file(C);
-	uiLayout *row;
-
-	if (sfile) {
-		if (!(U.uiflag & USER_HIDE_RECENT)) {
-			row = uiLayoutRow(pa->layout, false);
-			uiItemO(row, IFACE_("Reset"), ICON_X, "file.reset_recent");
-			uiIt

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list