[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57316] trunk/blender/source/blender: This commit replaces old "manual" Editors menu with nice RNA-based one ( so once again, some cleanup of old UI code).

Bastien Montagne montagne29 at wanadoo.fr
Sun Jun 9 18:18:24 CEST 2013


Revision: 57316
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57316
Author:   mont29
Date:     2013-06-09 16:18:23 +0000 (Sun, 09 Jun 2013)
Log Message:
-----------
This commit replaces old "manual" Editors menu with nice RNA-based one (so once again, some cleanup of old UI code). It makes the following changes:

* RNA's editor types enum (space_type_items) has been re-ordered, added icons, and removed internal-only SPACE_EMPTY value, so that it matches the menu.

* Two fixes in code drawing enums as dropdown menu:
** All items were taken into account when computing the number of needed columns, now simple separators (void string items) are ignored.
** Simple separators items were drawn as labels, taking far too much space!

And now translators will be free from that ugly, insane menu-string! :P

Thanks to Brecht for the review.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/interface_regions.c
    trunk/blender/source/blender/editors/screen/area.c
    trunk/blender/source/blender/makesrna/intern/rna_screen.c
    trunk/blender/source/blender/makesrna/intern/rna_space.c

Modified: trunk/blender/source/blender/editors/interface/interface_regions.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_regions.c	2013-06-09 15:17:03 UTC (rev 57315)
+++ trunk/blender/source/blender/editors/interface/interface_regions.c	2013-06-09 16:18:23 UTC (rev 57316)
@@ -1768,18 +1768,34 @@
 	const char *instr = arg_str;
 	int columns, rows, a, b;
 	int column_start = 0, column_end = 0;
+	int nbr_entries_nosepr = 0;
 
 	uiBlockSetFlag(block, UI_BLOCK_MOVEMOUSE_QUIT);
 	
 	/* compute menu data */
 	md = decompose_menu_string(instr);
 
-	/* columns and row estimation */
-	columns = (md->nitems + 20) / 20;
+	/* Run some "tweaking" checks. */
+	entry = md->items;
+	for (a = 0; a < md->nitems; a++, entry++) {
+		if (entry->sepr) {
+			/* inconsistent, but menus with labels do not look good flipped */
+			if (entry->str[0]) {
+				block->flag |= UI_BLOCK_NO_FLIP;
+				nbr_entries_nosepr++;
+			}
+			/* We do not want simple separators in nbr_entries_nosepr count */
+			continue;
+		}
+		nbr_entries_nosepr++;
+	}
+
+	/* Columns and row estimation. Ignore simple separators here. */
+	columns = (nbr_entries_nosepr + 20) / 20;
 	if (columns < 1)
 		columns = 1;
 	if (columns > 8)
-		columns = (md->nitems + 25) / 25;
+		columns = (nbr_entries_nosepr + 25) / 25;
 
 	rows = md->nitems / columns;
 	if (rows < 1)
@@ -1799,15 +1815,6 @@
 		}
 	}
 
-	/* inconsistent, but menus with labels do not look good flipped */
-	entry = md->items;
-	for (a = 0; a < md->nitems; a++, entry++) {
-		if (entry->sepr && entry->str[0]) {
-			block->flag |= UI_BLOCK_NO_FLIP;
-			break;
-		}
-	}
-
 	/* create items */
 	split = uiLayoutSplit(layout, 0.0f, FALSE);
 
