[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22533] branches/blender2.5/blender/source /blender: 2.5: Added operator ui() callback for defining own ui layout

Brecht Van Lommel brecht at blender.org
Sun Aug 16 22:23:34 CEST 2009


Revision: 22533
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22533
Author:   blendix
Date:     2009-08-16 22:23:34 +0200 (Sun, 16 Aug 2009)

Log Message:
-----------
2.5: Added operator ui() callback for defining own ui layout
to show properties.

* One problem is that we currently have 3 different kinds of
  property layouts, single column, two column, and single column
  with text inside button, probably best to reduce this..
* Last operator panel now shows operator name in the header.
* Fix extrude operator to not include transform properties
  anymore, since they are already there now due to macro system.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/interface/interface_utils.c
    branches/blender2.5/blender/source/blender/editors/mesh/editmesh_tools.c
    branches/blender2.5/blender/source/blender/editors/space_file/file_panels.c
    branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_toolbar.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_windowmanager_types.h
    branches/blender2.5/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_utils.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface_utils.c	2009-08-16 20:14:49 UTC (rev 22532)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface_utils.c	2009-08-16 20:23:34 UTC (rev 22533)
@@ -152,8 +152,6 @@
 	uiLayout *split, *col;
 	char *name;
 
-	uiItemL(layout, (char*)RNA_struct_ui_name(ptr->type), 0);
-
 	RNA_STRUCT_BEGIN(ptr, prop) {
 		if(strcmp(RNA_property_identifier(prop), "rna_type") == 0)
 			continue;

Modified: branches/blender2.5/blender/source/blender/editors/mesh/editmesh_tools.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/mesh/editmesh_tools.c	2009-08-16 20:14:49 UTC (rev 22532)
+++ branches/blender2.5/blender/source/blender/editors/mesh/editmesh_tools.c	2009-08-16 20:23:34 UTC (rev 22533)
@@ -756,11 +756,6 @@
 
 	/* flags */
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-
-	/* to give to transform */
-	Properties_Proportional(ot);
-	Properties_Constraints(ot);
-	RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
 }
 
 static int split_mesh(bContext *C, wmOperator *op)

Modified: branches/blender2.5/blender/source/blender/editors/space_file/file_panels.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_file/file_panels.c	2009-08-16 20:14:49 UTC (rev 22532)
+++ branches/blender2.5/blender/source/blender/editors/space_file/file_panels.c	2009-08-16 20:23:34 UTC (rev 22533)
@@ -170,23 +170,28 @@
 	wmOperator *op= sfile->op;
 	int empty= 1;
 
-	RNA_STRUCT_BEGIN(op->ptr, prop) {
-		if(strcmp(RNA_property_identifier(prop), "rna_type") == 0)
-			continue;
-		if(strcmp(RNA_property_identifier(prop), "filename") == 0)
-			continue;
-		if(strcmp(RNA_property_identifier(prop), "display") == 0)
-			continue;
-		if(strncmp(RNA_property_identifier(prop), "filter", 6) == 0)
-			continue;
+	if(op->type->ui) {
+		op->type->ui((bContext*)C, op->ptr, pa->layout);
+	}
+	else {
+		RNA_STRUCT_BEGIN(op->ptr, prop) {
+			if(strcmp(RNA_property_identifier(prop), "rna_type") == 0)
+				continue;
+			if(strcmp(RNA_property_identifier(prop), "filename") == 0)
+				continue;
+			if(strcmp(RNA_property_identifier(prop), "display") == 0)
+				continue;
+			if(strncmp(RNA_property_identifier(prop), "filter", 6) == 0)
+				continue;
 
-		uiItemFullR(pa->layout, NULL, 0, op->ptr, prop, -1, 0, 0, 0, 0);
-		empty= 0;
+			uiItemFullR(pa->layout, NULL, 0, op->ptr, prop, -1, 0, 0, 0, 0);
+			empty= 0;
+		}
+		RNA_STRUCT_END;
+
+		if(empty)
+			uiItemL(pa->layout, "No properties.", 0);
 	}
-	RNA_STRUCT_END;
-
-	if(empty)
-		uiItemL(pa->layout, "No properties.", 0);
 }
 
 void file_panels_register(ARegionType *art)

Modified: branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_toolbar.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_toolbar.c	2009-08-16 20:14:49 UTC (rev 22532)
+++ branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_toolbar.c	2009-08-16 20:23:34 UTC (rev 22533)
@@ -118,6 +118,19 @@
 	}
 }
 
