Quit from any window, Settings too, asks about unsaved tabs in front (X-01)

This commit is contained in:
ZacharyZhang-NY committed 2026-10-09 11:37:56 -04:00
1 parent 943411fb1a
commit 8a915ea354
15 files changed
+107 -19

No files matched your search

+26 -3
View File
@@ -3,7 +3,7 @@
use std::path::PathBuf;
use ely_gpui_component::primitives::Severity;
use ely_ui::commands::{CloseTab, Open, Quit, Save, SaveAs};
use ely_ui::commands::{CloseTab, Open, Save, SaveAs};
use gpui::{App, AppContext as _, Context, PathPromptOptions, TaskExt as _, Window};
use crate::{Dialog, Engine, Host, Opening, Saving, Tabs, in_window, text};
@@ -41,8 +41,31 @@ pub trait Closing: Host {
}
}
fn on_quit(&mut self, _: &Quit, window: &mut Window, cx: &mut Context<Self>) {
self.proceed(After::Quit, window, cx);
/// Takes `window` as home; quit anywhere asks here first.
fn own_window(&mut self, window: &Window, cx: &mut Context<Self>) {
let handle = window.window_handle();
self.core_mut().window = Some(handle);
let host = cx.entity().downgrade();
ely_ui::commands::route_quit(cx, move |cx| {
let host = host.clone();
// The asking window is busy until its action ends.
cx.defer(move |cx| {
let asked = handle.update(cx, |_, window, cx| {
// The question shows in front, with the keys.
window.activate_window();
host.update(cx, |host, cx| {
host.quitting(cx);
host.proceed(After::Quit, window, cx);
})
});
match asked {
Ok(Ok(())) => {}
// No home window is left to ask in.
_ if handle.update(cx, |_, _, _| ()).is_err() => cx.quit(),
Ok(Err(error)) | Err(error) => log::error!("office: the quit was not asked: {error}"),
}
});
});
}
fn no_document(&self, cx: &mut Context<Self>) {
+2
View File
@@ -72,6 +72,8 @@ pub trait Host: Sized + 'static {
fn observed(&mut self, id: u64, view: &Entity<View<Self>>, cx: &mut Context<Self>);
/// Runs before a search first moves the cursor.
fn search_leaves(&mut self, _: &mut Context<Self>) {}
/// Runs as a quit starts, before any tab closes.
fn quitting(&mut self, _: &mut Context<Self>) {}
/// Runs when a close stops: question or save cancelled.
fn close_cancelled(&mut self, _: &mut Context<Self>) {}
/// An outside change met a save; true if shown.
+26 -1
View File
@@ -1,5 +1,7 @@
use ely_platform::AppId;
use gpui::{Action, App, KeyBinding, Menu, MenuItem, SharedString, Window, actions};
use std::rc::Rc;
use gpui::{Action, App, Global, KeyBinding, Menu, MenuItem, SharedString, Window, actions};
use crate::i18n;
@@ -25,6 +27,29 @@ actions!(
[OpenElyDoc, OpenElyTable, OpenElyShow, OpenElyPdf, OpenElyMail, OpenElyTree, OpenElyMark, OpenElyAgent]
);
/// The main window's own quit, run from any window.
struct QuitRoute(Rc<dyn Fn(&mut App)>);
impl Global for QuitRoute {}
/// Quit from every window, settings too, runs `quit`.
pub fn route_quit(cx: &mut App, quit: impl Fn(&mut App) + 'static) {
cx.set_global(QuitRoute(Rc::new(quit)));
}
/// Quit, from any window, goes through `quit`.
pub fn bind_quit(cx: &mut App) {
cx.on_action(|_: &Quit, cx| quit(cx));
}
/// Quits through the main window's route, if one is set.
fn quit(cx: &mut App) {
match cx.try_global::<QuitRoute>().map(|route| Rc::clone(&route.0)) {
Some(route) => route(cx),
None => cx.quit(),
}
}
/// The action that starts `app` (§16 app switching).
pub fn switch_to(app: AppId) -> Box<dyn Action> {
match app {
+1 -1
View File
@@ -74,7 +74,7 @@ fn open<V: Render>(
theme::install(cx);
crate::i18n::install(cx);
crate::commands::bind_keys(cx);
cx.on_action(|_: &crate::commands::Quit, cx| cx.quit());
crate::commands::bind_quit(cx);
cx.on_action(move |_: &crate::commands::OpenSettings, cx| crate::settings::open(app, cx));
let mut options = WindowOptions {
focus: smoke == Smoke::Off,