basics_page.rs

  1use fs::Fs;
  2use gpui::{App, IntoElement, Window};
  3use settings::{Settings, update_settings_file};
  4use theme::{ThemeMode, ThemeSettings};
  5use ui::{SwitchField, ToggleButtonGroup, ToggleButtonSimple, ToggleButtonWithIcon, prelude::*};
  6
  7fn read_theme_selection(cx: &App) -> ThemeMode {
  8    let settings = ThemeSettings::get_global(cx);
  9    settings
 10        .theme_selection
 11        .as_ref()
 12        .and_then(|selection| selection.mode())
 13        .unwrap_or_default()
 14}
 15
 16fn write_theme_selection(theme_mode: ThemeMode, cx: &App) {
 17    let fs = <dyn Fs>::global(cx);
 18
 19    update_settings_file::<ThemeSettings>(fs, cx, move |settings, _| {
 20        settings.set_mode(theme_mode);
 21    });
 22}
 23
 24fn render_theme_section(cx: &mut App) -> impl IntoElement {
 25    let theme_mode = read_theme_selection(cx);
 26
 27    h_flex().justify_between().child(Label::new("Theme")).child(
 28        ToggleButtonGroup::single_row(
 29            "theme-selector-onboarding",
 30            [
 31                ToggleButtonSimple::new("Light", |_, _, cx| {
 32                    write_theme_selection(ThemeMode::Light, cx)
 33                }),
 34                ToggleButtonSimple::new("Dark", |_, _, cx| {
 35                    write_theme_selection(ThemeMode::Dark, cx)
 36                }),
 37                ToggleButtonSimple::new("System", |_, _, cx| {
 38                    write_theme_selection(ThemeMode::System, cx)
 39                }),
 40            ],
 41        )
 42        .selected_index(match theme_mode {
 43            ThemeMode::Light => 0,
 44            ThemeMode::Dark => 1,
 45            ThemeMode::System => 2,
 46        })
 47        .style(ui::ToggleButtonGroupStyle::Outlined)
 48        .button_width(rems_from_px(64.)),
 49    )
 50}
 51
 52fn render_telemetry_section() -> impl IntoElement {
 53    v_flex()
 54        .gap_3()
 55        .child(Label::new("Telemetry").size(LabelSize::Large))
 56        .child(SwitchField::new(
 57            "vim_mode",
 58            "Help Improve Zed",
 59            "Sending anonymous usage data helps us build the right features and create the best experience.",
 60            ui::ToggleState::Selected,
 61            |_, _, _| {},
 62        ))
 63        .child(SwitchField::new(
 64            "vim_mode",
 65            "Help Fix Zed",
 66            "Send crash reports so we can fix critical issues fast.",
 67            ui::ToggleState::Selected,
 68            |_, _, _| {},
 69        ))
 70}
 71
 72pub(crate) fn render_basics_page(_: &mut Window, cx: &mut App) -> impl IntoElement {
 73    v_flex()
 74        .gap_6()
 75        .child(render_theme_section(cx))
 76        .child(
 77            v_flex().gap_2().child(Label::new("Base Keymap")).child(
 78                ToggleButtonGroup::two_rows(
 79                    "multiple_row_test",
 80                    [
 81                        ToggleButtonWithIcon::new("VS Code", IconName::AiZed, |_, _, _| {}),
 82                        ToggleButtonWithIcon::new("Jetbrains", IconName::AiZed, |_, _, _| {}),
 83                        ToggleButtonWithIcon::new("Sublime Text", IconName::AiZed, |_, _, _| {}),
 84                    ],
 85                    [
 86                        ToggleButtonWithIcon::new("Atom", IconName::AiZed, |_, _, _| {}),
 87                        ToggleButtonWithIcon::new("Emacs", IconName::AiZed, |_, _, _| {}),
 88                        ToggleButtonWithIcon::new("Cursor (Beta)", IconName::AiZed, |_, _, _| {}),
 89                    ],
 90                )
 91                .button_width(rems_from_px(230.))
 92                .style(ui::ToggleButtonGroupStyle::Outlined)
 93            ),
 94        )
 95        .child(v_flex().justify_center().child(div().h_0().child("hack").invisible()).child(SwitchField::new(
 96            "vim_mode",
 97            "Vim Mode",
 98            "Coming from Neovim? Zed's first-class implementation of Vim Mode has got your back.",
 99            ui::ToggleState::Selected,
100            |_, _, _| {},
101        )))
102        .child(render_telemetry_section())
103}