Slice 1 of plan section 6 step 3 (docs/ui.md, "The GPUI front end"). The window
is the shell of ui/shells/desktop.slint, as entities that observe the root
state and tell the window only when what they show changed (they compare their
view of the state, so an engine event about a talker, a tick or a setting that
is not the theme's draws nothing):
- shell/rail.rs: the saved servers as avatars with their tints, initials,
presence dots, unread and live marks, the selection pill and ring, the plus
that adds a server and the settings button; a second click edits a server,
as the Slint rail's double click does.
- shell/sidebar.rs: the server on screen with its stats, the place of the
channel tree (slice 2), the voice card (disconnect, copy an invite, hold to
talk) while voice is connecting or connected, and the user card with the
microphone and sound buttons.
- shell/topbar.rs: the page's title, the search box and the settings button;
the last two are logged until their slices exist.
- shell/main_panel.rs: "No server selected" with the way to add one, or the
server on screen with Connect, Disconnect and Edit.
- shell/form.rs: the server form (address, name, nickname, password; Save,
Save and connect, Cancel, and a Remove that asks twice) in the place of the
main area until the dialogs slice.
- shell/toast.rs: the status line as a toast for a few seconds.
The eleven callbacks of bind/servers.rs that the shell has are GPUI actions
(shell/actions.rs: select, connect, disconnect, mute the microphone, mute the
sound, push to talk, edit, save, save and connect, delete, invite): a click
dispatches one, the window's root view handles it by asking the root state.
The window takes its title from the server on screen ("Voelin - Nightfall"),
keeps a focus of its own so that actions always find their handlers, tells the
root state where it is (ui.window), and opens where it was left (the size
always; the position where a screen still shows it and the window manager
honours one). The logo is served by the assets.
scripts/gpui-shot.sh finds the window by its title's prefix now that the title
follows the server.
Tests on GPUI's test platform draw the window and click it: a server added
appears in the rail, a click selects it and titles the window, a connect
reaches the engine, an engine event updates the rail and the cards, the form
adds, edits and removes, the toast goes, the window's place round-trips, an
idle window is not told, the sample servers fill the shell.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
212 lines
6.2 KiB
Rust
212 lines
6.2 KiB
Rust
//! The server form: where a server is added or edited (the server dialog of
|
|
//! the Slint front end, `bookmark_form` / `save_bookmark` /
|
|
//! `save_and_connect` / `delete_bookmark` of `bind/servers.rs`). The dialogs
|
|
//! come with their slice; until then the form takes the place of the main
|
|
//! area, with gpui-component's text inputs: the address (the only thing a
|
|
//! server needs), a name (empty: the server's own), the nickname and the
|
|
//! server's password.
|
|
|
|
use gpui_kit::component::button::{Button, ButtonVariants as _};
|
|
use gpui_kit::component::input::{Input, InputEvent, InputState};
|
|
use gpui_kit::prelude::FluentBuilder as _;
|
|
use gpui_kit::{
|
|
App, AppContext as _, Context, Entity, FontWeight, InteractiveElement as _, IntoElement,
|
|
ParentElement as _, Render, SharedString, Styled as _, Window, div, px,
|
|
};
|
|
use voelin_ui_vm::bridge::BookmarkForm;
|
|
|
|
use super::actions::{CancelServerForm, DeleteServer, SaveAndConnect, SaveServer};
|
|
use super::widgets::{panel, tagged};
|
|
use crate::theme::{VoelinTheme, hsla};
|
|
|
|
/// The form.
|
|
pub struct ServerForm {
|
|
id: i64,
|
|
connected: bool,
|
|
address: Entity<InputState>,
|
|
name: Entity<InputState>,
|
|
nickname: Entity<InputState>,
|
|
password: Entity<InputState>,
|
|
confirm_remove: bool,
|
|
}
|
|
|
|
impl ServerForm {
|
|
/// A form filled in with `form` (id -1: a new server). The address has the
|
|
/// focus; Enter in any field saves.
|
|
pub fn new(form: &BookmarkForm, window: &mut Window, cx: &mut Context<Self>) -> Self {
|
|
let field = |window: &mut Window,
|
|
cx: &mut Context<Self>,
|
|
placeholder: &str,
|
|
value: &str,
|
|
masked: bool| {
|
|
let input = cx.new(|cx| {
|
|
InputState::new(window, cx)
|
|
.placeholder(SharedString::from(placeholder.to_owned()))
|
|
.default_value(SharedString::from(value.to_owned()))
|
|
.masked(masked)
|
|
});
|
|
cx.subscribe_in(&input, window, |_, _, event: &InputEvent, window, cx| {
|
|
if matches!(event, InputEvent::PressEnter { .. }) {
|
|
window.dispatch_action(Box::new(SaveServer), cx);
|
|
}
|
|
})
|
|
.detach();
|
|
input
|
|
};
|
|
let address =
|
|
field(window, cx, "ts.example.com or ts.example.com:9987", &form.address, false);
|
|
let name = field(window, cx, "Optional: the server tells its own", &form.name, false);
|
|
let nickname = field(window, cx, "The name others see", &form.nickname, false);
|
|
let password = field(window, cx, "Optional", &form.server_password, true);
|
|
address.update(cx, |input, cx| input.focus(window, cx));
|
|
Self {
|
|
id: i64::from(form.id),
|
|
connected: form.connected,
|
|
address,
|
|
name,
|
|
nickname,
|
|
password,
|
|
confirm_remove: false,
|
|
}
|
|
}
|
|
|
|
/// The bookmark this form edits; -1 for a new server.
|
|
pub fn id(&self) -> i64 {
|
|
self.id
|
|
}
|
|
|
|
/// The form as the fields hold it now, for `AppState::save_bookmark`.
|
|
pub fn to_form(&self, cx: &App) -> BookmarkForm {
|
|
let text = |input: &Entity<InputState>| input.read(cx).value().to_string();
|
|
BookmarkForm {
|
|
id: self.id as i32,
|
|
name: text(&self.name).into(),
|
|
address: text(&self.address).into(),
|
|
nickname: text(&self.nickname).into(),
|
|
server_password: text(&self.password).into(),
|
|
connected: self.connected,
|
|
..Default::default()
|
|
}
|
|
}
|
|
|
|
/// Put `text` in the address field (a link that fills the form comes with
|
|
/// its slice; the tests type here).
|
|
pub fn set_address(&self, text: &str, window: &mut Window, cx: &mut App) {
|
|
self.address.update(cx, |input, cx| input.set_value(text.to_owned(), window, cx));
|
|
}
|
|
}
|
|
|
|
fn labelled(
|
|
theme: &VoelinTheme,
|
|
label: &'static str,
|
|
input: &Entity<InputState>,
|
|
) -> impl IntoElement {
|
|
let (c, m) = (&theme.colors, &theme.metrics);
|
|
div()
|
|
.flex()
|
|
.flex_col()
|
|
.gap(px(m.space_2))
|
|
.child(
|
|
div()
|
|
.text_size(px(m.font_sm))
|
|
.font_weight(FontWeight::MEDIUM)
|
|
.text_color(hsla(c.text_secondary))
|
|
.child(label),
|
|
)
|
|
.child(Input::new(input))
|
|
}
|
|
|
|
impl Render for ServerForm {
|
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
|
let theme = VoelinTheme::global(cx).clone();
|
|
let (c, m) = (&theme.colors, &theme.metrics);
|
|
let new = self.id < 0;
|
|
let id = self.id;
|
|
let confirm = self.confirm_remove;
|
|
panel(&theme)
|
|
.id("server-form")
|
|
.debug_selector(|| "server-form".into())
|
|
.flex_1()
|
|
.min_w_0()
|
|
.h_full()
|
|
.items_center()
|
|
.justify_center()
|
|
.child(
|
|
div()
|
|
.w_full()
|
|
.max_w(px(440.0))
|
|
.flex()
|
|
.flex_col()
|
|
.gap(px(m.space_4))
|
|
.p(px(m.space_5))
|
|
.child(
|
|
div()
|
|
.text_size(px(m.font_xl))
|
|
.font_weight(FontWeight::SEMIBOLD)
|
|
.text_color(hsla(c.text))
|
|
.child(if new { "Add a server" } else { "Edit the server" }),
|
|
)
|
|
.child(labelled(&theme, "Address", &self.address))
|
|
.child(labelled(&theme, "Name", &self.name))
|
|
.child(labelled(&theme, "Nickname", &self.nickname))
|
|
.child(labelled(&theme, "Server password", &self.password))
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.flex_row()
|
|
.items_center()
|
|
.gap(px(m.space_3))
|
|
.child(tagged(
|
|
"form-save",
|
|
Button::new("form-save").primary().label("Save").on_click(
|
|
|_, window, cx| {
|
|
window.dispatch_action(Box::new(SaveServer), cx)
|
|
},
|
|
),
|
|
))
|
|
.when(!self.connected, |row| {
|
|
row.child(tagged(
|
|
"form-connect",
|
|
Button::new("form-connect").label("Save and connect").on_click(
|
|
|_, window, cx| {
|
|
window.dispatch_action(Box::new(SaveAndConnect), cx)
|
|
},
|
|
),
|
|
))
|
|
})
|
|
.child(tagged(
|
|
"form-cancel",
|
|
Button::new("form-cancel").ghost().label("Cancel").on_click(
|
|
|_, window, cx| {
|
|
window.dispatch_action(Box::new(CancelServerForm), cx)
|
|
},
|
|
),
|
|
))
|
|
.when(!new, |row| {
|
|
row.child(div().flex_1()).child(tagged(
|
|
"form-remove",
|
|
Button::new("form-remove")
|
|
.danger()
|
|
.label(if confirm {
|
|
"Click again to remove"
|
|
} else {
|
|
"Remove"
|
|
})
|
|
.on_click(cx.listener(move |this, _, window, cx| {
|
|
if this.confirm_remove {
|
|
window.dispatch_action(
|
|
Box::new(DeleteServer { id }),
|
|
cx,
|
|
);
|
|
} else {
|
|
this.confirm_remove = true;
|
|
cx.notify();
|
|
}
|
|
})),
|
|
))
|
|
}),
|
|
),
|
|
)
|
|
}
|
|
}
|