mirror of
https://github.com/l0ng-ai/tty7.git
synced 2026-11-21 08:05:52 +00:00
Settings used to cover the workspace it was opened from, hiding the terminal a setting was being tried on. It now opens a separate window. - The state and page stay on the workspace's Tty7App; a thin SettingsWindow view borrows it to draw, observes it to repaint, and sets its own rem size. The state is built against the new window, so its inputs and subscriptions belong to it. - Opening again raises the window instead of closing it. Esc, Cmd-W and the close button go through close_settings_checked, so unsaved forms and theme drafts still prompt; closing hands focus back to the workspace window. The window goes when its owner is released. - open_settings_then / close_settings_then run follow-ups in the right window: loading an SSH form happens in the settings window, and Connect opens its tab in the workspace window. - Window opacity, blur and backdrop are pushed to every window, since they are now changed from a window that is not the workspace. - Tests keep the in-window overlay so they can drive settings through their single test window.
112 lines
4.7 KiB
Rust
112 lines
4.7 KiB
Rust
//! Settings in a window of its own.
|
|
//!
|
|
//! The settings page used to cover the workspace it was opened from, which hid
|
|
//! the terminal a setting was being tried out on. It now opens beside it. The
|
|
//! state and the page itself still belong to the workspace's `Tty7App` — this
|
|
//! window only borrows it to draw — so every setting keeps the one code path it
|
|
//! had, and a change repaints both windows.
|
|
|
|
use gpui::{
|
|
App, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render,
|
|
Styled as _, Subscription, TitlebarOptions, WeakEntity, Window, WindowBounds,
|
|
WindowDecorations, WindowOptions, prelude::FluentBuilder as _, px, size,
|
|
};
|
|
use gpui_component::{ActiveTheme as _, TitleBar};
|
|
|
|
use crate::core::actions::{CloseActiveTab, OpenSettings};
|
|
use crate::core::config::Config;
|
|
use crate::ui::app::Tty7App;
|
|
|
|
/// Big enough for the navigation column and a comfortable page beside it.
|
|
const DEFAULT_SIZE: (f32, f32) = (960., 700.);
|
|
const MIN_SIZE: (f32, f32) = (720., 480.);
|
|
|
|
pub(crate) fn window_options(cx: &mut App) -> WindowOptions {
|
|
WindowOptions {
|
|
window_bounds: Some(WindowBounds::Windowed(gpui::Bounds::centered(
|
|
None,
|
|
size(px(DEFAULT_SIZE.0), px(DEFAULT_SIZE.1)),
|
|
cx,
|
|
))),
|
|
app_id: Some("tty7".to_owned()),
|
|
titlebar: Some(TitlebarOptions {
|
|
traffic_light_position: Some(crate::ui::theme::traffic_light_position()),
|
|
..TitleBar::title_bar_options()
|
|
}),
|
|
window_decorations: Some(WindowDecorations::Client),
|
|
window_background: crate::ui::theme::background_appearance(cx),
|
|
window_min_size: Some(size(px(MIN_SIZE.0), px(MIN_SIZE.1))),
|
|
..Default::default()
|
|
}
|
|
}
|
|
|
|
pub(crate) struct SettingsWindow {
|
|
app: WeakEntity<Tty7App>,
|
|
_observe: Subscription,
|
|
_release: Subscription,
|
|
}
|
|
|
|
impl SettingsWindow {
|
|
pub(crate) fn new(app: &Entity<Tty7App>, window: &mut Window, cx: &mut Context<Self>) -> Self {
|
|
// Every settings change notifies the app, not this view; without this
|
|
// the page would change underneath and never repaint here.
|
|
let observe = cx.observe(app, |_, _, cx| cx.notify());
|
|
// The workspace that owns the page is gone, so the page is too.
|
|
let release = cx.observe_release_in(app, window, |_, _, window, _| window.remove_window());
|
|
// The close button asks the same question Escape does: a half-edited
|
|
// form or theme draft gets its prompt, and the window only goes once
|
|
// it is answered.
|
|
let weak = app.downgrade();
|
|
window.on_window_should_close(cx, move |window, cx| match weak.upgrade() {
|
|
Some(app) => {
|
|
app.update(cx, |this, cx| this.close_settings_checked(window, cx));
|
|
false
|
|
}
|
|
None => true,
|
|
});
|
|
Self {
|
|
app: app.downgrade(),
|
|
_observe: observe,
|
|
_release: release,
|
|
}
|
|
}
|
|
|
|
fn close(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
|
if let Some(app) = self.app.upgrade() {
|
|
app.update(cx, |this, cx| this.close_settings_checked(window, cx));
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Render for SettingsWindow {
|
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
|
// The workspace window sets this in its own render; a second window
|
|
// has to, or the page lays out against the default 16px rem.
|
|
window.set_rem_size(px(cx.global::<Config>().ui_font_size));
|
|
let page = self.app.upgrade().map(|app| {
|
|
let page = app.update(cx, |this, cx| {
|
|
// The state can be gone for a frame between closing and the
|
|
// window being removed.
|
|
this.has_settings()
|
|
.then(|| this.render_settings(window, cx).into_any_element())
|
|
});
|
|
if page.is_none() {
|
|
// Closed without passing through `close_settings` — nothing
|
|
// is left to draw, so the window goes too.
|
|
app.update(cx, |this, cx| this.forget_settings_window(cx));
|
|
window.remove_window();
|
|
}
|
|
page
|
|
});
|
|
gpui::div()
|
|
.size_full()
|
|
.bg(crate::ui::theme::overlay_background(cx))
|
|
.text_color(cx.theme().foreground)
|
|
// ⌘W closes this window the way it closes a tab in a workspace.
|
|
.on_action(cx.listener(|this, _: &CloseActiveTab, window, cx| this.close(window, cx)))
|
|
// ⌘, lands here while this window has focus; it is already open.
|
|
.on_action(cx.listener(|_, _: &OpenSettings, window, _| window.activate_window()))
|
|
.when_some(page.flatten(), |root, page| root.child(page))
|
|
}
|
|
}
|