Merge pull request #1019 from panekj/fix/window

fix: add CloseWindow command, properly handle window/app closing
This commit is contained in:
Dongdong Zhou 2022-08-31 19:26:41 +01:00 committed by GitHub
commit ba3f6d6b95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 1 deletions

View File

@ -1,3 +1,9 @@
# --------------------------------- Window ---------------------------------------------
[[keymaps]]
command = "window_close"
key = "Meta+Shift+W"
# --------------------------------- General --------------------------------------------
[[keymaps]]

View File

@ -1,3 +1,9 @@
# --------------------------------- Window ---------------------------------------------
[[keymaps]]
command = "close_window"
key = "Alt+F4"
# --------------------------------- General --------------------------------------------
[[keymaps]]

View File

@ -273,6 +273,10 @@ pub enum LapceWorkbenchCommand {
#[strum(serialize = "new_window")]
NewWindow,
#[strum(message = "Close Window")]
#[strum(serialize = "close_window")]
CloseWindow,
#[strum(message = "New File")]
#[strum(serialize = "new_file")]
NewFile,
@ -566,6 +570,7 @@ pub enum LapceUICommand {
FilterItems,
RestartToUpdate(PathBuf, ReleaseInfo),
NewWindow(WindowId),
CloseWindow(WindowId),
ReloadWindow,
CloseBuffers(Vec<BufferId>),
RequestPaintRect(Rect),

View File

@ -1401,6 +1401,13 @@ pub fn run_workbench_command(
Target::Global,
));
}
LapceWorkbenchCommand::CloseWindow => {
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::CloseWindow(self.window_id),
Target::Auto,
));
}
LapceWorkbenchCommand::ReloadWindow => {
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,

View File

@ -498,6 +498,15 @@ fn command(
ctx.new_window(desc);
return druid::Handled::Yes;
}
LapceUICommand::CloseWindow(window_id) => {
ctx.submit_command(Command::new(
druid::commands::CLOSE_WINDOW,
(),
Target::Window(*window_id),
));
let _ = data.db.save_app(data);
return druid::Handled::Yes;
}
_ => (),
}
}

View File

@ -829,7 +829,11 @@ pub fn window_controls(
commands.push((
close_rect,
Command::new(druid::commands::QUIT_APP, (), Target::Global),
Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::CloseWindow(window_id),
Target::Auto,
),
));
let hover_color = {