[Bf-blender-cvs] [1b400c13645] topbar: Only add "More..." button when there are advanced operator properties

Julian Eisel noreply at git.blender.org
Thu Nov 23 18:27:40 CET 2017


Commit: 1b400c13645d0d398f85dd39c924967dfcaa7eff
Author: Julian Eisel
Date:   Thu Nov 23 18:26:50 2017 +0100
Branches: topbar
https://developer.blender.org/rB1b400c13645d0d398f85dd39c924967dfcaa7eff

Only add "More..." button when there are advanced operator properties

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/interface/interface_utils.c

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 0aa5c9a3fe6..51a98c47718 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -699,8 +699,16 @@ typedef enum {
 	UI_BUT_LABEL_ALIGN_SPLIT_COLUMN,
 } eButLabelAlign;
 
+/* Return info for uiDefAutoButsRNA */
+typedef enum {
+	/* Returns when no buttons were added */
+	UI_PROP_BUTS_NONE_ADDED       = (1 << 0),
+	/* Returned when any property failed the custom check callback (check_prop) */
+	UI_PROP_BUTS_ANY_FAILED_CHECK = (1 << 1),
+} eAutoPropButsReturn;
+
 uiBut *uiDefAutoButR(uiBlock *block, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, const char *name, int icon, int x1, int y1, int x2, int y2);
-int uiDefAutoButsRNA(
+eAutoPropButsReturn uiDefAutoButsRNA(
         uiLayout *layout, struct PointerRNA *ptr,
         bool (*check_prop)(struct PointerRNA *, struct PropertyRNA *),
         eButLabelAlign label_align, const bool compact);
@@ -867,8 +875,6 @@ enum {
 	UI_TEMPLATE_OP_PROPS_SHOW_TITLE       = (1 << 0),
 	UI_TEMPLATE_OP_PROPS_SHOW_EMPTY       = (1 << 1),
 	UI_TEMPLATE_OP_PROPS_COMPACT          = (1 << 2),
-	/* Don't show advanced properties */
-	UI_TEMPLATE_OP_PROPS_SKIP_ADVANCED    = (1 << 3),
 };
 
 /* used for transp checkers */
@@ -994,7 +1000,7 @@ void uiTemplateImageInfo(uiLayout *layout, struct bContext *C, struct Image *ima
 void uiTemplateRunningJobs(uiLayout *layout, struct bContext *C);
 void UI_but_func_operator_search(uiBut *but);
 void uiTemplateOperatorSearch(uiLayout *layout);
-void uiTemplateOperatorPropertyButs(
+eAutoPropButsReturn uiTemplateOperatorPropertyButs(
         const struct bContext *C, uiLayout *layout, struct wmOperator *op,
         bool (*check_prop)(struct PointerRNA *, struct PropertyRNA *),
         const eButLabelAlign label_align, const short flag);
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 3fcadd8081a..a89dbe387bd 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -1418,18 +1418,22 @@ static bool template_operator_redo_property_buts_poll(PointerRNA *UNUSED(ptr), P
 
 static void template_operator_redo_property_buts_draw(
         const bContext *C, wmOperator *op,
-        uiLayout *layout, int layout_flags)
+        uiLayout *layout, int layout_flags,
+        bool *r_has_advanced)
 {
 	if (op->type->flag & OPTYPE_MACRO) {
 		for (wmOperator *macro_op = op->macro.first; macro_op; macro_op = macro_op->next) {
-			template_operator_redo_property_buts_draw(C, macro_op, layout, layout_flags);
+			template_operator_redo_property_buts_draw(C, macro_op, layout, layout_flags, r_has_advanced);
 		}
 	}
 	else {
 		/* Might want to make label_align adjustable somehow. */
-		uiTemplateOperatorPropertyButs(
-	                        C, layout, op, template_operator_redo_property_buts_poll,
-	                        UI_BUT_LABEL_ALIGN_NONE, layout_flags);
+		eAutoPropButsReturn return_info = uiTemplateOperatorPropertyButs(
+		                                          C, layout, op, template_operator_redo_property_buts_poll,
+		                                          UI_BUT_LABEL_ALIGN_NONE, layout_flags);
+		if (return_info & UI_PROP_BUTS_ANY_FAILED_CHECK) {
+			*r_has_advanced = true;
+		}
 	}
 }
 
@@ -1437,7 +1441,6 @@ void uiTemplateOperatorRedoProperties(uiLayout *layout, bContext *C)
 {
 	wmOperator *op = WM_operator_last_redo(C);
 	uiBlock *block = uiLayoutGetBlock(layout);
-	const int layout_flags = (UI_TEMPLATE_OP_PROPS_COMPACT | UI_TEMPLATE_OP_PROPS_SKIP_ADVANCED);
 
 	if (op) {
 		/* Repeat button with operator name as text. */
@@ -1445,9 +1448,12 @@ void uiTemplateOperatorRedoProperties(uiLayout *layout, bContext *C)
 		            ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0, NULL);
 
 		if (WM_operator_repeat_check(C, op)) {
-			template_operator_redo_property_buts_draw(C, op, layout, layout_flags);
-			/* TODO check whether there are hidden advanced properties at all */
-			uiItemO(layout, IFACE_("More..."), ICON_NONE, "SCREEN_OT_redo_last");
+			bool has_advanced = false;
+
+			template_operator_redo_property_buts_draw(C, op, layout, UI_TEMPLATE_OP_PROPS_COMPACT, &has_advanced);
+			if (has_advanced) {
+				uiItemO(layout, IFACE_("More..."), ICON_NONE, "SCREEN_OT_redo_last");
+			}
 		}
 
 		UI_block_func_handle_set(block, ED_undo_operator_repeat_cb_evt, op);
@@ -3808,12 +3814,13 @@ static void ui_layout_operator_buts__reset_cb(bContext *UNUSED(C), void *op_pt,
  * Draw Operator property buttons for redoing execution with different settings.
  * This function does not initialize the layout, functions can be called on the layout before and after.
  */
-void uiTemplateOperatorPropertyButs(
+eAutoPropButsReturn uiTemplateOperatorPropertyButs(
         const bContext *C, uiLayout *layout, wmOperator *op,
         bool (*check_prop)(struct PointerRNA *, struct PropertyRNA *),
         const eButLabelAlign label_align, const short flag)
 {
 	uiBlock *block = uiLayoutGetBlock(layout);
+	eAutoPropButsReturn return_info = 0;
 
 	if (!op->properties) {
 		IDPropertyTemplate val = {0};
@@ -3862,19 +3869,19 @@ void uiTemplateOperatorPropertyButs(
 		op->type->ui((bContext *)C, op);
 		op->layout = NULL;
 
-		/* UI_LAYOUT_OP_SHOW_EMPTY ignored */
+		/* UI_LAYOUT_OP_SHOW_EMPTY ignored. return_info is ignored too. We could
+		 * allow ot.ui callback to return this, but not needed right now. */
 	}
 	else {
 		wmWindowManager *wm = CTX_wm_manager(C);
 		PointerRNA ptr;
-		int empty;
 
 		RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
 
 		/* main draw call */
-		empty = uiDefAutoButsRNA(layout, &ptr, check_prop, label_align, (flag & UI_TEMPLATE_OP_PROPS_COMPACT)) == 0;
+		return_info = uiDefAutoButsRNA(layout, &ptr, check_prop, label_align, (flag & UI_TEMPLATE_OP_PROPS_COMPACT));
 
-		if (empty && (flag & UI_TEMPLATE_OP_PROPS_SHOW_EMPTY)) {
+		if ((return_info & UI_PROP_BUTS_NONE_ADDED) && (flag & UI_TEMPLATE_OP_PROPS_SHOW_EMPTY)) {
 			uiItemL(layout, IFACE_("No Properties"), ICON_NONE);
 		}
 	}
@@ -3915,6 +3922,8 @@ void uiTemplateOperatorPropertyButs(
 			}
 		}
 	}
+
+	return return_info;
 }
 
 /************************* Running Jobs Template **************************/
diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c
index 19ebb16d985..f28da5a666b 100644
--- a/source/blender/editors/interface/interface_utils.c
+++ b/source/blender/editors/interface/interface_utils.c
@@ -157,21 +157,27 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind
  * \a check_prop callback filters functions to avoid drawing certain properties,
  * in cases where PROP_HIDDEN flag can't be used for a property.
  */
-int uiDefAutoButsRNA(
+eAutoPropButsReturn uiDefAutoButsRNA(
         uiLayout *layout, PointerRNA *ptr,
         bool (*check_prop)(PointerRNA *, PropertyRNA *),
         const eButLabelAlign label_align, const bool compact)
 {
+	eAutoPropButsReturn return_info = UI_PROP_BUTS_NONE_ADDED;
 	uiLayout *split, *col;
 	int flag;
 	const char *name;
-	int tot = 0;
 
 	RNA_STRUCT_BEGIN (ptr, prop)
 	{
 		flag = RNA_property_flag(prop);
-		if (flag & PROP_HIDDEN || (check_prop && check_prop(ptr, prop) == 0))
+
+		if (flag & PROP_HIDDEN) {
+			continue;
+		}
+		if (check_prop && check_prop(ptr, prop) == 0) {
+			return_info |= UI_PROP_BUTS_ANY_FAILED_CHECK;
 			continue;
+		}
 
 		switch (label_align) {
 			case UI_BUT_LABEL_ALIGN_COLUMN:
@@ -212,11 +218,11 @@ int uiDefAutoButsRNA(
 		}
 
 		uiItemFullR(col, ptr, prop, -1, 0, compact ? UI_ITEM_R_COMPACT : 0, name, ICON_NONE);
-		tot++;
+		return_info &= ~UI_PROP_BUTS_NONE_ADDED;
 	}
 	RNA_STRUCT_END;
 
-	return tot;
+	return return_info;
 }
 
 /* *** RNA collection search menu *** */



More information about the Bf-blender-cvs mailing list