Enable manual worktree organization (#11504)

Release Notes:

- Preserve order of worktrees in project
([#10883](https://github.com/zed-industries/zed/issues/10883)).
- Enable drag-and-drop reordering for project worktrees

Note: worktree order is not synced during collaboration but guests can
reorder their own project panels.

![Reordering
worktrees](https://github.com/zed-industries/zed/assets/1347854/1c63d83c-5d4e-4b55-b840-bfbf32521b2a)

---------

Co-authored-by: Kirill Bulatov <kirill@zed.dev>
This commit is contained in:
Elliot Thomas 2024-05-24 10:15:48 +01:00 committed by GitHub
parent 1e5389a2be
commit b9697fb487
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 479 additions and 54 deletions

View file

@ -33,6 +33,8 @@ impl LocalPaths {
.into_iter()
.map(|p| p.as_ref().to_path_buf())
.collect();
// Ensure all future `zed workspace1 workspace2` and `zed workspace2 workspace1` calls are using the same workspace.
// The actual workspace order is stored in the `LocalPathsOrder` struct.
paths.sort();
Self(Arc::new(paths))
}
@ -44,7 +46,8 @@ impl LocalPaths {
impl From<LocalPaths> for SerializedWorkspaceLocation {
fn from(local_paths: LocalPaths) -> Self {
Self::Local(local_paths)
let order = LocalPathsOrder::default_for_paths(&local_paths);
Self::Local(local_paths, order)
}
}
@ -68,6 +71,43 @@ impl Column for LocalPaths {
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct LocalPathsOrder(Vec<usize>);
impl LocalPathsOrder {
pub fn new(order: impl IntoIterator<Item = usize>) -> Self {
Self(order.into_iter().collect())
}
pub fn order(&self) -> &[usize] {
self.0.as_slice()
}
pub fn default_for_paths(paths: &LocalPaths) -> Self {
Self::new(0..paths.0.len())
}
}
impl StaticColumnCount for LocalPathsOrder {}
impl Bind for &LocalPathsOrder {
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
statement.bind(&bincode::serialize(&self.0)?, start_index)
}
}
impl Column for LocalPathsOrder {
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
let order_blob = statement.column_blob(start_index)?;
let order = if order_blob.is_empty() {
Vec::new()
} else {
bincode::deserialize(order_blob).context("deserializing workspace root order")?
};
Ok((Self(order), start_index + 1))
}
}
impl From<SerializedDevServerProject> for SerializedWorkspaceLocation {
fn from(dev_server_project: SerializedDevServerProject) -> Self {
Self::DevServer(dev_server_project)
@ -101,7 +141,7 @@ impl Column for SerializedDevServerProject {
#[derive(Debug, PartialEq, Clone)]
pub enum SerializedWorkspaceLocation {
Local(LocalPaths),
Local(LocalPaths, LocalPathsOrder),
DevServer(SerializedDevServerProject),
}