[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60045] branches/soc-2013-ui_replay: Added dividers and made the tool shelf context dependent

Vincent Akkermans vincent at ack-err.net
Wed Sep 11 14:13:21 CEST 2013


Revision: 60045
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60045
Author:   ack-err
Date:     2013-09-11 12:13:20 +0000 (Wed, 11 Sep 2013)
Log Message:
-----------
Added dividers and made the tool shelf context dependent

Modified Paths:
--------------
    branches/soc-2013-ui_replay/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h
    branches/soc-2013-ui_replay/source/blender/editors/interface/interface_handlers.c
    branches/soc-2013-ui_replay/source/blender/editors/interface/interface_layout.c
    branches/soc-2013-ui_replay/source/blender/editors/screen/area.c
    branches/soc-2013-ui_replay/source/blender/editors/space_view3d/space_view3d.c
    branches/soc-2013-ui_replay/source/blender/makesdna/DNA_screen_types.h
    branches/soc-2013-ui_replay/source/blender/windowmanager/intern/wm_operators.c

Modified: branches/soc-2013-ui_replay/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2013-ui_replay/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-09-11 11:43:43 UTC (rev 60044)
+++ branches/soc-2013-ui_replay/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-09-11 12:13:20 UTC (rev 60045)
@@ -183,11 +183,11 @@
 
         col = layout.column(align=True)
         row = col.row(align=True, button_height=1.5)
-        row.operator("wm.call_menu", text="", single_unit=False, shortcut=False, icon='TOOLBAR_ADD').name = 'INFO_MT_mesh_add'
-        row.operator("wm.call_menu", text="", single_unit=False, shortcut=False, icon='TOOLBAR_DELETE').name = 'VIEW3D_MT_edit_mesh_delete'
+        row.operator("wm.call_menu", text="", single_unit=False, shortcut=False, icon='ADD').name = 'INFO_MT_mesh_add'
+        row.operator("wm.call_menu", text="", single_unit=False, shortcut=False, icon='DELETE').name = 'VIEW3D_MT_edit_mesh_delete'
         
         col = layout.column(align=True)
-        col.operator("mesh.duplicate_move", text="Duplicate", single_unit=False, icon='TOOLBAR_DUP')
+        col.operator("mesh.duplicate_move", text="Duplicate", single_unit=False, icon='DUP')
 
 class VIEW3D_PT_tools_editmode_mesh(View3DPanel, Panel):
     bl_context = "mesh_edit"
@@ -198,8 +198,8 @@
 
         col = layout.column(align=True)
         row = col.row(align=True, button_height=1.5)
-        row.operator("view3d.edit_mesh_extrude_move_normal", text="", single_unit=False, shortcut=False, icon='EXTRUDE_REGION')
-        row.operator("view3d.edit_mesh_extrude_individual_move", text="", single_unit=False, shortcut=False, icon='EXTRUDE_INDIVIDUAL')
+        row.operator("view3d.edit_mesh_extrude_move_normal", text="", single_unit=False, shortcut=False)
+        row.operator("view3d.edit_mesh_extrude_individual_move", text="", single_unit=False, shortcut=False)
         col.operator("wm.call_menu", text="Extrude...", single_unit=False, shortcut=False).name = 'VIEW3D_MT_edit_mesh_extrude'
 
         col = layout.column(align=True)
@@ -209,7 +209,7 @@
         props.use_occlude_geometry = True
         props.only_selected = False
         
-        row.operator("mesh.loopcut_slide", text="", single_unit=False, shortcut=False, icon='LOOP_CUT')
+        row.operator("mesh.loopcut_slide", text="", single_unit=False, shortcut=False, icon='LOOPCUT')
         
         props = col.operator("mesh.knife_tool", text="Knife select")
         props.use_occlude_geometry = False

Modified: branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h	2013-09-11 11:43:43 UTC (rev 60044)
+++ branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h	2013-09-11 12:13:20 UTC (rev 60045)
@@ -907,7 +907,7 @@
 void uiItemMenuEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, const char *name, int icon);
 
 /* OperatorListItem utilities */
