Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: new windows would never be created after closing all #1651

Merged
merged 2 commits into from Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,8 @@

### Bug Fixes

- [#1588](https://github.com/lapce/lapce/issues/1588): Fixed an issue where new windows would never be created after closing all windows on macOS.
I-Info marked this conversation as resolved.
Show resolved Hide resolved

## 0.2.2

### Features/Changes
Expand Down
109 changes: 56 additions & 53 deletions lapce-ui/src/app.rs
Expand Up @@ -289,6 +289,58 @@ impl LapceAppDelegate {
pub fn new() -> Self {
Self {}
}

fn new_window(
window_id: &WindowId,
ctx: &mut druid::DelegateCtx,
data: &mut LapceData,
) {
let (size, pos) = data
.windows
.get(window_id)
// If maximised, use default dimensions instead
.filter(|win| !win.maximised)
.map(|win| (win.size, win.pos + (50.0, 50.0)))
.unwrap_or_else(|| {
data.db
.get_last_window_info()
.map(|i| (i.size, i.pos))
.unwrap_or_else(|_| {
(Size::new(800.0, 600.0), Point::new(0.0, 0.0))
})
});
let info = WindowInfo {
size,
pos,
maximised: false,
tabs: TabsInfo {
active_tab: 0,
workspaces: vec![],
},
};
let mut window_data = LapceWindowData::new(
data.keypress.clone(),
data.latest_release.clone(),
data.update_in_process,
data.log_file.clone(),
data.panel_orders.clone(),
ctx.get_external_handle(),
&info,
data.db.clone(),
);
let root = build_window(&mut window_data);
let window_id = window_data.window_id;
data.windows.insert(window_id, window_data.clone());
let desc = new_window_desc(
window_id,
root,
info.size,
info.pos,
info.maximised,
&window_data.config,
);
ctx.new_window(desc);
}
}

impl Default for LapceAppDelegate {
Expand All @@ -313,11 +365,9 @@ impl AppDelegate<LapceData> for LapceAppDelegate {
}
Event::ApplicationShouldHandleReopen(has_visible_windows) => {
if !has_visible_windows {
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::NewWindow(WindowId::next()),
Target::Global,
));
// Create new window immediately
let new_window_id = WindowId::next();
Self::new_window(&new_window_id, ctx, data);
}
return None;
}
Expand Down Expand Up @@ -543,54 +593,7 @@ impl AppDelegate<LapceData> for LapceAppDelegate {
return druid::Handled::Yes;
}
LapceUICommand::NewWindow(from_window_id) => {
let (size, pos) = data
.windows
.get(from_window_id)
// If maximised, use default dimensions instead
.filter(|win| !win.maximised)
.map(|win| (win.size, win.pos + (50.0, 50.0)))
.unwrap_or_else(|| {
data.db
.get_last_window_info()
.map(|i| (i.size, i.pos))
.unwrap_or_else(|_| {
(
Size::new(800.0, 600.0),
Point::new(0.0, 0.0),
)
})
});
let info = WindowInfo {
size,
pos,
maximised: false,
tabs: TabsInfo {
active_tab: 0,
workspaces: vec![],
},
};
let mut window_data = LapceWindowData::new(
data.keypress.clone(),
data.latest_release.clone(),
data.update_in_process,
data.log_file.clone(),
data.panel_orders.clone(),
ctx.get_external_handle(),
&info,
data.db.clone(),
);
let root = build_window(&mut window_data);
let window_id = window_data.window_id;
data.windows.insert(window_id, window_data.clone());
let desc = new_window_desc(
window_id,
root,
info.size,
info.pos,
info.maximised,
&window_data.config,
);
ctx.new_window(desc);
Self::new_window(from_window_id, ctx, data);
return druid::Handled::Yes;
}
LapceUICommand::CloseWindow(window_id) => {
Expand Down