Automatically hide "View Panel" notification after refocusing Zed (#27512)
Now if you refocus Zed manually (e.g. cmd-tab), we hide the "View Panel" notification automatically. This also fixes a related subscription leak. Release Notes: - N/A
This commit is contained in:
parent
85740ddaa4
commit
7537f0557f
1 changed files with 55 additions and 29 deletions
|
@ -47,6 +47,7 @@ pub struct ActiveThread {
|
||||||
last_error: Option<ThreadError>,
|
last_error: Option<ThreadError>,
|
||||||
pop_ups: Vec<WindowHandle<ToolReadyPopUp>>,
|
pop_ups: Vec<WindowHandle<ToolReadyPopUp>>,
|
||||||
_subscriptions: Vec<Subscription>,
|
_subscriptions: Vec<Subscription>,
|
||||||
|
pop_up_subscriptions: HashMap<WindowHandle<ToolReadyPopUp>, Vec<Subscription>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RenderedMessage {
|
struct RenderedMessage {
|
||||||
|
@ -253,6 +254,7 @@ impl ActiveThread {
|
||||||
last_error: None,
|
last_error: None,
|
||||||
pop_ups: Vec::new(),
|
pop_ups: Vec::new(),
|
||||||
_subscriptions: subscriptions,
|
_subscriptions: subscriptions,
|
||||||
|
pop_up_subscriptions: HashMap::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
for message in thread.read(cx).messages().cloned().collect::<Vec<_>>() {
|
for message in thread.read(cx).messages().cloned().collect::<Vec<_>>() {
|
||||||
|
@ -548,7 +550,10 @@ impl ActiveThread {
|
||||||
.log_err()
|
.log_err()
|
||||||
{
|
{
|
||||||
if let Some(pop_up) = screen_window.entity(cx).log_err() {
|
if let Some(pop_up) = screen_window.entity(cx).log_err() {
|
||||||
cx.subscribe_in(&pop_up, window, {
|
self.pop_up_subscriptions
|
||||||
|
.entry(screen_window)
|
||||||
|
.or_insert_with(Vec::new)
|
||||||
|
.push(cx.subscribe_in(&pop_up, window, {
|
||||||
|this, _, event, window, cx| match event {
|
|this, _, event, window, cx| match event {
|
||||||
ToolReadyPopupEvent::Accepted => {
|
ToolReadyPopupEvent::Accepted => {
|
||||||
let handle = window.window_handle();
|
let handle = window.window_handle();
|
||||||
|
@ -562,10 +567,12 @@ impl ActiveThread {
|
||||||
.update(cx, |_view, window, _cx| {
|
.update(cx, |_view, window, _cx| {
|
||||||
window.activate_window();
|
window.activate_window();
|
||||||
|
|
||||||
if let Some(workspace) = workspace_handle.upgrade()
|
if let Some(workspace) =
|
||||||
|
workspace_handle.upgrade()
|
||||||
{
|
{
|
||||||
workspace.update(_cx, |workspace, cx| {
|
workspace.update(_cx, |workspace, cx| {
|
||||||
workspace.focus_panel::<AssistantPanel>(
|
workspace
|
||||||
|
.focus_panel::<AssistantPanel>(
|
||||||
window, cx,
|
window, cx,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -580,10 +587,27 @@ impl ActiveThread {
|
||||||
this.dismiss_notifications(cx);
|
this.dismiss_notifications(cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}));
|
||||||
.detach();
|
|
||||||
|
|
||||||
self.pop_ups.push(screen_window);
|
self.pop_ups.push(screen_window);
|
||||||
|
|
||||||
|
// If the user manually refocuses the original window, dismiss the popup.
|
||||||
|
self.pop_up_subscriptions
|
||||||
|
.entry(screen_window)
|
||||||
|
.or_insert_with(Vec::new)
|
||||||
|
.push({
|
||||||
|
let pop_up_weak = pop_up.downgrade();
|
||||||
|
|
||||||
|
cx.observe_window_activation(window, move |_, window, cx| {
|
||||||
|
if window.is_window_active() {
|
||||||
|
if let Some(pop_up) = pop_up_weak.upgrade() {
|
||||||
|
pop_up.update(cx, |_, cx| {
|
||||||
|
cx.emit(ToolReadyPopupEvent::Dismissed);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1750,6 +1774,8 @@ impl ActiveThread {
|
||||||
window.remove_window();
|
window.remove_window();
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
|
self.pop_up_subscriptions.remove(&window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue