title_bar: Add icon for project branch trigger button (#29494)

Shashank Verma created

Added icon for branch switcher in title bar

| `main`    | This PR |
| -------- | ------- |
| <img width="196" alt="Screenshot 2025-04-27 at 1 02 47 PM"
src="https://github.com/user-attachments/assets/5625f6c5-7b11-4f3d-bed8-6ea3b74d9416"
/> | <img width="217" alt="Screenshot 2025-04-27 at 1 07 11 PM"
src="https://github.com/user-attachments/assets/6c83daa6-fa71-44a8-8f6b-e33b2217b29e"
/> |

Release Notes:

- Added icon for branch switcher in title bar

---------

Signed-off-by: Shashank Verma <shashank.verma2002@gmail.com>

Change summary

assets/settings/default.json               |  5 +++
crates/title_bar/src/title_bar.rs          | 15 ++++++++++
crates/title_bar/src/title_bar_settings.rs | 32 ++++++++++++++++++++++++
3 files changed, 51 insertions(+), 1 deletion(-)

Detailed changes

assets/settings/default.json 🔗

@@ -307,6 +307,11 @@
     // Whether to show agent review buttons in the editor toolbar.
     "agent_review": true
   },
+  // Titlebar related settings
+  "title_bar": {
+    // Whether to show the branch icon beside branch switcher in the title bar.
+    "show_branch_icon": false
+  },
   // Scrollbar related settings
   "scrollbar": {
     // When to show the scrollbar in the editor.

crates/title_bar/src/title_bar.rs 🔗

@@ -2,6 +2,7 @@ mod application_menu;
 mod collab;
 mod onboarding_banner;
 mod platforms;
+mod title_bar_settings;
 mod window_controls;
 
 #[cfg(feature = "stories")]
@@ -31,6 +32,7 @@ use settings::Settings as _;
 use smallvec::SmallVec;
 use std::sync::Arc;
 use theme::ActiveTheme;
+use title_bar_settings::TitleBarSettings;
 use ui::{
     Avatar, Button, ButtonLike, ButtonStyle, ContextMenu, Icon, IconName, IconSize,
     IconWithIndicator, Indicator, PopoverMenu, Tooltip, h_flex, prelude::*,
@@ -53,6 +55,8 @@ const BOOK_ONBOARDING: &str = "https://dub.sh/zed-c-onboarding";
 actions!(collab, [ToggleUserMenu, ToggleProjectMenu, SwitchBranch]);
 
 pub fn init(cx: &mut App) {
+    TitleBarSettings::register(cx);
+
     cx.observe_new(|workspace: &mut Workspace, window, cx| {
         let Some(window) = window else {
             return;
@@ -549,7 +553,16 @@ impl TitleBar {
                     let _ = workspace.update(cx, |_this, cx| {
                         window.dispatch_action(zed_actions::git::Branch.boxed_clone(), cx);
                     });
-                }),
+                })
+                .when(
+                    TitleBarSettings::get_global(cx).show_branch_icon,
+                    |branch_button| {
+                        branch_button
+                            .icon(IconName::GitBranch)
+                            .icon_position(IconPosition::Start)
+                            .icon_color(Color::Muted)
+                    },
+                ),
         )
     }
 

crates/title_bar/src/title_bar_settings.rs 🔗

@@ -0,0 +1,32 @@
+use db::anyhow;
+use schemars::JsonSchema;
+use serde::{Deserialize, Serialize};
+use settings::{Settings, SettingsSources};
+
+#[derive(Deserialize, Debug, Clone, Copy, PartialEq)]
+pub struct TitleBarSettings {
+    pub show_branch_icon: bool,
+}
+
+#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
+pub struct TitleBarSettingsContent {
+    /// Whether to show the branch icon beside branch switcher in the title bar.
+    ///
+    /// Default: false
+    pub show_branch_icon: Option<bool>,
+}
+
+impl Settings for TitleBarSettings {
+    const KEY: Option<&'static str> = Some("title_bar");
+
+    type FileContent = TitleBarSettingsContent;
+
+    fn load(sources: SettingsSources<Self::FileContent>, _: &mut gpui::App) -> anyhow::Result<Self>
+    where
+        Self: Sized,
+    {
+        sources.json_merge()
+    }
+
+    fn import_from_vscode(_: &settings::VsCodeSettings, _: &mut Self::FileContent) {}
+}