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