Move settings subscription to dock
Reduces likelihood of panels being unable to move themselves
This commit is contained in:
parent
fee369bca1
commit
898645681f
6 changed files with 13 additions and 62 deletions
|
@ -192,17 +192,6 @@ impl AssistantPanel {
|
||||||
retrieve_context_in_next_inline_assist: false,
|
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
|
this
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -127,17 +127,6 @@ impl ChatPanel {
|
||||||
open_context_menu: None,
|
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(
|
this.subscriptions.push(cx.subscribe(
|
||||||
&ActiveCall::global(cx),
|
&ActiveCall::global(cx),
|
||||||
move |this: &mut Self, call, event: &room::Event, cx| match event {
|
move |this: &mut Self, call, event: &room::Event, cx| match event {
|
||||||
|
|
|
@ -254,19 +254,6 @@ impl CollabPanel {
|
||||||
|
|
||||||
this.update_entries(false, cx);
|
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);
|
let active_call = ActiveCall::global(cx);
|
||||||
this.subscriptions
|
this.subscriptions
|
||||||
.push(cx.observe(&this.user_store, |this, _, cx| {
|
.push(cx.observe(&this.user_store, |this, _, cx| {
|
||||||
|
|
|
@ -246,18 +246,6 @@ impl ProjectPanel {
|
||||||
};
|
};
|
||||||
this.update_visible_entries(None, cx);
|
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
|
this
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -159,15 +159,6 @@ impl TerminalPanel {
|
||||||
height: None,
|
height: None,
|
||||||
_subscriptions: subscriptions,
|
_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
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ use gpui::{
|
||||||
};
|
};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use settings::SettingsStore;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use ui::{h_stack, ContextMenu, IconButton, Tooltip};
|
use ui::{h_stack, ContextMenu, IconButton, Tooltip};
|
||||||
use ui::{prelude::*, right_click_menu};
|
use ui::{prelude::*, right_click_menu};
|
||||||
|
@ -14,7 +15,6 @@ use ui::{prelude::*, right_click_menu};
|
||||||
const RESIZE_HANDLE_SIZE: Pixels = Pixels(6.);
|
const RESIZE_HANDLE_SIZE: Pixels = Pixels(6.);
|
||||||
|
|
||||||
pub enum PanelEvent {
|
pub enum PanelEvent {
|
||||||
ChangePosition,
|
|
||||||
ZoomIn,
|
ZoomIn,
|
||||||
ZoomOut,
|
ZoomOut,
|
||||||
Activate,
|
Activate,
|
||||||
|
@ -177,7 +177,7 @@ impl DockPosition {
|
||||||
|
|
||||||
struct PanelEntry {
|
struct PanelEntry {
|
||||||
panel: Arc<dyn PanelHandle>,
|
panel: Arc<dyn PanelHandle>,
|
||||||
_subscriptions: [Subscription; 2],
|
_subscriptions: [Subscription; 3],
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PanelButtons {
|
pub struct PanelButtons {
|
||||||
|
@ -321,9 +321,15 @@ impl Dock {
|
||||||
) {
|
) {
|
||||||
let subscriptions = [
|
let subscriptions = [
|
||||||
cx.observe(&panel, |_, _, cx| cx.notify()),
|
cx.observe(&panel, |_, _, cx| cx.notify()),
|
||||||
cx.subscribe(&panel, move |this, panel, event, cx| match event {
|
cx.observe_global::<SettingsStore>({
|
||||||
PanelEvent::ChangePosition => {
|
let workspace = workspace.clone();
|
||||||
|
let panel = panel.clone();
|
||||||
|
|
||||||
|
move |this, cx| {
|
||||||
let new_position = panel.read(cx).position(cx);
|
let new_position = panel.read(cx).position(cx);
|
||||||
|
if new_position == this.position {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let Ok(new_dock) = workspace.update(cx, |workspace, cx| {
|
let Ok(new_dock) = workspace.update(cx, |workspace, cx| {
|
||||||
if panel.is_zoomed(cx) {
|
if panel.is_zoomed(cx) {
|
||||||
|
@ -354,6 +360,8 @@ impl Dock {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}),
|
||||||
|
cx.subscribe(&panel, move |this, panel, event, cx| match event {
|
||||||
PanelEvent::ZoomIn => {
|
PanelEvent::ZoomIn => {
|
||||||
this.set_panel_zoomed(&panel.to_any(), true, cx);
|
this.set_panel_zoomed(&panel.to_any(), true, cx);
|
||||||
if !panel.focus_handle(cx).contains_focused(cx) {
|
if !panel.focus_handle(cx).contains_focused(cx) {
|
||||||
|
@ -735,9 +743,8 @@ pub mod test {
|
||||||
true
|
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;
|
self.position = position;
|
||||||
cx.emit(PanelEvent::ChangePosition);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size(&self, _: &WindowContext) -> Pixels {
|
fn size(&self, _: &WindowContext) -> Pixels {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue