[Bf-blender-cvs] [34ebf6f82c4] blender2.8: Workspaces: move delete to right click menu, instead of X on tab.

Brecht Van Lommel noreply at git.blender.org
Thu Aug 23 20:06:38 CEST 2018


Commit: 34ebf6f82c4a375feb3c5260597042ff41adc7b5
Author: Brecht Van Lommel
Date:   Thu Aug 23 19:58:54 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB34ebf6f82c4a375feb3c5260597042ff41adc7b5

Workspaces: move delete to right click menu, instead of X on tab.

These are not intended to be closed as often as e.g. browser tabs, they are
intended to be more persistent and accidental closing should be avoided.

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

M	release/scripts/startup/bl_ui/space_topbar.py
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_context_menu.c
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/screen/workspace_edit.c
M	source/blender/makesrna/intern/rna_ui_api.c

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

diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index 881d3db8a4c..8bf8e40d74e 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -47,8 +47,8 @@ class TOPBAR_HT_upper_bar(Header):
         if not screen.show_fullscreen:
             layout.template_ID_tabs(
                 window, "workspace",
-                new="workspace.workspace_add_menu",
-                unlink="workspace.workspace_delete",
+                new="workspace.add_menu",
+                menu="TOPBAR_MT_workspace_menu",
             )
         else:
             layout.operator(
@@ -622,11 +622,23 @@ class TOPBAR_MT_window_specials(Menu):
         layout.operator("screen.userpref_show", text="User Preferences...", icon='PREFERENCES')
 
 
+class TOPBAR_MT_workspace_menu(Menu):
+    bl_label = "Workspace"
+
+    def draw(self, context):
+        layout = self.layout
+
+        layout.operator("workspace.duplicate", text="Duplicate")
+        if len(bpy.data.workspaces) > 1:
+            layout.operator("workspace.delete", text="Delete")
+
+
 classes = (
     TOPBAR_HT_upper_bar,
     TOPBAR_HT_lower_bar,
     TOPBAR_MT_file_specials,
     TOPBAR_MT_window_specials,
+    TOPBAR_MT_workspace_menu,
     INFO_MT_editor_menus,
     INFO_MT_file,
     INFO_MT_file_import,
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 5cc3e369439..c88470bd323 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1033,7 +1033,7 @@ void uiTemplateIDPreview(
 void uiTemplateIDTabs(
         uiLayout *layout, struct bContext *C,
         PointerRNA *ptr, const char *propname,
-        const char *newop, const char *openop, const char *unlinkop,
+        const char *newop, const char *openop, const char *menu,
         int filter);
 void uiTemplateAnyID(
         uiLayout *layout, struct PointerRNA *ptr, const char *propname,
@@ -1221,6 +1221,7 @@ void UI_context_active_but_prop_get_filebrowser(
 void UI_context_active_but_prop_get_templateID(
         struct bContext *C,
         struct PointerRNA *r_ptr, struct PropertyRNA **r_prop);
+struct ID *UI_context_active_but_get_tab_ID(struct bContext *C);
 
 uiBut *UI_region_active_but_get(struct ARegion *ar);
 
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 37c56d454bb..edb0928c57e 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -2075,7 +2075,7 @@ static bool ui_but_icon_extra_is_visible_text_clear(const uiBut *but)
 
 static bool ui_but_icon_extra_is_visible_search_unlink(const uiBut *but)
 {
-	BLI_assert(ELEM(but->type, UI_BTYPE_SEARCH_MENU, UI_BTYPE_TAB));
+	BLI_assert(ELEM(but->type, UI_BTYPE_SEARCH_MENU));
 	return ((but->editstr == NULL) &&
 	        (but->drawstr[0] != '\0') &&
 	        (but->flag & UI_BUT_VALUE_CLEAR));
@@ -2118,11 +2118,6 @@ uiButExtraIconType ui_but_icon_extra_get(uiBut *but)
 				return UI_BUT_ICONEXTRA_EYEDROPPER;
 			}
 			break;
-		case UI_BTYPE_TAB:
-			if (ui_but_icon_extra_is_visible_search_unlink(but)) {
-				return UI_BUT_ICONEXTRA_CLEAR;
-			}
-			break;
 		default:
 			break;
 	}
@@ -3095,7 +3090,6 @@ void ui_but_update_ex(uiBut *but, const bool validate)
 
 		case UI_BTYPE_TEXT:
 		case UI_BTYPE_SEARCH_MENU:
-		case UI_BTYPE_TAB:
 			if (!but->editstr) {
 				char str[UI_MAX_DRAW_STR];
 
diff --git a/source/blender/editors/interface/interface_context_menu.c b/source/blender/editors/interface/interface_context_menu.c
index 8d4f8594a90..281c2fb7104 100644
--- a/source/blender/editors/interface/interface_context_menu.c
+++ b/source/blender/editors/interface/interface_context_menu.c
@@ -361,7 +361,14 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but)
 		uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT);
 	}
 
-	if (but->rnapoin.data && but->rnaprop) {
+	if (but->type == UI_BTYPE_TAB) {
+		uiButTab *tab = (uiButTab *)but;
+		if (tab->menu) {
+			UI_menutype_draw(C, tab->menu, layout);
+			uiItemS(layout);
+		}
+	}
+	else if (but->rnapoin.data && but->rnaprop) {
 		PointerRNA *ptr = &but->rnapoin;
 		PropertyRNA *prop = but->rnaprop;
 		const PropertyType type = RNA_property_type(prop);
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 0ba9261c4bd..4b68be8fa3b 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -3763,17 +3763,6 @@ static int ui_do_but_TAB(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
 			return WM_UI_HANDLER_BREAK;
 		}
 		else if (ELEM(event->type, LEFTMOUSE, PADENTER, RETKEY) && (event->val == KM_CLICK)) {
-			const bool has_icon_extra = ui_but_icon_extra_get(but) == UI_BUT_ICONEXTRA_CLEAR;
-
-			if (has_icon_extra && ui_but_is_mouse_over_icon_extra(data->region, but, &event->x)) {
-				uiButTab *tab = (uiButTab *)but;
-				wmOperatorType *ot_backup = but->optype;
-
-				but->optype = tab->unlink_ot;
-				/* Force calling unlink/delete operator. */
-				ui_apply_but(C, block, but, data, true);
-				but->optype = ot_backup;
-			}
 			button_activate_state(C, but, BUTTON_STATE_EXIT);
 			return WM_UI_HANDLER_BREAK;
 		}
@@ -8910,7 +8899,6 @@ static int ui_handle_menu_event(
 			else {
 
 				/* check mouse moving outside of the menu */
-				//printf("inside %d mm quit %d\n", inside, block->flag & (UI_BLOCK_MOVEMOUSE_QUIT);
 				if (inside == 0 && (block->flag & (UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_POPOVER))) {
 					uiSafetyRct *saferct;
 
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index f7507223f31..863e4b3762a 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -322,7 +322,7 @@ struct uiBut {
 
 typedef struct uiButTab {
 	uiBut but;
-	struct wmOperatorType *unlink_ot;
+	struct MenuType *menu;
 } uiButTab;
 
 typedef struct ColorPicker {
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 820b34c1ac4..9c4e7faa73e 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -822,38 +822,45 @@ static void template_ID(
 	UI_block_align_end(block);
 }
 
+
+ID *UI_context_active_but_get_tab_ID(bContext *C)
+{
+	uiBut *but = UI_context_active_but_get(C);
+
+	if (but && but->type == UI_BTYPE_TAB) {
+		return but->custom_data;
+	}
+	else {
+		return NULL;
+	}
+}
+
 static void template_ID_tabs(
         bContext *C, uiLayout *layout, TemplateID *template, StructRNA *type, int flag,
-        const char *newop, const char *UNUSED(openop), const char *unlinkop)
+        const char *newop, const char *UNUSED(openop), const char *menu)
 {
 	const ARegion *region = CTX_wm_region(C);
 	const PointerRNA active_ptr = RNA_property_pointer_get(&template->ptr, template->prop);
+	MenuType *mt = WM_menutype_find(menu, false);
+
 	const int but_align = (region->alignment == RGN_ALIGN_TOP) ? UI_BUT_ALIGN_DOWN : UI_BUT_ALIGN_TOP;
 	const int but_height = UI_UNIT_Y * 1.1;
 
 	uiBlock *block = uiLayoutGetBlock(layout);
 	uiStyle *style = UI_style_get_dpi();
 
-
 	for (ID *id = template->idlb->first; id; id = id->next) {
-		wmOperatorType *unlink_ot = WM_operatortype_find(unlinkop, false);
-		const bool is_active = active_ptr.data == id;
-		const unsigned int but_width = (
-		        UI_fontstyle_string_width(&style->widgetlabel, id->name + 2) + UI_UNIT_X +
-		        (is_active ? ICON_DEFAULT_WIDTH_SCALE : 0));
-		uiButTab *tab;
-
-		tab = (uiButTab *)uiDefButR_prop(
-		        block, UI_BTYPE_TAB, 0, "", 0, 0, but_width, UI_UNIT_Y * 1.1,
+		const int name_width = UI_fontstyle_string_width(&style->widgetlabel, id->name + 2);
+		const int but_width = name_width + UI_UNIT_X;
+
+		uiButTab *tab = (uiButTab *)uiDefButR_prop(
+		        block, UI_BTYPE_TAB, 0, id->name + 2, 0, 0, but_width, but_height,
 		        &template->ptr, template->prop, 0, 0.0f,
 		        sizeof(id->name) - 2, 0.0f, 0.0f, "");
 		UI_but_funcN_set(&tab->but, template_ID_set_property_cb, MEM_dupallocN(template), id);
 		tab->but.custom_data = (void *)id;
-		tab->unlink_ot = unlink_ot;
+		tab->menu = mt;
 
-		if (is_active) {
-			UI_but_flag_enable(&tab->but, UI_BUT_VALUE_CLEAR);
-		}
 		UI_but_drawflag_enable(&tab->but, but_align);
 	}
 
diff --git a/source/blender/editors/screen/workspace_edit.c b/source/blender/editors/screen/workspace_edit.c
index 4f8389d9f7d..246d2fed1a1 100644
--- a/source/blender/editors/screen/workspace_edit.c
+++ b/source/blender/editors/screen/workspace_edit.c
@@ -256,23 +256,36 @@ void ED_workspace_scene_data_sync(
  *
  * \{ */
 
+static WorkSpace *workspace_context_get(bContext *C)
+{
+	ID *id = UI_context_active_but_get_tab_ID(C);
+	if (id && GS(id->name) == ID_WS) {
+		return (WorkSpace *)id;
+	}
+
+	wmWindow *win = CTX_wm_window(C);
+	return WM_window_get_active_workspace(win);
+}
+
 static int workspace_new_exec(bContext *C, wmOperator *UNUSED(op))
 {
 	Main *bmain = CTX_data_main(C);
 	wmWindow *win = CTX_wm_window(C);
-	WorkSpace *workspace = ED_workspace_duplicate(WM_window_get_active_workspace(win), bmain, win);
+	WorkSpace *workspace = workspace_context_get(C);
+
+	workspace = ED_workspace_duplicate(workspace, bmain, win);
 
 	WM_event_add_notifier(C, NC_SCREEN | ND_WORKSPACE_SET, workspace);
 
 	return OPERATOR_FINISHED;
 }
 
-static void WORKSPACE_OT_workspace_duplicate(wmOperatorType *ot)
+static void WORKSPACE_OT_duplicate(wmOperatorType *ot)
 {
 	/* identifiers */
 	ot->name = "New Workspace";
 	ot->description = "Add a new workspace";
-	ot->idname = "WORKSPACE_OT_workspace_duplicate";
+	ot->idname = "WORKSPACE_OT_duplicate";
 
 	/* api callbacks */
 	ot->exec = workspace_new_exec;
@@ -281,19 +294,18 @@ static void WORKSPACE_OT_workspace_duplicate(wmOperatorType *ot)
 
 static int workspace_delete_exec(bContext *C, wmOperator *UNUSED(op))
 {
-	wmWindow *win = CTX_wm_window

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list