WIP fixing dock problems
This commit is contained in:
@@ -175,16 +175,21 @@ impl Dock {
|
||||
new_position: DockPosition,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) {
|
||||
dbg!("starting", &new_position);
|
||||
workspace.dock.position = new_position;
|
||||
// Tell the pane about the new anchor position
|
||||
workspace.dock.pane.update(cx, |pane, cx| {
|
||||
dbg!("setting docked");
|
||||
pane.set_docked(Some(new_position.anchor()), cx)
|
||||
});
|
||||
|
||||
if workspace.dock.position.is_visible() {
|
||||
dbg!("dock is visible");
|
||||
// Close the right sidebar if the dock is on the right side and the right sidebar is open
|
||||
if workspace.dock.position.anchor() == DockAnchor::Right {
|
||||
dbg!("dock anchor is right");
|
||||
if workspace.right_sidebar().read(cx).is_open() {
|
||||
dbg!("Toggling right sidebar");
|
||||
workspace.toggle_sidebar(SidebarSide::Right, cx);
|
||||
}
|
||||
}
|
||||
@@ -194,8 +199,10 @@ impl Dock {
|
||||
if pane.read(cx).items().next().is_none() {
|
||||
let item_to_add = (workspace.dock.default_item_factory)(workspace, cx);
|
||||
// Adding the item focuses the pane by default
|
||||
dbg!("Adding item to dock");
|
||||
Pane::add_item(workspace, &pane, item_to_add, true, true, None, cx);
|
||||
} else {
|
||||
dbg!("just focusing dock");
|
||||
cx.focus(pane);
|
||||
}
|
||||
} else if let Some(last_active_center_pane) = workspace
|
||||
@@ -207,6 +214,7 @@ impl Dock {
|
||||
}
|
||||
cx.emit(crate::Event::DockAnchorChanged);
|
||||
workspace.serialize_workspace(cx);
|
||||
dbg!("Serializing workspace after dock position changed");
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ define_connection! {
|
||||
dock_visible INTEGER, // Boolean
|
||||
dock_anchor TEXT, // Enum: 'Bottom' / 'Right' / 'Expanded'
|
||||
dock_pane INTEGER, // NULL indicates that we don't have a dock pane yet
|
||||
project_panel_open INTEGER, //Boolean
|
||||
left_sidebar_open INTEGER, //Boolean
|
||||
timestamp TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
FOREIGN KEY(dock_pane) REFERENCES panes(pane_id)
|
||||
) STRICT;
|
||||
@@ -91,7 +91,7 @@ impl WorkspaceDb {
|
||||
|
||||
// Note that we re-assign the workspace_id here in case it's empty
|
||||
// and we've grabbed the most recent workspace
|
||||
let (workspace_id, workspace_location, project_panel_open, dock_position): (
|
||||
let (workspace_id, workspace_location, left_sidebar_open, dock_position): (
|
||||
WorkspaceId,
|
||||
WorkspaceLocation,
|
||||
bool,
|
||||
@@ -99,12 +99,12 @@ impl WorkspaceDb {
|
||||
) = iife!({
|
||||
if worktree_roots.len() == 0 {
|
||||
self.select_row(sql!(
|
||||
SELECT workspace_id, workspace_location, project_panel_open, dock_visible, dock_anchor
|
||||
SELECT workspace_id, workspace_location, left_sidebar_open, dock_visible, dock_anchor
|
||||
FROM workspaces
|
||||
ORDER BY timestamp DESC LIMIT 1))?()?
|
||||
} else {
|
||||
self.select_row_bound(sql!(
|
||||
SELECT workspace_id, workspace_location, project_panel_open, dock_visible, dock_anchor
|
||||
SELECT workspace_id, workspace_location, left_sidebar_open, dock_visible, dock_anchor
|
||||
FROM workspaces
|
||||
WHERE workspace_location = ?))?(&workspace_location)?
|
||||
}
|
||||
@@ -125,7 +125,7 @@ impl WorkspaceDb {
|
||||
.context("Getting center group")
|
||||
.log_err()?,
|
||||
dock_position,
|
||||
project_panel_open
|
||||
left_sidebar_open
|
||||
})
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ impl WorkspaceDb {
|
||||
INSERT INTO workspaces(
|
||||
workspace_id,
|
||||
workspace_location,
|
||||
project_panel_open,
|
||||
left_sidebar_open,
|
||||
dock_visible,
|
||||
dock_anchor,
|
||||
timestamp
|
||||
@@ -160,11 +160,11 @@ impl WorkspaceDb {
|
||||
ON CONFLICT DO
|
||||
UPDATE SET
|
||||
workspace_location = ?2,
|
||||
project_panel_open = ?3,
|
||||
left_sidebar_open = ?3,
|
||||
dock_visible = ?4,
|
||||
dock_anchor = ?5,
|
||||
timestamp = CURRENT_TIMESTAMP
|
||||
))?((workspace.id, &workspace.location, workspace.project_panel_open, workspace.dock_position))
|
||||
))?((workspace.id, &workspace.location, workspace.left_sidebar_open, workspace.dock_position))
|
||||
.context("Updating workspace")?;
|
||||
|
||||
// Save center pane group and dock pane
|
||||
@@ -198,7 +198,8 @@ impl WorkspaceDb {
|
||||
query! {
|
||||
pub fn recent_workspaces(limit: usize) -> Result<Vec<(WorkspaceId, WorkspaceLocation)>> {
|
||||
SELECT workspace_id, workspace_location
|
||||
FROM workspaces
|
||||
FROM workspaces
|
||||
WHERE workspace_location IS NOT NULL
|
||||
ORDER BY timestamp DESC
|
||||
LIMIT ?
|
||||
}
|
||||
@@ -458,7 +459,7 @@ mod tests {
|
||||
dock_position: crate::dock::DockPosition::Shown(DockAnchor::Bottom),
|
||||
center_group: Default::default(),
|
||||
dock_pane: Default::default(),
|
||||
project_panel_open: true
|
||||
left_sidebar_open: true
|
||||
};
|
||||
|
||||
let mut workspace_2 = SerializedWorkspace {
|
||||
@@ -467,7 +468,7 @@ mod tests {
|
||||
dock_position: crate::dock::DockPosition::Hidden(DockAnchor::Expanded),
|
||||
center_group: Default::default(),
|
||||
dock_pane: Default::default(),
|
||||
project_panel_open: false
|
||||
left_sidebar_open: false
|
||||
};
|
||||
|
||||
db.save_workspace(workspace_1.clone()).await;
|
||||
@@ -573,7 +574,7 @@ mod tests {
|
||||
dock_position: DockPosition::Shown(DockAnchor::Bottom),
|
||||
center_group,
|
||||
dock_pane,
|
||||
project_panel_open: true
|
||||
left_sidebar_open: true
|
||||
};
|
||||
|
||||
db.save_workspace(workspace.clone()).await;
|
||||
@@ -601,7 +602,7 @@ mod tests {
|
||||
dock_position: crate::dock::DockPosition::Shown(DockAnchor::Bottom),
|
||||
center_group: Default::default(),
|
||||
dock_pane: Default::default(),
|
||||
project_panel_open: true,
|
||||
left_sidebar_open: true,
|
||||
};
|
||||
|
||||
let mut workspace_2 = SerializedWorkspace {
|
||||
@@ -610,7 +611,7 @@ mod tests {
|
||||
dock_position: crate::dock::DockPosition::Hidden(DockAnchor::Expanded),
|
||||
center_group: Default::default(),
|
||||
dock_pane: Default::default(),
|
||||
project_panel_open: false,
|
||||
left_sidebar_open: false,
|
||||
};
|
||||
|
||||
db.save_workspace(workspace_1.clone()).await;
|
||||
@@ -646,7 +647,7 @@ mod tests {
|
||||
dock_position: DockPosition::Shown(DockAnchor::Right),
|
||||
center_group: Default::default(),
|
||||
dock_pane: Default::default(),
|
||||
project_panel_open: false
|
||||
left_sidebar_open: false
|
||||
};
|
||||
|
||||
db.save_workspace(workspace_3.clone()).await;
|
||||
@@ -681,7 +682,7 @@ mod tests {
|
||||
dock_position: crate::dock::DockPosition::Hidden(DockAnchor::Right),
|
||||
center_group: center_group.clone(),
|
||||
dock_pane,
|
||||
project_panel_open: true
|
||||
left_sidebar_open: true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ pub struct SerializedWorkspace {
|
||||
pub dock_position: DockPosition,
|
||||
pub center_group: SerializedPaneGroup,
|
||||
pub dock_pane: SerializedPane,
|
||||
pub project_panel_open: bool,
|
||||
pub left_sidebar_open: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
@@ -95,26 +95,33 @@ impl SerializedPaneGroup {
|
||||
workspace_id: WorkspaceId,
|
||||
workspace: &ViewHandle<Workspace>,
|
||||
cx: &mut AsyncAppContext,
|
||||
) -> (Member, Option<ViewHandle<Pane>>) {
|
||||
) -> Option<(Member, Option<ViewHandle<Pane>>)> {
|
||||
match self {
|
||||
SerializedPaneGroup::Group { axis, children } => {
|
||||
let mut current_active_pane = None;
|
||||
let mut members = Vec::new();
|
||||
for child in children {
|
||||
let (new_member, active_pane) = child
|
||||
if let Some((new_member, active_pane)) = child
|
||||
.deserialize(project, workspace_id, workspace, cx)
|
||||
.await;
|
||||
members.push(new_member);
|
||||
.await
|
||||
{
|
||||
members.push(new_member);
|
||||
|
||||
current_active_pane = current_active_pane.or(active_pane);
|
||||
current_active_pane = current_active_pane.or(active_pane);
|
||||
}
|
||||
}
|
||||
(
|
||||
|
||||
if members.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some((
|
||||
Member::Axis(PaneAxis {
|
||||
axis: *axis,
|
||||
members,
|
||||
}),
|
||||
current_active_pane,
|
||||
)
|
||||
))
|
||||
}
|
||||
SerializedPaneGroup::Pane(serialized_pane) => {
|
||||
let pane = workspace.update(cx, |workspace, cx| workspace.add_pane(cx));
|
||||
@@ -123,7 +130,11 @@ impl SerializedPaneGroup {
|
||||
.deserialize_to(project, &pane, workspace_id, workspace, cx)
|
||||
.await;
|
||||
|
||||
(Member::Pane(pane.clone()), active.then(|| pane))
|
||||
if pane.read_with(cx, |pane, _| pane.items().next().is_some()) {
|
||||
Some((Member::Pane(pane.clone()), active.then(|| pane)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1244,6 +1244,8 @@ impl Workspace {
|
||||
Dock::hide_on_sidebar_shown(self, sidebar_side, cx);
|
||||
}
|
||||
|
||||
self.serialize_workspace(cx);
|
||||
|
||||
cx.focus_self();
|
||||
cx.notify();
|
||||
}
|
||||
@@ -1275,6 +1277,9 @@ impl Workspace {
|
||||
} else {
|
||||
cx.focus_self();
|
||||
}
|
||||
|
||||
self.serialize_workspace(cx);
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
@@ -1302,6 +1307,9 @@ impl Workspace {
|
||||
cx.focus(active_item.to_any());
|
||||
}
|
||||
}
|
||||
|
||||
self.serialize_workspace(cx);
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
@@ -2268,13 +2276,20 @@ impl Workspace {
|
||||
self.database_id
|
||||
}
|
||||
|
||||
fn location(&self, cx: &AppContext) -> WorkspaceLocation {
|
||||
self.project()
|
||||
.read(cx)
|
||||
.visible_worktrees(cx)
|
||||
.map(|worktree| worktree.read(cx).abs_path())
|
||||
.collect::<Vec<_>>()
|
||||
.into()
|
||||
fn location(&self, cx: &AppContext) -> Option<WorkspaceLocation> {
|
||||
let project = self.project().read(cx);
|
||||
|
||||
if project.is_local() {
|
||||
Some(
|
||||
project
|
||||
.visible_worktrees(cx)
|
||||
.map(|worktree| worktree.read(cx).abs_path())
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_panes(&mut self, member: Member, cx: &mut ViewContext<Workspace>) {
|
||||
@@ -2331,24 +2346,24 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
let location = self.location(cx);
|
||||
if let Some(location) = self.location(cx) {
|
||||
if !location.paths().is_empty() {
|
||||
let dock_pane = serialize_pane_handle(self.dock.pane(), cx);
|
||||
let center_group = build_serialized_pane_group(&self.center.root, cx);
|
||||
|
||||
if !location.paths().is_empty() {
|
||||
let dock_pane = serialize_pane_handle(self.dock.pane(), cx);
|
||||
let center_group = build_serialized_pane_group(&self.center.root, cx);
|
||||
let serialized_workspace = SerializedWorkspace {
|
||||
id: self.database_id,
|
||||
location,
|
||||
dock_position: self.dock.position(),
|
||||
dock_pane,
|
||||
center_group,
|
||||
left_sidebar_open: self.left_sidebar.read(cx).is_open(),
|
||||
};
|
||||
|
||||
let serialized_workspace = SerializedWorkspace {
|
||||
id: self.database_id,
|
||||
location: self.location(cx),
|
||||
dock_position: self.dock.position(),
|
||||
dock_pane,
|
||||
center_group,
|
||||
project_panel_open: self.left_sidebar.read(cx).is_open(),
|
||||
};
|
||||
|
||||
cx.background()
|
||||
.spawn(persistence::DB.save_workspace(serialized_workspace))
|
||||
.detach();
|
||||
cx.background()
|
||||
.spawn(persistence::DB.save_workspace(serialized_workspace))
|
||||
.detach();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2375,34 +2390,46 @@ impl Workspace {
|
||||
.await;
|
||||
|
||||
// Traverse the splits tree and add to things
|
||||
let (root, active_pane) = serialized_workspace
|
||||
let center_group = serialized_workspace
|
||||
.center_group
|
||||
.deserialize(&project, serialized_workspace.id, &workspace, &mut cx)
|
||||
.await;
|
||||
|
||||
// Remove old panes from workspace panes list
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
workspace.remove_panes(workspace.center.root.clone(), cx);
|
||||
if let Some((center_group, active_pane)) = center_group {
|
||||
workspace.remove_panes(workspace.center.root.clone(), cx);
|
||||
|
||||
// Swap workspace center group
|
||||
workspace.center = PaneGroup::with_root(root);
|
||||
// Swap workspace center group
|
||||
workspace.center = PaneGroup::with_root(center_group);
|
||||
|
||||
// Change the focus to the workspace first so that we retrigger focus in on the pane.
|
||||
cx.focus_self();
|
||||
|
||||
if let Some(active_pane) = active_pane {
|
||||
cx.focus(active_pane);
|
||||
} else {
|
||||
cx.focus(workspace.panes.last().unwrap().clone());
|
||||
}
|
||||
} else {
|
||||
cx.focus_self();
|
||||
}
|
||||
|
||||
// Note, if this is moved after 'set_dock_position'
|
||||
// it causes an infinite loop.
|
||||
if serialized_workspace.project_panel_open {
|
||||
workspace.toggle_sidebar_item_focus(SidebarSide::Left, 0, cx)
|
||||
if workspace.left_sidebar().read(cx).is_open()
|
||||
!= serialized_workspace.left_sidebar_open
|
||||
{
|
||||
workspace.toggle_sidebar(SidebarSide::Left, cx);
|
||||
}
|
||||
|
||||
Dock::set_dock_position(workspace, serialized_workspace.dock_position, cx);
|
||||
|
||||
if let Some(active_pane) = active_pane {
|
||||
// Change the focus to the workspace first so that we retrigger focus in on the pane.
|
||||
cx.focus_self();
|
||||
cx.focus(active_pane);
|
||||
}
|
||||
// Dock::set_dock_position(workspace, serialized_workspace.dock_position, cx);
|
||||
|
||||
cx.notify();
|
||||
});
|
||||
|
||||
// Serialize ourself to make sure our timestamps and any pane / item changes are replicated
|
||||
workspace.read_with(&cx, |workspace, cx| workspace.serialize_workspace(cx))
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
Reference in New Issue
Block a user