1use std::ops::Deref;
2
3use gpui::{rems, AbsoluteLength, AppContext, WindowContext};
4
5use crate::prelude::*;
6
7pub fn init(cx: &mut AppContext) {
8 cx.set_global(FakeSettings::default());
9}
10
11/// Returns the user settings.
12pub fn user_settings(cx: &WindowContext) -> FakeSettings {
13 cx.global::<FakeSettings>().clone()
14}
15
16pub fn user_settings_mut<'cx>(cx: &'cx mut WindowContext) -> &'cx mut FakeSettings {
17 cx.global_mut::<FakeSettings>()
18}
19
20#[derive(Clone)]
21pub enum SettingValue<T> {
22 UserDefined(T),
23 Default(T),
24}
25
26impl<T> Deref for SettingValue<T> {
27 type Target = T;
28
29 fn deref(&self) -> &Self::Target {
30 match self {
31 Self::UserDefined(value) => value,
32 Self::Default(value) => value,
33 }
34 }
35}
36
37#[derive(Clone)]
38pub struct TitlebarSettings {
39 pub show_project_owner: SettingValue<bool>,
40 pub show_git_status: SettingValue<bool>,
41 pub show_git_controls: SettingValue<bool>,
42}
43
44impl Default for TitlebarSettings {
45 fn default() -> Self {
46 Self {
47 show_project_owner: SettingValue::Default(true),
48 show_git_status: SettingValue::Default(true),
49 show_git_controls: SettingValue::Default(true),
50 }
51 }
52}
53
54// These should be merged into settings
55#[derive(Clone)]
56pub struct FakeSettings {
57 pub default_panel_size: SettingValue<AbsoluteLength>,
58 pub list_disclosure_style: SettingValue<DisclosureControlStyle>,
59 pub list_indent_depth: SettingValue<AbsoluteLength>,
60 pub titlebar: TitlebarSettings,
61}
62
63impl Default for FakeSettings {
64 fn default() -> Self {
65 Self {
66 titlebar: TitlebarSettings::default(),
67 list_disclosure_style: SettingValue::Default(DisclosureControlStyle::ChevronOnHover),
68 list_indent_depth: SettingValue::Default(rems(0.3).into()),
69 default_panel_size: SettingValue::Default(rems(16.).into()),
70 }
71 }
72}
73
74impl FakeSettings {}