Implement WindowContext::remove_window
This commit is contained in:
parent
089bf58934
commit
c1ca7ad41d
3 changed files with 15 additions and 6 deletions
|
@ -789,10 +789,13 @@ impl Context for AppContext {
|
||||||
|
|
||||||
let root_view = window.root_view.clone().unwrap();
|
let root_view = window.root_view.clone().unwrap();
|
||||||
let result = update(root_view, &mut WindowContext::new(cx, &mut window));
|
let result = update(root_view, &mut WindowContext::new(cx, &mut window));
|
||||||
|
|
||||||
|
if !window.removed {
|
||||||
cx.windows
|
cx.windows
|
||||||
.get_mut(handle.id)
|
.get_mut(handle.id)
|
||||||
.ok_or_else(|| anyhow!("window not found"))?
|
.ok_or_else(|| anyhow!("window not found"))?
|
||||||
.replace(window);
|
.replace(window);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
})
|
})
|
||||||
|
|
|
@ -159,6 +159,7 @@ impl Drop for FocusHandle {
|
||||||
// Holds the state for a specific window.
|
// Holds the state for a specific window.
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
pub(crate) handle: AnyWindowHandle,
|
pub(crate) handle: AnyWindowHandle,
|
||||||
|
pub(crate) removed: bool,
|
||||||
platform_window: Box<dyn PlatformWindow>,
|
platform_window: Box<dyn PlatformWindow>,
|
||||||
display_id: DisplayId,
|
display_id: DisplayId,
|
||||||
sprite_atlas: Arc<dyn PlatformAtlas>,
|
sprite_atlas: Arc<dyn PlatformAtlas>,
|
||||||
|
@ -229,6 +230,7 @@ impl Window {
|
||||||
|
|
||||||
Window {
|
Window {
|
||||||
handle,
|
handle,
|
||||||
|
removed: false,
|
||||||
platform_window,
|
platform_window,
|
||||||
display_id,
|
display_id,
|
||||||
sprite_atlas,
|
sprite_atlas,
|
||||||
|
@ -320,6 +322,11 @@ impl<'a> WindowContext<'a> {
|
||||||
self.window.dirty = true;
|
self.window.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Close this window.
|
||||||
|
pub fn remove_window(&mut self) {
|
||||||
|
self.window.removed = true;
|
||||||
|
}
|
||||||
|
|
||||||
/// Obtain a new `FocusHandle`, which allows you to track and manipulate the keyboard focus
|
/// Obtain a new `FocusHandle`, which allows you to track and manipulate the keyboard focus
|
||||||
/// for elements rendered within this window.
|
/// for elements rendered within this window.
|
||||||
pub fn focus_handle(&mut self) -> FocusHandle {
|
pub fn focus_handle(&mut self) -> FocusHandle {
|
||||||
|
|
|
@ -621,8 +621,7 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
project2::Event::Closed => {
|
project2::Event::Closed => {
|
||||||
// todo!()
|
cx.remove_window();
|
||||||
// cx.remove_window();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
project2::Event::DeletedEntry(entry_id) => {
|
project2::Event::DeletedEntry(entry_id) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue