Add last window closed setting (#25185)
Release Notes: - Added an `on_last_window_closed` setting, that allows users to quit the app when the last window is closed --------- Co-authored-by: Richard <richard@zed.dev>
This commit is contained in:
parent
ffc7558a1d
commit
40425093df
8 changed files with 171 additions and 8 deletions
|
@ -1804,6 +1804,7 @@ impl Workspace {
|
|||
}
|
||||
|
||||
pub fn close_window(&mut self, _: &CloseWindow, window: &mut Window, cx: &mut Context<Self>) {
|
||||
println!("workspace::close_window");
|
||||
let prepare = self.prepare_to_close(CloseIntent::CloseWindow, window, cx);
|
||||
cx.spawn_in(window, |_, mut cx| async move {
|
||||
if prepare.await? {
|
||||
|
|
|
@ -18,11 +18,31 @@ pub struct WorkspaceSettings {
|
|||
pub autosave: AutosaveSetting,
|
||||
pub restore_on_startup: RestoreOnStartupBehavior,
|
||||
pub drop_target_size: f32,
|
||||
pub when_closing_with_no_tabs: CloseWindowWhenNoItems,
|
||||
pub use_system_path_prompts: bool,
|
||||
pub command_aliases: HashMap<String, String>,
|
||||
pub show_user_picture: bool,
|
||||
pub max_tabs: Option<NonZeroUsize>,
|
||||
pub when_closing_with_no_tabs: CloseWindowWhenNoItems,
|
||||
pub on_last_window_closed: OnLastWindowClosed,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum OnLastWindowClosed {
|
||||
/// Match platform conventions by default, so don't quit on macOS, and quit on other platforms
|
||||
#[default]
|
||||
PlatformDefault,
|
||||
/// Quit the application the last window is closed
|
||||
QuitApp,
|
||||
}
|
||||
|
||||
impl OnLastWindowClosed {
|
||||
pub fn is_quit_app(&self) -> bool {
|
||||
match self {
|
||||
OnLastWindowClosed::PlatformDefault => false,
|
||||
OnLastWindowClosed::QuitApp => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||
|
@ -136,11 +156,15 @@ pub struct WorkspaceSettingsContent {
|
|||
///
|
||||
/// Default: true
|
||||
pub show_user_picture: Option<bool>,
|
||||
// Maximum open tabs in a pane. Will not close an unsaved
|
||||
// tab. Set to `None` for unlimited tabs.
|
||||
//
|
||||
// Default: none
|
||||
/// Maximum open tabs in a pane. Will not close an unsaved
|
||||
/// tab. Set to `None` for unlimited tabs.
|
||||
///
|
||||
/// Default: none
|
||||
pub max_tabs: Option<NonZeroUsize>,
|
||||
/// What to do when the last window is closed
|
||||
///
|
||||
/// Default: auto (nothing on macOS, "app quit" otherwise)
|
||||
pub on_last_window_closed: Option<OnLastWindowClosed>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue