[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48069] branches/soc-2012-bratwurst/source /blender: Add an X button to the screen and scene dropdowns that allow the user to delete screens and scenes without switching to them .

Jorge Rodriguez bs.vino at gmail.com
Tue Jun 19 08:12:06 CEST 2012


Revision: 48069
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48069
Author:   vino
Date:     2012-06-19 06:11:52 +0000 (Tue, 19 Jun 2012)
Log Message:
-----------
Add an X button to the screen and scene dropdowns that allow the user to delete screens and scenes without switching to them.

Modified Paths:
--------------
    branches/soc-2012-bratwurst/source/blender/editors/include/UI_interface.h
    branches/soc-2012-bratwurst/source/blender/editors/interface/interface_intern.h
    branches/soc-2012-bratwurst/source/blender/editors/interface/interface_layout.c
    branches/soc-2012-bratwurst/source/blender/editors/interface/interface_regions.c
    branches/soc-2012-bratwurst/source/blender/editors/interface/interface_templates.c
    branches/soc-2012-bratwurst/source/blender/editors/interface/interface_widgets.c
    branches/soc-2012-bratwurst/source/blender/editors/screen/screen_edit.c
    branches/soc-2012-bratwurst/source/blender/editors/screen/screen_ops.c
    branches/soc-2012-bratwurst/source/blender/editors/space_outliner/outliner_draw.c
    branches/soc-2012-bratwurst/source/blender/editors/space_view3d/view3d_toolbar.c
    branches/soc-2012-bratwurst/source/blender/windowmanager/intern/wm_operators.c

Modified: branches/soc-2012-bratwurst/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/include/UI_interface.h	2012-06-19 05:41:22 UTC (rev 48068)
+++ branches/soc-2012-bratwurst/source/blender/editors/include/UI_interface.h	2012-06-19 06:11:52 UTC (rev 48069)
@@ -578,7 +578,7 @@
 uiBut *uiFindInlink(uiBlock *block, void *poin);
 
 /* use inside searchfunc to add items */
-int     uiSearchItemAdd(uiSearchItems *items, const char *name, void *poin, int iconid);
+int     uiSearchItemAdd(uiSearchItems *items, const char *name, void *poin, int iconid, const char *unlink_operator);
 /* bfunc gets search item *poin as arg2, or if NULL the old string */
 void    uiButSetSearchFunc(uiBut *but,        uiButSearchFunc sfunc, void *arg1, uiButHandleFunc bfunc, void *active);
 /* height in pixels, it's using hardcoded values still */

Modified: branches/soc-2012-bratwurst/source/blender/editors/interface/interface_intern.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/interface/interface_intern.h	2012-06-19 05:41:22 UTC (rev 48068)
+++ branches/soc-2012-bratwurst/source/blender/editors/interface/interface_intern.h	2012-06-19 06:11:52 UTC (rev 48069)
@@ -478,7 +478,7 @@
 struct ThemeUI;
 void ui_widget_color_init(struct ThemeUI *tui);
 
-void ui_draw_menu_item(struct uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state);
+void ui_draw_menu_item(struct uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, struct wmOperatorType* unlink_operator, int state);
 void ui_draw_preview_item(struct uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state);
 
 extern unsigned char checker_stipple_sml[];

Modified: branches/soc-2012-bratwurst/source/blender/editors/interface/interface_layout.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/interface/interface_layout.c	2012-06-19 05:41:22 UTC (rev 48068)
+++ branches/soc-2012-bratwurst/source/blender/editors/interface/interface_layout.c	2012-06-19 06:11:52 UTC (rev 48069)
@@ -1313,7 +1313,7 @@
 	
 	/* add search items from temporary list */
 	for (cis = items_list->first; cis; cis = cis->next) {
-		if (!uiSearchItemAdd(items, cis->name, SET_INT_IN_POINTER(cis->index), cis->iconid)) {
+		if (!uiSearchItemAdd(items, cis->name, SET_INT_IN_POINTER(cis->index), cis->iconid, NULL)) {
 			break;
 		}
 	}

Modified: branches/soc-2012-bratwurst/source/blender/editors/interface/interface_regions.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/interface/interface_regions.c	2012-06-19 05:41:22 UTC (rev 48068)
+++ branches/soc-2012-bratwurst/source/blender/editors/interface/interface_regions.c	2012-06-19 06:11:52 UTC (rev 48069)
@@ -703,6 +703,7 @@
 	char **names;
 	void **pointers;
 	int *icons;
+	wmOperatorType **unlink_operators;
 
 	AutoComplete *autocpl;
 	void *active;
@@ -713,6 +714,7 @@
 	uiFontStyle fstyle;
 	uiSearchItems items;
 	int active;     /* index in items array */
+	int delete_active;	/* the mouse is over the delete button instead of the item text */
 	int noback;     /* when menu opened with enough space for this */
 	int preview;    /* draw thumbnail previews, rather than list */
 	int prv_rows, prv_cols;
@@ -722,7 +724,7 @@
 
 /* exported for use by search callbacks */
 /* returns zero if nothing to add */
-int uiSearchItemAdd(uiSearchItems *items, const char *name, void *poin, int iconid)
+int uiSearchItemAdd(uiSearchItems *items, const char *name, void *poin, int iconid, const char *unlink_operator)
 {
 	/* hijack for autocomplete */
 	if (items->autocpl) {
@@ -755,6 +757,16 @@
 		items->pointers[items->totitem] = poin;
 	if (items->icons)
 		items->icons[items->totitem] = iconid;
+	if (items->unlink_operators && unlink_operator)
+	{
+		wmOperatorType* wm = WM_operatortype_find(unlink_operator, 0);
+		PropertyRNA* prna = RNA_struct_type_find_property(wm->srna, "index");
+
+		// Only add an delete "X" button if the unlink operator has an "index" property, so the "X" doesn't show up for operators that don't support it.
+		if (prna) {
+			items->unlink_operators[items->totitem] = wm;
+		}
+	}
 	
 	items->totitem++;
 	
@@ -845,16 +857,31 @@
 	uiSearchboxData *data = ar->regiondata;
 
 	but->func_arg2 = NULL;
+	but->optype = NULL;
 	
 	if (data->active) {
-		char *name = data->items.names[data->active - 1];
-		char *cpoin = strchr(name, '|');
+		if (data->delete_active) {
+			but->optype = data->items.unlink_operators[data->active - 1];
+
+			if (but->opptr) {
+				WM_operator_properties_free(but->opptr);
+				MEM_freeN(but->opptr);
+			}
+
+			but->opptr = MEM_callocN(sizeof(PointerRNA), "uiButOpPtr");
+
+			WM_operator_properties_create(but->opptr, but->optype->idname);
+			RNA_int_set(but->opptr, "index", data->active - 1);
+		} else {
+			char *name = data->items.names[data->active - 1];
+			char *cpoin = strchr(name, '|');
 		
-		if (cpoin) cpoin[0] = 0;
-		BLI_strncpy(but->editstr, name, data->items.maxstrlen);
-		if (cpoin) cpoin[0] = '|';
+			if (cpoin) cpoin[0] = 0;
+			BLI_strncpy(but->editstr, name, data->items.maxstrlen);
+			if (cpoin) cpoin[0] = '|';
 		
-		but->func_arg2 = data->items.pointers[data->active - 1];
+			but->func_arg2 = data->items.pointers[data->active - 1];
+		}
 	}
 }
 
@@ -879,7 +906,15 @@
 				for (a = 0; a < data->items.totitem; a++) {
 					ui_searchbox_butrect(&rect, data, a);
 					if (BLI_in_rcti(&rect, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin)) {
-						if (data->active != a + 1) {
+						int old_delete_active = data->delete_active;
+						if (data->items.unlink_operators[a]) {
+							rcti delete_rect = rect;
+							delete_rect.xmin = delete_rect.xmax - (ICON_DEFAULT_HEIGHT + 6);
+							data->delete_active = !!BLI_in_rcti(&delete_rect, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin);
+						} else
+							data->delete_active = 0;
+
+						if (data->active != a + 1 || old_delete_active != data->delete_active) {
 							data->active = a + 1;
 							ui_searchbox_select(C, ar, but, 0);
 							break;
@@ -1001,7 +1036,7 @@
 				if (data->preview)
 					ui_draw_preview_item(&data->fstyle, &rect, data->items.names[a], data->items.icons[a], (a + 1) == data->active ? UI_ACTIVE : 0);
 				else 
-					ui_draw_menu_item(&data->fstyle, &rect, data->items.names[a], data->items.icons[a], (a + 1) == data->active ? UI_ACTIVE : 0);
+					ui_draw_menu_item(&data->fstyle, &rect, data->items.names[a], data->items.icons[a], data->items.unlink_operators[a], (a + 1) == data->active ? UI_ACTIVE : 0);
 			}
 			
 			/* indicate more */
@@ -1022,11 +1057,14 @@
 		else {
 			/* draw items */
 			for (a = 0; a < data->items.totitem; a++) {
+				int state = (a + 1) == data->active ? UI_ACTIVE : 0;
+				if (data->delete_active)
+					state |= UI_BUT_ALIGN_RIGHT;	// Means the delete button is active. I'm overloading it.
+
 				ui_searchbox_butrect(&rect, data, a);
 				
 				/* widget itself */
-				ui_draw_menu_item(&data->fstyle, &rect, data->items.names[a], data->items.icons[a], (a + 1) == data->active ? UI_ACTIVE : 0);
-				
+				ui_draw_menu_item(&data->fstyle, &rect, data->items.names[a], data->items.icons[a], data->items.unlink_operators[a], state);
 			}
 			/* indicate more */
 			if (data->items.more) {
@@ -1057,6 +1095,7 @@
 	MEM_freeN(data->items.names);
 	MEM_freeN(data->items.pointers);
 	MEM_freeN(data->items.icons);
+	MEM_freeN(data->items.unlink_operators);
 	
 	MEM_freeN(data);
 	ar->regiondata = NULL;
@@ -1207,6 +1246,7 @@
 	data->items.names = MEM_callocN(data->items.maxitem * sizeof(void *), "search names");
 	data->items.pointers = MEM_callocN(data->items.maxitem * sizeof(void *), "search pointers");
 	data->items.icons = MEM_callocN(data->items.maxitem * sizeof(int), "search icons");
+	data->items.unlink_operators = MEM_callocN(data->items.maxitem * sizeof(void *), "delete buttons");
 	for (x1 = 0; x1 < data->items.maxitem; x1++)
 		data->items.names[x1] = MEM_callocN(but->hardmax + 1, "search pointers");
 	

Modified: branches/soc-2012-bratwurst/source/blender/editors/interface/interface_templates.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/interface/interface_templates.c	2012-06-19 05:41:22 UTC (rev 48068)
+++ branches/soc-2012-bratwurst/source/blender/editors/interface/interface_templates.c	2012-06-19 06:11:52 UTC (rev 48069)
@@ -97,6 +97,8 @@
 	ListBase *idlb;
 	int prv_rows, prv_cols;
 	int preview;
+
+	const char *unlink_operator;
 } TemplateID;
 
 /* Search browse menu, assign  */
@@ -146,7 +148,7 @@
 
 				iconid = ui_id_icon_get((bContext *)C, id, template->preview);
 
-				if (!uiSearchItemAdd(items, name_ui, id, iconid))
+				if (!uiSearchItemAdd(items, name_ui, id, iconid, template->unlink_operator))
 					break;
 			}
 		}
@@ -352,6 +354,9 @@
 	idfrom = template->ptr.id.data;
 	// lb = template->idlb;
 
+	if (unlinkop)
+		template->unlink_operator = unlinkop;
+
 	block = uiLayoutGetBlock(layout);
 	uiBlockBeginAlign(block);
 
@@ -2557,7 +2562,7 @@
 					}
 				}
 				
-				if (0 == uiSearchItemAdd(items, name, ot, 0))
+				if (0 == uiSearchItemAdd(items, name, ot, 0, NULL))
 					break;
 			}
 		}

Modified: branches/soc-2012-bratwurst/source/blender/editors/interface/interface_widgets.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/interface/interface_widgets.c	2012-06-19 05:41:22 UTC (rev 48068)
+++ branches/soc-2012-bratwurst/source/blender/editors/interface/interface_widgets.c	2012-06-19 06:11:52 UTC (rev 48069)
@@ -3305,15 +3305,30 @@
 
 /* helper call to draw a menu item without button */
 /* state: UI_ACTIVE or 0 */
-void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state)
+void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, struct wmOperatorType* unlink_operator, int state)
 {
 	uiWidgetType *wt = widget_type(UI_WTYPE_MENU_ITEM);
 	rcti _rect = *rect;
+	rcti _rect_thinner = *rect;
 	char *cpoin;
-	
+
+	if (unlink_operator)
+	{
+		if (state & UI_BUT_ALIGN_RIGHT)
+			_rect_thinner.xmin = _rect_thinner.xmax - (ICON_DEFAULT_HEIGHT + 6);
+		else

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list