parent
64a5153bb5
commit
0c8ee21e22
1 changed files with 25 additions and 27 deletions
|
@ -1305,6 +1305,18 @@ impl Workspace {
|
||||||
&self.right_dock
|
&self.right_dock
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn all_docks(&self) -> [&Entity<Dock>; 3] {
|
||||||
|
[&self.left_dock, &self.bottom_dock, &self.right_dock]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn dock_at_position(&self, position: DockPosition) -> &Entity<Dock> {
|
||||||
|
match position {
|
||||||
|
DockPosition::Left => &self.left_dock,
|
||||||
|
DockPosition::Bottom => &self.bottom_dock,
|
||||||
|
DockPosition::Right => &self.right_dock,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_edited(&self) -> bool {
|
pub fn is_edited(&self) -> bool {
|
||||||
self.window_edited
|
self.window_edited
|
||||||
}
|
}
|
||||||
|
@ -1319,11 +1331,8 @@ impl Workspace {
|
||||||
cx.on_focus_in(&focus_handle, window, Self::handle_panel_focused)
|
cx.on_focus_in(&focus_handle, window, Self::handle_panel_focused)
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
let dock = match panel.position(window, cx) {
|
let dock_position = panel.position(window, cx);
|
||||||
DockPosition::Left => &self.left_dock,
|
let dock = self.dock_at_position(dock_position);
|
||||||
DockPosition::Bottom => &self.bottom_dock,
|
|
||||||
DockPosition::Right => &self.right_dock,
|
|
||||||
};
|
|
||||||
|
|
||||||
dock.update(cx, |dock, cx| {
|
dock.update(cx, |dock, cx| {
|
||||||
dock.add_panel(panel, self.weak_self.clone(), window, cx)
|
dock.add_panel(panel, self.weak_self.clone(), window, cx)
|
||||||
|
@ -1797,7 +1806,7 @@ impl Workspace {
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
let docks = [&self.left_dock, &self.bottom_dock, &self.right_dock];
|
let docks = self.all_docks();
|
||||||
let active_dock = docks
|
let active_dock = docks
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|dock| dock.focus_handle(cx).contains_focused(window, cx));
|
.find(|dock| dock.focus_handle(cx).contains_focused(window, cx));
|
||||||
|
@ -2397,12 +2406,7 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_dock_at_position_open(&self, position: DockPosition, cx: &mut Context<Self>) -> bool {
|
pub fn is_dock_at_position_open(&self, position: DockPosition, cx: &mut Context<Self>) -> bool {
|
||||||
let dock = match position {
|
self.dock_at_position(position).read(cx).is_open()
|
||||||
DockPosition::Left => &self.left_dock,
|
|
||||||
DockPosition::Bottom => &self.bottom_dock,
|
|
||||||
DockPosition::Right => &self.right_dock,
|
|
||||||
};
|
|
||||||
dock.read(cx).is_open()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_dock(
|
pub fn toggle_dock(
|
||||||
|
@ -2411,11 +2415,7 @@ impl Workspace {
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
let dock = match dock_side {
|
let dock = self.dock_at_position(dock_side);
|
||||||
DockPosition::Left => &self.left_dock,
|
|
||||||
DockPosition::Bottom => &self.bottom_dock,
|
|
||||||
DockPosition::Right => &self.right_dock,
|
|
||||||
};
|
|
||||||
let mut focus_center = false;
|
let mut focus_center = false;
|
||||||
let mut reveal_dock = false;
|
let mut reveal_dock = false;
|
||||||
dock.update(cx, |dock, cx| {
|
dock.update(cx, |dock, cx| {
|
||||||
|
@ -2457,9 +2457,7 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn close_all_docks(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
pub fn close_all_docks(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let docks = [&self.left_dock, &self.bottom_dock, &self.right_dock];
|
for dock in self.all_docks() {
|
||||||
|
|
||||||
for dock in docks {
|
|
||||||
dock.update(cx, |dock, cx| {
|
dock.update(cx, |dock, cx| {
|
||||||
dock.set_open(false, window, cx);
|
dock.set_open(false, window, cx);
|
||||||
});
|
});
|
||||||
|
@ -2495,7 +2493,7 @@ impl Workspace {
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> Option<Arc<dyn PanelHandle>> {
|
) -> Option<Arc<dyn PanelHandle>> {
|
||||||
let mut panel = None;
|
let mut panel = None;
|
||||||
for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] {
|
for dock in self.all_docks() {
|
||||||
if let Some(panel_index) = dock.read(cx).panel_index_for_proto_id(panel_id) {
|
if let Some(panel_index) = dock.read(cx).panel_index_for_proto_id(panel_id) {
|
||||||
panel = dock.update(cx, |dock, cx| {
|
panel = dock.update(cx, |dock, cx| {
|
||||||
dock.activate_panel(panel_index, window, cx);
|
dock.activate_panel(panel_index, window, cx);
|
||||||
|
@ -2523,7 +2521,7 @@ impl Workspace {
|
||||||
) -> Option<Arc<dyn PanelHandle>> {
|
) -> Option<Arc<dyn PanelHandle>> {
|
||||||
let mut result_panel = None;
|
let mut result_panel = None;
|
||||||
let mut serialize = false;
|
let mut serialize = false;
|
||||||
for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] {
|
for dock in self.all_docks() {
|
||||||
if let Some(panel_index) = dock.read(cx).panel_index_for_type::<T>() {
|
if let Some(panel_index) = dock.read(cx).panel_index_for_type::<T>() {
|
||||||
let mut focus_center = false;
|
let mut focus_center = false;
|
||||||
let panel = dock.update(cx, |dock, cx| {
|
let panel = dock.update(cx, |dock, cx| {
|
||||||
|
@ -2562,7 +2560,7 @@ impl Workspace {
|
||||||
|
|
||||||
/// Open the panel of the given type
|
/// Open the panel of the given type
|
||||||
pub fn open_panel<T: Panel>(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
pub fn open_panel<T: Panel>(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] {
|
for dock in self.all_docks() {
|
||||||
if let Some(panel_index) = dock.read(cx).panel_index_for_type::<T>() {
|
if let Some(panel_index) = dock.read(cx).panel_index_for_type::<T>() {
|
||||||
dock.update(cx, |dock, cx| {
|
dock.update(cx, |dock, cx| {
|
||||||
dock.activate_panel(panel_index, window, cx);
|
dock.activate_panel(panel_index, window, cx);
|
||||||
|
@ -2573,7 +2571,7 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn panel<T: Panel>(&self, cx: &App) -> Option<Entity<T>> {
|
pub fn panel<T: Panel>(&self, cx: &App) -> Option<Entity<T>> {
|
||||||
[&self.left_dock, &self.bottom_dock, &self.right_dock]
|
self.all_docks()
|
||||||
.iter()
|
.iter()
|
||||||
.find_map(|dock| dock.read(cx).panel::<T>())
|
.find_map(|dock| dock.read(cx).panel::<T>())
|
||||||
}
|
}
|
||||||
|
@ -2593,7 +2591,7 @@ impl Workspace {
|
||||||
|
|
||||||
// If another dock is zoomed, hide it.
|
// If another dock is zoomed, hide it.
|
||||||
let mut focus_center = false;
|
let mut focus_center = false;
|
||||||
for dock in [&self.left_dock, &self.right_dock, &self.bottom_dock] {
|
for dock in self.all_docks() {
|
||||||
dock.update(cx, |dock, cx| {
|
dock.update(cx, |dock, cx| {
|
||||||
if Some(dock.position()) != dock_to_reveal {
|
if Some(dock.position()) != dock_to_reveal {
|
||||||
if let Some(panel) = dock.active_panel() {
|
if let Some(panel) = dock.active_panel() {
|
||||||
|
@ -3546,7 +3544,7 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn focused_pane(&self, window: &Window, cx: &App) -> Entity<Pane> {
|
pub fn focused_pane(&self, window: &Window, cx: &App) -> Entity<Pane> {
|
||||||
for dock in [&self.left_dock, &self.right_dock, &self.bottom_dock] {
|
for dock in self.all_docks() {
|
||||||
if dock.focus_handle(cx).contains_focused(window, cx) {
|
if dock.focus_handle(cx).contains_focused(window, cx) {
|
||||||
if let Some(pane) = dock
|
if let Some(pane) = dock
|
||||||
.read(cx)
|
.read(cx)
|
||||||
|
@ -4139,7 +4137,7 @@ impl Workspace {
|
||||||
) -> (Option<Box<dyn ItemHandle>>, Option<proto::PanelId>) {
|
) -> (Option<Box<dyn ItemHandle>>, Option<proto::PanelId>) {
|
||||||
let mut active_item = None;
|
let mut active_item = None;
|
||||||
let mut panel_id = None;
|
let mut panel_id = None;
|
||||||
for dock in [&self.left_dock, &self.right_dock, &self.bottom_dock] {
|
for dock in self.all_docks() {
|
||||||
if dock.focus_handle(cx).contains_focused(window, cx) {
|
if dock.focus_handle(cx).contains_focused(window, cx) {
|
||||||
if let Some(panel) = dock.read(cx).active_panel() {
|
if let Some(panel) = dock.read(cx).active_panel() {
|
||||||
if let Some(pane) = panel.pane(cx) {
|
if let Some(pane) = panel.pane(cx) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue