settings_content.rs

  1mod language;
  2mod theme;
  3pub use language::*;
  4pub use theme::*;
  5
  6use std::env;
  7
  8use collections::HashMap;
  9use gpui::{App, SharedString};
 10use release_channel::ReleaseChannel;
 11use schemars::JsonSchema;
 12use serde::{Deserialize, Serialize};
 13
 14use crate::ActiveSettingsProfileName;
 15
 16#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
 17pub struct SettingsContent {
 18    #[serde(flatten)]
 19    pub project: ProjectSettingsContent,
 20
 21    #[serde(flatten)]
 22    pub theme: ThemeSettingsContent,
 23
 24    pub base_keymap: Option<BaseKeymapContent>,
 25
 26    pub auto_update: Option<bool>,
 27
 28    pub title_bar: Option<TitleBarSettingsContent>,
 29}
 30
 31impl SettingsContent {
 32    pub fn languages_mut(&mut self) -> &mut HashMap<SharedString, LanguageSettingsContent> {
 33        &mut self.project.all_languages.languages.0
 34    }
 35}
 36
 37// todo!() what should this be?
 38#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
 39pub struct ServerSettingsContent {
 40    #[serde(flatten)]
 41    pub project: ProjectSettingsContent,
 42}
 43
 44#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
 45pub struct UserSettingsContent {
 46    #[serde(flatten)]
 47    pub content: SettingsContent,
 48
 49    pub dev: Option<SettingsContent>,
 50    pub nightly: Option<SettingsContent>,
 51    pub preview: Option<SettingsContent>,
 52    pub stable: Option<SettingsContent>,
 53
 54    pub macos: Option<SettingsContent>,
 55    pub windows: Option<SettingsContent>,
 56    pub linux: Option<SettingsContent>,
 57
 58    #[serde(default)]
 59    pub profiles: HashMap<String, SettingsContent>,
 60}
 61
 62pub struct ExtensionsSettingsContent {
 63    pub all_languages: AllLanguageSettingsContent,
 64}
 65
 66impl UserSettingsContent {
 67    pub fn for_release_channel(&self) -> Option<&SettingsContent> {
 68        match *release_channel::RELEASE_CHANNEL {
 69            ReleaseChannel::Dev => self.dev.as_ref(),
 70            ReleaseChannel::Nightly => self.nightly.as_ref(),
 71            ReleaseChannel::Preview => self.preview.as_ref(),
 72            ReleaseChannel::Stable => self.stable.as_ref(),
 73        }
 74    }
 75
 76    pub fn for_os(&self) -> Option<&SettingsContent> {
 77        match env::consts::OS {
 78            "macos" => self.macos.as_ref(),
 79            "linux" => self.linux.as_ref(),
 80            "windows" => self.windows.as_ref(),
 81            _ => None,
 82        }
 83    }
 84
 85    pub fn for_profile(&self, cx: &App) -> Option<&SettingsContent> {
 86        let Some(active_profile) = cx.try_global::<ActiveSettingsProfileName>() else {
 87            return None;
 88        };
 89        self.profiles.get(&active_profile.0)
 90    }
 91}
 92
 93/// Base key bindings scheme. Base keymaps can be overridden with user keymaps.
 94///
 95/// Default: VSCode
 96#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
 97pub enum BaseKeymapContent {
 98    #[default]
 99    VSCode,
100    JetBrains,
101    SublimeText,
102    Atom,
103    TextMate,
104    Emacs,
105    Cursor,
106    None,
107}
108
109#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
110pub struct ProjectSettingsContent {
111    #[serde(flatten)]
112    pub(crate) all_languages: AllLanguageSettingsContent,
113}
114
115#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
116pub struct TitleBarSettingsContent {
117    /// Controls when the title bar is visible: "always" | "never" | "hide_in_full_screen".
118    ///
119    /// Default: "always"
120    pub show: Option<TitleBarVisibilityContent>,
121    /// Whether to show the branch icon beside branch switcher in the title bar.
122    ///
123    /// Default: false
124    pub show_branch_icon: Option<bool>,
125    /// Whether to show onboarding banners in the title bar.
126    ///
127    /// Default: true
128    pub show_onboarding_banner: Option<bool>,
129    /// Whether to show user avatar in the title bar.
130    ///
131    /// Default: true
132    pub show_user_picture: Option<bool>,
133    /// Whether to show the branch name button in the titlebar.
134    ///
135    /// Default: true
136    pub show_branch_name: Option<bool>,
137    /// Whether to show the project host and name in the titlebar.
138    ///
139    /// Default: true
140    pub show_project_items: Option<bool>,
141    /// Whether to show the sign in button in the title bar.
142    ///
143    /// Default: true
144    pub show_sign_in: Option<bool>,
145    /// Whether to show the menus in the title bar.
146    ///
147    /// Default: false
148    pub show_menus: Option<bool>,
149}
150
151#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Debug)]
152#[serde(rename_all = "snake_case")]
153pub enum TitleBarVisibilityContent {
154    Always,
155    Never,
156    HideInFullScreen,
157}