use std::ops::Deref; use gpui::{rems, AbsoluteLength, AppContext, WindowContext}; use crate::prelude::*; pub fn init(cx: &mut AppContext) { cx.set_global(FakeSettings::default()); } /// Returns the user settings. pub fn user_settings(cx: &WindowContext) -> FakeSettings { cx.global::().clone() } pub fn user_settings_mut<'cx>(cx: &'cx mut WindowContext) -> &'cx mut FakeSettings { cx.global_mut::() } #[derive(Clone)] pub enum SettingValue { UserDefined(T), Default(T), } impl Deref for SettingValue { type Target = T; fn deref(&self) -> &Self::Target { match self { Self::UserDefined(value) => value, Self::Default(value) => value, } } } #[derive(Clone)] pub struct TitlebarSettings { pub show_project_owner: SettingValue, pub show_git_status: SettingValue, pub show_git_controls: SettingValue, } impl Default for TitlebarSettings { fn default() -> Self { Self { show_project_owner: SettingValue::Default(true), show_git_status: SettingValue::Default(true), show_git_controls: SettingValue::Default(true), } } } // These should be merged into settings #[derive(Clone)] pub struct FakeSettings { pub default_panel_size: SettingValue, pub list_disclosure_style: SettingValue, pub list_indent_depth: SettingValue, pub titlebar: TitlebarSettings, } impl Default for FakeSettings { fn default() -> Self { Self { titlebar: TitlebarSettings::default(), list_disclosure_style: SettingValue::Default(DisclosureControlStyle::ChevronOnHover), list_indent_depth: SettingValue::Default(rems(0.3).into()), default_panel_size: SettingValue::Default(rems(16.).into()), } } } impl FakeSettings {}