-struct OperatorListItem *uiOperatorListItemPresent(ListBase *lb, const char *idname, IDProperty *properties);
+struct OperatorListItem *uiOperatorListItemPresent(ListBase *lb, const char *idname, IDProperty *properties, const char *context);
 struct OperatorListItem *uiRegionDraggedOperatorListItem(struct ARegion *ar);
 int uiRegionDraggedNewIndex(struct ARegion *ar);
 

Modified: branches/soc-2013-ui_replay/source/blender/editors/interface/interface_handlers.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/interface/interface_handlers.c	2013-09-11 11:43:43 UTC (rev 60044)
+++ branches/soc-2013-ui_replay/source/blender/editors/interface/interface_handlers.c	2013-09-11 12:13:20 UTC (rev 60045)
@@ -5101,6 +5101,31 @@
 	ED_region_tag_redraw(ar);
 }
 
+static void add_divider_to_icon_shelf(bContext *C, void *arg_ot, void *arg_opptr)
+{
+	ARegion *ar = CTX_wm_region(C);
+	wmOperatorType *ot = arg_ot;
+	PointerRNA *opptr = (PointerRNA*)arg_opptr;
+	OperatorListItem *oli = uiOperatorListItemPresent(&ar->operators, ot->idname, opptr->data, CTX_data_mode_string(C));
+	OperatorListItem *div;
+	
+	/*
+	 * Only add a divider if:
+	 * - the current button is not a divider
+	 * - the current button does not have a divider in front of it already
+	 */
+	if (oli && !(oli->flag & OLI_DIVIDER) &&
+		!(oli->prev != NULL && ((OperatorListItem*)(oli->prev))->flag & OLI_DIVIDER)) {
+		div = MEM_callocN(sizeof(OperatorListItem), "OperatorListItem divider");
+		div->flag |= OLI_DIVIDER;
+		BLI_strncpy(div->context, CTX_data_mode_string(C), MAX_NAME);
+		
+		BLI_insertlinkbefore(&ar->operators, oli, div);
+	}
+	
+	ED_region_tag_redraw(ar);
+}
+
 static bool ui_but_menu(bContext *C, uiBut *but)
 {
 	uiPopupMenu *pup;
@@ -5357,22 +5382,34 @@
 			
 			/* Remove the operator from the custom enclosure */
 			if (ar->regiontype == RGN_TYPE_TOOLS) {
-				opp_but = uiDefIconTextBut(block, BUT, 0, ICON_NONE, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Remove From Panel"), 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
+				opp_but = uiDefIconTextBut(block, BUT, 0, ICON_NONE,
+										   CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Remove From Panel"),
+										   0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
 				uiButSetFunc(opp_but, remove_from_custom_panel, pa, but->optype);
 				uiItemS(layout);
 			}
 			else if (ar->regiontype == RGN_TYPE_MENU_BAR &&
-					 uiOperatorListItemPresent(&ar->operators, but->optype->idname, but->opptr->data)) {
-				opp_but = uiDefIconTextBut(block, BUT, 0, ICON_NONE, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Remove From Icon Shelf"), 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
+					 uiOperatorListItemPresent(&ar->operators, but->optype->idname, but->opptr->data, CTX_data_mode_string(C))) {
+				opp_but = uiDefIconTextBut(block, BUT, 0, ICON_NONE,
+										   CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add Divider to the Left"),
+										   0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
+				uiButSetFunc(opp_but, add_divider_to_icon_shelf, but->optype, but->opptr);
+				
+				opp_but = uiDefIconTextBut(block, BUT, 0, ICON_NONE,
+										   CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Remove From Icon Shelf"),
+										   0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
 				uiButSetFunc(opp_but, remove_from_icon_shelf, but->optype, but->opptr);
 				uiItemS(layout);
 			}
 			
-			opp_but = uiDefIconTextBut(block, BUT, 0, ICON_NONE, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add to Icon Shelf"), 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
-			uiButSetFunc(opp_but, add_to_icon_shelf, but->optype, but->opptr);
+			if (ar->regiontype != RGN_TYPE_MENU_BAR) {
+				opp_but = uiDefIconTextBut(block, BUT, 0, ICON_NONE,
+										   CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add to Icon Shelf"),
+										   0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
+				uiButSetFunc(opp_but, add_to_icon_shelf, but->optype, but->opptr);
+			}
 			
 			uiItemMenuF(layout, IFACE_("Add to Custom Panel..."), ICON_NONE, add_to_custom_panel_menu, but->optype);
-			
 		}
 		
 		uiItemS(layout);
@@ -7661,15 +7698,29 @@
 {
 	uiHandleRegionDragData *data = ar->dragdata;
 	int cur_index = BLI_findindex(&ar->operators, data->oli);
-	int dx, dunits, maxindex;
-	
+	OperatorListItem *oli_iter = data->oli;
+	int dx, dunits, dunits_iter, extra_units = 0, maxindex;
+
 	// Calculate the new index of the button based on the drag offset
-	dx = data->startx - event->x;
+	dx = event->x - data->startx;
 	dunits = dx / (UI_UNIT_X * 1.5); // TODO: make sure this factor corresponds to menubar button sizes
-	data->newindex = (cur_index - dunits);
+	
+	// Offset the new index by the interleaved list items that aren't shown in the current contex
+	dunits_iter = dunits;
+	while (dunits_iter != 0) {
+		oli_iter = dunits < 0 ? oli_iter->prev : oli_iter->next;
+		if (oli_iter == NULL) break;
+		if (strcmp(oli_iter->context, CTX_data_mode_string(C)) != 0)
+			extra_units += (dunits < 0 ? -1 : 1);
+		dunits_iter += (dunits < 0 ? 1 : -1);
+	}
+	
+	data->newindex = (cur_index + dunits) + extra_units;
 	maxindex = (BLI_countlist(&ar->operators) - 1);
 	CLAMP(data->newindex, 0, maxindex);
 	
+	printf("dx: %i dunits: %i extra_units: %i newindex: %i\n", dx, dunits, extra_units, data->newindex);
+	
 	ED_region_tag_redraw(ar);
 }
 
@@ -7751,7 +7802,8 @@
 			 * global drag */
 			if (data->state == REGION_STATE_DRAG_BUTTON) {
 				uiBut *but = ui_but_find_activated(ar);
-				ui_button_active_free(C, but);
+				if (but)
+					ui_button_active_free(C, but);
 			}
 			
 			MEM_freeN(data);
@@ -7765,7 +7817,7 @@
 			uiBut *but = ui_but_find_activated(ar);
 			
 			if (but->optype) {
-				oli = uiOperatorListItemPresent(&ar->operators, but->optype->idname, but->opptr ? but->opptr->data : NULL);
+				oli = uiOperatorListItemPresent(&ar->operators, but->optype->idname, but->opptr ? but->opptr->data : NULL, CTX_data_mode_string(C));
 				
 				if (oli) {
 					data = MEM_callocN(sizeof(uiHandleRegionDragData), "uiHandleRegionDragData");

Modified: branches/soc-2013-ui_replay/source/blender/editors/interface/interface_layout.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/interface/interface_layout.c	2013-09-11 11:43:43 UTC (rev 60044)
+++ branches/soc-2013-ui_replay/source/blender/editors/interface/interface_layout.c	2013-09-11 12:13:20 UTC (rev 60045)
@@ -1825,24 +1825,28 @@
 /********************* OperatorListItem utilities ********************/
 
 /* return 1 when an OperatorListItem with the same name and properties is already present in lb */
-OperatorListItem *uiOperatorListItemPresent(ListBase *lb, const char *idname, IDProperty *properties)
+OperatorListItem *uiOperatorListItemPresent(ListBase *lb, const char *idname, IDProperty *properties, const char *context)
 {
 	OperatorListItem *oli;
 	
 	for (oli = lb->first; oli; oli = oli->next) {
 		
 		if (strcmp(oli->optype_idname, idname) == 0) {
-			/* if no idprops are present, and the name is the same */
-			if (oli->properties == NULL && properties == NULL) {
-				return oli;
+			if (strcmp(oli->context, context) == 0) {
+				/* if no idprops are present, and the name is the same */

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list