@@ -1837,9 +1844,14 @@
 			entry = &md->items[column_start + column_end - 1 - a];
 
 		if (entry->sepr) {
-			uiItemL(column, entry->str, entry->icon);
-			bt = block->buttons.last;
-			bt->flag = UI_TEXT_LEFT;
+			if (entry->str[0]) {
+				uiItemL(column, entry->str, entry->icon);
+				bt = block->buttons.last;
+				bt->flag = UI_TEXT_LEFT;
+			}
+			else {
+				uiItemS(column);
+			}
 		}
 		else if (entry->icon) {
 			uiDefIconTextButF(block, BUTM, B_NOP, entry->icon, entry->str, 0, 0,

Modified: trunk/blender/source/blender/editors/screen/area.c
===================================================================
--- trunk/blender/source/blender/editors/screen/area.c	2013-06-09 15:17:03 UTC (rev 57315)
+++ trunk/blender/source/blender/editors/screen/area.c	2013-06-09 16:18:23 UTC (rev 57316)
@@ -46,6 +46,9 @@
 #include "BKE_global.h"
 #include "BKE_screen.h"
 
+#include "RNA_access.h"
+#include "RNA_types.h"
+
 #include "WM_api.h"
 #include "WM_types.h"
 #include "wm_subwindow.h"
@@ -1494,71 +1497,19 @@
 	WM_event_add_notifier(C, NC_SPACE | ND_SPACE_CHANGED, sa);
 }
 
-static const char *editortype_pup(void)
-{
-	const char *types = N_(
-	    "Editor type: %t"
-	    "|3D View %x1"
-
-	    "|%l"
-
-	    "|Timeline %x15"
-	    "|Graph Editor %x2"
-	    "|Dope Sheet %x12"
-	    "|NLA Editor %x13"
-
-	    "|%l"
-
-	    "|UV/Image Editor %x6"
-
-	    "|Video Sequence Editor %x8"
-	    "|Movie Clip Editor %x20"
-	    "|Text Editor %x9"
-	    "|Node Editor %x16"
-	    "|Logic Editor %x17"
-
-	    "|%l"
-
-	    "|Properties %x4"
-	    "|Outliner %x3"
-	    "|User Preferences %x19"
-	    "|Info %x7"
-
-	    "|%l"
-
-	    "|File Browser %x5"
-
-	    "|%l"
-
-	    "|Python Console %x18"
-	    );
-
-	return IFACE_(types);
-}
-
-static void spacefunc(struct bContext *C, void *UNUSED(arg1), void *UNUSED(arg2))
-{
-	ED_area_newspace(C, CTX_wm_area(C), CTX_wm_area(C)->butspacetype);
-	ED_area_tag_redraw(CTX_wm_area(C));
-
-	/* send space change notifier */
-	WM_event_add_notifier(C, NC_SPACE | ND_SPACE_CHANGED, CTX_wm_area(C));
-}
-
 /* returns offset for next button in header */
 int ED_area_header_switchbutton(const bContext *C, uiBlock *block, int yco)
 {
 	ScrArea *sa = CTX_wm_area(C);
-	uiBut *but;
+	bScreen *scr = CTX_wm_screen(C);
+	PointerRNA areaptr;
 	int xco = 0.4 * U.widget_unit;
-	
-	but = uiDefIconTextButC(block, ICONTEXTROW, 0, ICON_VIEW3D, 
-	                        editortype_pup(), xco, yco, 1.5 * U.widget_unit, U.widget_unit,
-	                        &(sa->butspacetype), 1.0, SPACEICONMAX, 0, 0,
-	                        TIP_("Display current editor type (click for a menu of available types)"));
-	uiButSetFunc(but, spacefunc, NULL, NULL);
-	uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */
-	
+
+	RNA_pointer_create(&(scr->id), &RNA_Area, sa, &areaptr);
+
+	uiDefButR(block, MENU, 0, NULL, xco, yco, 1.5 * U.widget_unit, U.widget_unit,
+	          &areaptr, "type", 0, 0.0f, 0.0f, 0.0f, 0.0f, "");
+
 	return xco + 1.7 * U.widget_unit;
 }
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_screen.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_screen.c	2013-06-09 15:17:03 UTC (rev 57315)
+++ trunk/blender/source/blender/makesrna/intern/rna_screen.c	2013-06-09 16:18:23 UTC (rev 57316)
@@ -105,6 +105,7 @@
 	return (sc->full != 0);
 }
 
