Move settings subscription to dock

Reduces likelihood of panels being unable to move themselves
This commit is contained in:
Conrad Irwin 2024-01-13 22:35:33 -07:00
parent fee369bca1
commit 898645681f
6 changed files with 13 additions and 62 deletions

View file

@ -192,17 +192,6 @@ impl AssistantPanel {
retrieve_context_in_next_inline_assist: false,
};
let mut old_dock_position = this.position(cx);
this.subscriptions =
vec![cx.observe_global::<SettingsStore>(move |this, cx| {
let new_dock_position = this.position(cx);
if new_dock_position != old_dock_position {
old_dock_position = new_dock_position;
cx.emit(PanelEvent::ChangePosition);
}
cx.notify();
})];
this
})
})

View file

@ -127,17 +127,6 @@ impl ChatPanel {
open_context_menu: None,
};
let mut old_dock_position = this.position(cx);
this.subscriptions.push(cx.observe_global::<SettingsStore>(
move |this: &mut Self, cx| {
let new_dock_position = this.position(cx);
if new_dock_position != old_dock_position {
old_dock_position = new_dock_position;
cx.emit(PanelEvent::ChangePosition);
}
cx.notify();
},
));
this.subscriptions.push(cx.subscribe(
&ActiveCall::global(cx),
move |this: &mut Self, call, event: &room::Event, cx| match event {

View file

@ -254,19 +254,6 @@ impl CollabPanel {
this.update_entries(false, cx);
// Update the dock position when the setting changes.
let mut old_dock_position = this.position(cx);
this.subscriptions.push(cx.observe_global::<SettingsStore>(
move |this: &mut Self, cx| {
let new_dock_position = this.position(cx);
if new_dock_position != old_dock_position {
old_dock_position = new_dock_position;
cx.emit(PanelEvent::ChangePosition);
}
cx.notify();
},
));
let active_call = ActiveCall::global(cx);
this.subscriptions
.push(cx.observe(&this.user_store, |this, _, cx| {

View file

@ -246,18 +246,6 @@ impl ProjectPanel {
};
this.update_visible_entries(None, cx);
// Update the dock position when the setting changes.
let mut old_dock_position = this.position(cx);
ProjectPanelSettings::register(cx);
cx.observe_global::<SettingsStore>(move |this, cx| {
let new_dock_position = this.position(cx);
if new_dock_position != old_dock_position {
old_dock_position = new_dock_position;
cx.emit(PanelEvent::ChangePosition);
}
})
.detach();
this
});

View file

@ -159,15 +159,6 @@ impl TerminalPanel {
height: None,
_subscriptions: subscriptions,
};
let mut old_dock_position = this.position(cx);
cx.observe_global::<SettingsStore>(move |this, cx| {
let new_dock_position = this.position(cx);
if new_dock_position != old_dock_position {
old_dock_position = new_dock_position;
cx.emit(PanelEvent::ChangePosition);
}
})
.detach();
this
}

View file

@ -7,6 +7,7 @@ use gpui::{
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use settings::SettingsStore;
use std::sync::Arc;
use ui::{h_stack, ContextMenu, IconButton, Tooltip};
use ui::{prelude::*, right_click_menu};
@ -14,7 +15,6 @@ use ui::{prelude::*, right_click_menu};
const RESIZE_HANDLE_SIZE: Pixels = Pixels(6.);
pub enum PanelEvent {
ChangePosition,
ZoomIn,
ZoomOut,
Activate,
@ -177,7 +177,7 @@ impl DockPosition {
struct PanelEntry {
panel: Arc<dyn PanelHandle>,
_subscriptions: [Subscription; 2],
_subscriptions: [Subscription; 3],
}
pub struct PanelButtons {
@ -321,9 +321,15 @@ impl Dock {
) {
let subscriptions = [
cx.observe(&panel, |_, _, cx| cx.notify()),
cx.subscribe(&panel, move |this, panel, event, cx| match event {
PanelEvent::ChangePosition => {
cx.observe_global::<SettingsStore>({
let workspace = workspace.clone();
let panel = panel.clone();
move |this, cx| {
let new_position = panel.read(cx).position(cx);
if new_position == this.position {
return;
}
let Ok(new_dock) = workspace.update(cx, |workspace, cx| {
if panel.is_zoomed(cx) {
@ -354,6 +360,8 @@ impl Dock {
}
});
}
}),
cx.subscribe(&panel, move |this, panel, event, cx| match event {
PanelEvent::ZoomIn => {
this.set_panel_zoomed(&panel.to_any(), true, cx);
if !panel.focus_handle(cx).contains_focused(cx) {
@ -735,9 +743,8 @@ pub mod test {
true
}
fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>) {
fn set_position(&mut self, position: DockPosition, _: &mut ViewContext<Self>) {
self.position = position;
cx.emit(PanelEvent::ChangePosition);
}
fn size(&self, _: &WindowContext) -> Pixels {