+static wmOperator *view3d_last_operator(const bContext *C)
+{
+	wmWindowManager *wm= CTX_wm_manager(C);
+	wmOperator *op;
+
+	/* only for operators that are registered and did an undo push */
+	for(op= wm->operators.last; op; op= op->prev)
+		if((op->type->flag & OPTYPE_REGISTER) && (op->type->flag & OPTYPE_UNDO))
+			break;
+
+	return op;
+}
+
 static void view3d_panel_operator_redo_buts(const bContext *C, Panel *pa, wmOperator *op)
 {
 	wmWindowManager *wm= CTX_wm_manager(C);
@@ -129,28 +142,32 @@
 	}
 	
 	RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
-	uiDefAutoButsRNA(C, pa->layout, &ptr, 1);
-	
+	if(op->type->ui)
+		op->type->ui((bContext*)C, &ptr, pa->layout);
+	else
+		uiDefAutoButsRNA(C, pa->layout, &ptr, 1);
 }
 
+static void view3d_panel_operator_redo_header(const bContext *C, Panel *pa)
+{
+	wmOperator *op= view3d_last_operator(C);
+
+	if(op) BLI_strncpy(pa->drawname, op->type->name, sizeof(pa->drawname));
+	else BLI_strncpy(pa->drawname, "Operator", sizeof(pa->drawname));
+}
+
 static void view3d_panel_operator_redo(const bContext *C, Panel *pa)
 {
-	wmWindowManager *wm= CTX_wm_manager(C);
-	wmOperator *op;
+	wmOperator *op= view3d_last_operator(C);
 	uiBlock *block;
 	
-	block= uiLayoutGetBlock(pa->layout);
-
-	/* only for operators that are registered and did an undo push */
-	for(op= wm->operators.last; op; op= op->prev)
-		if((op->type->flag & OPTYPE_REGISTER) && (op->type->flag & OPTYPE_UNDO))
-			break;
-	
 	if(op==NULL)
 		return;
 	if(op->type->poll && op->type->poll((bContext *)C)==0)
 		return;
 	
+	block= uiLayoutGetBlock(pa->layout);
+
 	uiBlockSetFunc(block, redo_cb, op, NULL);
 	
 	if(op->macro.first) {
@@ -279,7 +296,8 @@
 	
 	pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel last operator");
 	strcpy(pt->idname, "VIEW3D_PT_last_operator");
-	strcpy(pt->label, "Last Operator");
+	strcpy(pt->label, "Operator");
+	pt->draw_header= view3d_panel_operator_redo_header;
 	pt->draw= view3d_panel_operator_redo;
 	BLI_addtail(&art->paneltypes, pt);
 }

Modified: branches/blender2.5/blender/source/blender/makesdna/DNA_windowmanager_types.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesdna/DNA_windowmanager_types.h	2009-08-16 20:14:49 UTC (rev 22532)
+++ branches/blender2.5/blender/source/blender/makesdna/DNA_windowmanager_types.h	2009-08-16 20:23:34 UTC (rev 22533)
@@ -54,6 +54,7 @@
 struct PointerRNA;
 struct ReportList;
 struct Report;
+struct uiLayout;
 
 #define OP_MAX_TYPENAME	64
 #define KMAP_MAX_NAME	64
@@ -208,8 +209,8 @@
 	 * that the operator might still fail to execute even if this return true */
 	int (*poll)(struct bContext *);
 	
-	/* panel for redo and repeat */
-	void *(*uiBlock)(struct wmOperator *);
+	/* optional panel for redo and repeat, autogenerated if not set */
+	void (*ui)(struct bContext *, struct PointerRNA *, struct uiLayout *);
 	
 	/* rna for properties */
 	struct StructRNA *srna;

Modified: branches/blender2.5/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- branches/blender2.5/blender/source/blender/windowmanager/intern/wm_operators.c	2009-08-16 20:14:49 UTC (rev 22532)
+++ branches/blender2.5/blender/source/blender/windowmanager/intern/wm_operators.c	2009-08-16 20:23:34 UTC (rev 22533)
@@ -543,8 +543,13 @@
 
 	RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
 	layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 300, 20, style);
-	uiDefAutoButsRNA(C, layout, &ptr, 2);
+	uiItemL(layout, op->type->name, 0);
 
+	if(op->type->ui)
+		op->type->ui((bContext*)C, &ptr, layout);
+	else
+		uiDefAutoButsRNA(C, layout, &ptr, 2);
+
 	uiPopupBoundsBlock(block, 4.0f, 0, 0);
 	uiEndBlock(C, block);
 
@@ -585,7 +590,12 @@
 	uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1);
 	
 	layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 300, 20, style);
-	uiDefAutoButsRNA(C, layout, op->ptr, 2);
+	uiItemL(layout, op->type->name, 0);
+
+	if(op->type->ui)
+		op->type->ui(C, op->ptr, layout);
+	else
+		uiDefAutoButsRNA(C, layout, op->ptr, 2);
 	
 	uiPopupBoundsBlock(block, 4.0f, 0, 0);
 	uiEndBlock(C, block);





More information about the Bf-blender-cvs mailing list