UI: add active tool panel to tool settings
authorCampbell Barton <ideasman42@gmail.com>
Wed, 29 Aug 2018 22:55:34 +0000 (08:55 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 29 Aug 2018 23:00:39 +0000 (09:00 +1000)
release/scripts/startup/bl_ui/space_toolsystem_common.py
release/scripts/startup/bl_ui/space_topbar.py
source/blender/editors/space_buttons/space_buttons.c

index e03b3eb585d9b2c4e18783325cac59d4d003ce4a..b8e3d81c1d4b76aced1af803b679e0e015a20b66 100644 (file)
@@ -513,16 +513,21 @@ class ToolSelectPanelHelper:
         self.draw_cls(self.layout, context)
 
     @staticmethod
-    def draw_active_tool_header(context, layout):
+    def draw_active_tool_header(
+            context, layout,
+            *,
+            show_tool_name=False,
+    ):
         # BAD DESIGN WARNING: last used tool
         workspace = context.workspace
         space_type = workspace.tools_space_type
         mode = workspace.tools_mode
         item, tool, icon_value = ToolSelectPanelHelper._tool_get_active(context, space_type, mode, with_icon=True)
         if item is None:
-            return
-        # Note: we could show 'item.text' here but it makes the layout jitter when switcuing tools.
-        layout.label(text=" ", icon_value=icon_value)
+            return None
+        # Note: we could show 'item.text' here but it makes the layout jitter when switching tools.
+        # Add some spacing since the icon is currently assuming regular small icon size.
+        layout.label(text="    " + item.text if show_tool_name else " ", icon_value=icon_value)
         draw_settings = item.draw_settings
         if draw_settings is not None:
             draw_settings(context, layout, tool)
index b6a68f067852ffa5457eea2443fd63ca59eab891..3395889cf8287248dc18dd7b53921680c554ac3a 100644 (file)
@@ -614,6 +614,26 @@ class TOPBAR_MT_workspace_menu(Menu):
             layout.operator("workspace.delete", text="Delete")
 
 
+class TOPBAR_PT_active_tool(Panel):
+    bl_space_type = 'PROPERTIES'
+    bl_region_type = 'WINDOW'
+    bl_category = ""
+    bl_context = ".active_tool"  # dot on purpose (access from tool settings)
+    bl_label = "Active Tool"
+
+    def draw(self, context):
+        layout = self.layout
+
+        # Panel display of topbar tool settings.
+        # currently displays in tool settings, keep here since the same functionality is used for the topbar.
+
+        layout.use_property_split = True
+        layout.use_property_decorate = False
+
+        from .space_toolsystem_common import ToolSelectPanelHelper
+        ToolSelectPanelHelper.draw_active_tool_header(context, layout, show_tool_name=True)
+
+
 classes = (
     TOPBAR_HT_upper_bar,
     TOPBAR_HT_lower_bar,
@@ -630,6 +650,7 @@ classes = (
     TOPBAR_MT_render,
     TOPBAR_MT_window,
     TOPBAR_MT_help,
+    TOPBAR_PT_active_tool,
 )
 
 if __name__ == "__main__":  # only for live edit.
index 0350e3fcd144ed0d18342cc1d7f3fa6d848bf538..fe10eee053698ee94a83058ba51cd2658d81910c 100644 (file)
@@ -200,11 +200,13 @@ static void buttons_main_region_layout_properties(const bContext *C, SpaceButs *
 
 static void buttons_main_region_layout_tool(const bContext *C, ARegion *ar)
 {
-       const char *contexts[3] = {NULL};
-
        const WorkSpace *workspace = CTX_wm_workspace(C);
        const int mode = CTX_data_mode_enum(C);
 
+       const char *contexts_base[4] = {NULL};
+       contexts_base[0] = ".active_tool";
+       const char **contexts = &contexts_base[1];
+
        if (workspace->tools_space_type == SPACE_VIEW3D) {
                switch (mode) {
                        case CTX_MODE_EDIT_MESH:
@@ -283,7 +285,7 @@ static void buttons_main_region_layout_tool(const bContext *C, ARegion *ar)
        }
 
        const bool vertical = true;
-       ED_region_panels_layout_ex(C, ar, contexts, -1, vertical);
+       ED_region_panels_layout_ex(C, ar, contexts_base, -1, vertical);
 }
 
 static void buttons_main_region_layout(const bContext *C, ARegion *ar)
@@ -365,6 +367,10 @@ static void buttons_header_region_message_subscribe(
        if (!ELEM(sbuts->mainb, BCONTEXT_RENDER, BCONTEXT_SCENE, BCONTEXT_WORLD)) {
                WM_msg_subscribe_rna_anon_prop(mbus, ViewLayer, name, &msg_sub_value_region_tag_redraw);
        }
+
+       if (sbuts->mainb == BCONTEXT_TOOL) {
+               WM_msg_subscribe_rna_anon_prop(mbus, WorkSpace, tools, &msg_sub_value_region_tag_redraw);
+       }
 }
 
 /* draw a certain button set only if properties area is currently