migrate ui components to gpui-kit
This commit is contained in:
@@ -3,15 +3,18 @@ use gpui::{
|
||||
App, AppContext, Context, Entity, IntoElement, ParentElement, PathPromptOptions, Render,
|
||||
SharedString, Styled, Window, div,
|
||||
};
|
||||
use gpui_kit::assets::IconName;
|
||||
use gpui_kit::component::button::{Button, ButtonVariants};
|
||||
use gpui_kit::component::form::field;
|
||||
use gpui_kit::component::group_box::{GroupBox, GroupBoxVariants};
|
||||
use gpui_kit::component::input::{Input, InputState};
|
||||
use gpui_kit::component::menu::{DropdownMenu, PopupMenuItem};
|
||||
use gpui_kit::component::notification::Notification;
|
||||
use gpui_kit::component::switch::Switch;
|
||||
use gpui_kit::component::{ActiveTheme, Disableable, Sizable, WindowExt, h_flex, v_flex};
|
||||
use settings::AppSettings;
|
||||
use theme::{ActiveTheme, AppExt as _, AppearanceMode, TextStyle, Typeset as _};
|
||||
use ui::button::{Button, ButtonVariants};
|
||||
use ui::group_box::{GroupBox, GroupBoxVariants};
|
||||
use ui::input::{Input, InputState};
|
||||
use ui::menu::{DropdownMenu, PopupMenuItem};
|
||||
use ui::notification::Notification;
|
||||
use ui::switch::Switch;
|
||||
use ui::{Disableable, IconName, Sizable, WindowExtension, h_flex, v_flex};
|
||||
use settings::AppearanceMode;
|
||||
use ui::{TextStyle, Typeset as _};
|
||||
|
||||
pub fn init(window: &mut Window, cx: &mut App) -> Entity<Preferences> {
|
||||
cx.new(|cx| Preferences::new(window, cx))
|
||||
@@ -50,7 +53,9 @@ impl Preferences {
|
||||
/// Set the appearance mode (system, light or dark)
|
||||
fn set_appearance_mode(mode: AppearanceMode, cx: &mut App) {
|
||||
AppSettings::update_appearance_mode(mode, cx);
|
||||
cx.set_appearance_mode(mode);
|
||||
AppSettings::global(cx).update(cx, |settings, cx| {
|
||||
settings.apply_theme(cx);
|
||||
});
|
||||
}
|
||||
|
||||
/// Ask the user for an image to show behind chat and group panels
|
||||
@@ -109,33 +114,29 @@ impl Render for Preferences {
|
||||
.id("general")
|
||||
.title("General")
|
||||
.fill()
|
||||
.child(
|
||||
Switch::new("screening")
|
||||
.label("Screening")
|
||||
.description(SCREENING)
|
||||
.checked(screening)
|
||||
.on_click(move |_, _window, cx| {
|
||||
.child(field().label("Screening").description(SCREENING).child(
|
||||
Switch::new("screening").checked(screening).on_click(
|
||||
move |_, _window, cx| {
|
||||
AppSettings::update_screening(!screening, cx);
|
||||
}),
|
||||
)
|
||||
},
|
||||
),
|
||||
))
|
||||
.child(
|
||||
Switch::new("wot-auto-trust")
|
||||
.label("Web of Trust")
|
||||
.description(WOT)
|
||||
.checked(wot_auto_trust)
|
||||
.on_click(move |_, _window, cx| {
|
||||
AppSettings::update_wot_auto_trust(!wot_auto_trust, cx);
|
||||
}),
|
||||
field().label("Web of Trust").description(WOT).child(
|
||||
Switch::new("wot-auto-trust")
|
||||
.checked(wot_auto_trust)
|
||||
.on_click(move |_, _window, cx| {
|
||||
AppSettings::update_wot_auto_trust(!wot_auto_trust, cx);
|
||||
}),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
Switch::new("avatar")
|
||||
.label("Hide user avatar")
|
||||
.description(AVATAR)
|
||||
.checked(hide_avatar)
|
||||
.on_click(move |_, _window, cx| {
|
||||
.child(field().label("Hide user avatar").description(AVATAR).child(
|
||||
Switch::new("avatar").checked(hide_avatar).on_click(
|
||||
move |_, _window, cx| {
|
||||
AppSettings::update_hide_avatar(!hide_avatar, cx);
|
||||
}),
|
||||
),
|
||||
},
|
||||
),
|
||||
)),
|
||||
)
|
||||
.child(
|
||||
GroupBox::new()
|
||||
@@ -156,14 +157,14 @@ impl Render for Preferences {
|
||||
.child(
|
||||
div()
|
||||
.text_style(TextStyle::Caption)
|
||||
.text_color(cx.theme().text_muted)
|
||||
.text_color(cx.theme().muted_foreground)
|
||||
.child(SharedString::from(MODE)),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
Button::new("appearance-mode")
|
||||
.label(appearance_mode.label())
|
||||
.ghost_alt()
|
||||
.ghost()
|
||||
.small()
|
||||
.dropdown_menu(|this, _window, _cx| {
|
||||
AppearanceMode::ALL.iter().fold(this, |menu, mode| {
|
||||
@@ -183,14 +184,17 @@ impl Render for Preferences {
|
||||
.title("Background")
|
||||
.fill()
|
||||
.child(
|
||||
Switch::new("panel-background")
|
||||
field()
|
||||
.label("Panel background")
|
||||
.description(BACKGROUND)
|
||||
.checked(panel_background)
|
||||
.on_click(move |_, _window, cx| {
|
||||
AppSettings::update_panel_background(!panel_background, cx);
|
||||
cx.refresh_windows();
|
||||
}),
|
||||
.child(
|
||||
Switch::new("panel-background")
|
||||
.checked(panel_background)
|
||||
.on_click(move |_, _window, cx| {
|
||||
AppSettings::update_panel_background(!panel_background, cx);
|
||||
cx.refresh_windows();
|
||||
}),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
h_flex()
|
||||
@@ -208,7 +212,7 @@ impl Render for Preferences {
|
||||
.child(
|
||||
div()
|
||||
.text_style(TextStyle::Caption)
|
||||
.text_color(cx.theme().text_muted)
|
||||
.text_color(cx.theme().muted_foreground)
|
||||
.truncate()
|
||||
.child(SharedString::from(background_label)),
|
||||
),
|
||||
@@ -220,7 +224,7 @@ impl Render for Preferences {
|
||||
.child(
|
||||
Button::new("choose-background")
|
||||
.label("Choose image")
|
||||
.ghost_alt()
|
||||
.ghost()
|
||||
.small()
|
||||
.disabled(!panel_background)
|
||||
.on_click(|_, _window, cx| {
|
||||
@@ -230,7 +234,7 @@ impl Render for Preferences {
|
||||
.child(
|
||||
Button::new("reset-background")
|
||||
.label("Reset")
|
||||
.ghost_alt()
|
||||
.ghost()
|
||||
.small()
|
||||
.disabled(
|
||||
!panel_background
|
||||
@@ -250,13 +254,14 @@ impl Render for Preferences {
|
||||
.title("Experiments")
|
||||
.fill()
|
||||
.child(
|
||||
Switch::new("nip4e")
|
||||
field()
|
||||
.label("Decoupling Encryption Key")
|
||||
.description(NIP4E)
|
||||
.checked(nip4e)
|
||||
.on_click(move |_, _window, cx| {
|
||||
AppSettings::update_nip4e(!nip4e, cx);
|
||||
}),
|
||||
.child(Switch::new("nip4e").checked(nip4e).on_click(
|
||||
move |_, _window, cx| {
|
||||
AppSettings::update_nip4e(!nip4e, cx);
|
||||
},
|
||||
)),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
@@ -285,7 +290,7 @@ impl Render for Preferences {
|
||||
div()
|
||||
.text_style(TextStyle::Caption2)
|
||||
.italic()
|
||||
.text_color(cx.theme().text_faint)
|
||||
.text_color(cx.theme().muted_foreground)
|
||||
.child(SharedString::from("Only support blossom service")),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user