+
 static void rna_Area_type_set(PointerRNA *ptr, int value)
 {
 	ScrArea *sa = (ScrArea *)ptr->data;
@@ -204,8 +205,9 @@
 	RNA_def_property_enum_sdna(prop, NULL, "spacetype");
 	RNA_def_property_enum_items(prop, space_type_items);
 	RNA_def_property_enum_funcs(prop, NULL, "rna_Area_type_set", NULL);
-	RNA_def_property_ui_text(prop, "Type", "Space type");
+	RNA_def_property_ui_text(prop, "Editor Type", "Current editor type for this area");
 	RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 	RNA_def_property_update(prop, 0, "rna_Area_type_update");
 
 	prop = RNA_def_property(srna, "x", PROP_INT, PROP_NONE);

Modified: trunk/blender/source/blender/makesrna/intern/rna_space.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_space.c	2013-06-09 15:17:03 UTC (rev 57315)
+++ trunk/blender/source/blender/makesrna/intern/rna_space.c	2013-06-09 16:18:23 UTC (rev 57316)
@@ -58,25 +58,30 @@
 
 #include "RNA_enum_types.h"
 
+
 EnumPropertyItem space_type_items[] = {
-	{SPACE_EMPTY, "EMPTY", 0, "Empty", ""},
-	{SPACE_VIEW3D, "VIEW_3D", 0, "3D View", ""},
-	{SPACE_IPO, "GRAPH_EDITOR", 0, "Graph Editor", ""},
-	{SPACE_OUTLINER, "OUTLINER", 0, "Outliner", ""},
-	{SPACE_BUTS, "PROPERTIES", 0, "Properties", ""},
-	{SPACE_FILE, "FILE_BROWSER", 0, "File Browser", ""},
-	{SPACE_IMAGE, "IMAGE_EDITOR", 0, "Image Editor", ""},
-	{SPACE_INFO, "INFO", 0, "Info", ""},
-	{SPACE_SEQ, "SEQUENCE_EDITOR", 0, "Sequence Editor", ""},
-	{SPACE_TEXT, "TEXT_EDITOR", 0, "Text Editor", ""},
-	{SPACE_ACTION, "DOPESHEET_EDITOR", 0, "Dope Sheet Editor", ""},
-	{SPACE_NLA, "NLA_EDITOR", 0, "NLA Editor", ""},
-	{SPACE_TIME, "TIMELINE", 0, "Timeline", ""},
-	{SPACE_NODE, "NODE_EDITOR", 0, "Node Editor", ""},
-	{SPACE_LOGIC, "LOGIC_EDITOR", 0, "Logic Editor", ""},
-	{SPACE_CONSOLE, "CONSOLE", 0, "Python Console", ""},
-	{SPACE_USERPREF, "USER_PREFERENCES", 0, "User Preferences", ""},
-	{SPACE_CLIP, "CLIP_EDITOR", 0, "Clip Editor", ""},
+	{SPACE_VIEW3D, "VIEW_3D", ICON_VIEW3D, "3D View", ""},
+	{0, "", ICON_NONE, NULL, NULL},
+	{SPACE_TIME, "TIMELINE", ICON_TIME, "Timeline", ""},
+	{SPACE_IPO, "GRAPH_EDITOR", ICON_IPO, "Graph Editor", ""},
+	{SPACE_ACTION, "DOPESHEET_EDITOR", ICON_ACTION, "Dope Sheet", ""},
+	{SPACE_NLA, "NLA_EDITOR", ICON_NLA, "NLA Editor", ""},
+	{0, "", ICON_NONE, NULL, NULL},
+	{SPACE_IMAGE, "IMAGE_EDITOR", ICON_IMAGE_COL, "UV/Image Editor", ""},
+	{SPACE_SEQ, "SEQUENCE_EDITOR", ICON_SEQUENCE, "Video Sequence Editor", ""},
+	{SPACE_CLIP, "CLIP_EDITOR", ICON_CLIP, "Movie Clip Editor", ""},
+	{SPACE_TEXT, "TEXT_EDITOR", ICON_TEXT, "Text Editor", ""},
+	{SPACE_NODE, "NODE_EDITOR", ICON_NODETREE, "Node Editor", ""},
+	{SPACE_LOGIC, "LOGIC_EDITOR", ICON_LOGIC, "Logic Editor", ""},
+	{0, "", ICON_NONE, NULL, NULL},
+	{SPACE_BUTS, "PROPERTIES", ICON_BUTS, "Properties", ""},
+	{SPACE_OUTLINER, "OUTLINER", ICON_OOPS, "Outliner", ""},
+	{SPACE_USERPREF, "USER_PREFERENCES", ICON_PREFERENCES, "User Preferences", ""},
+	{SPACE_INFO, "INFO", ICON_INFO, "Info", ""},
+	{0, "", ICON_NONE, NULL, NULL},
+	{SPACE_FILE, "FILE_BROWSER", ICON_FILESEL, "File Browser", ""},
+	{0, "", ICON_NONE, NULL, NULL},
+	{SPACE_CONSOLE, "CONSOLE", ICON_CONSOLE, "Python Console", ""},
 	{0, NULL, 0, NULL, NULL}
 };
 




More information about the Bf-blender-cvs mailing list