Split and move to pane working
This commit is contained in:
parent
9abfa037fd
commit
738893c527
11 changed files with 206 additions and 123 deletions
|
@ -908,7 +908,7 @@ async fn test_host_disconnect(
|
||||||
cx_b.add_window(|cx| Workspace::new(project_b.clone(), |_, _| unimplemented!(), cx));
|
cx_b.add_window(|cx| Workspace::new(project_b.clone(), |_, _| unimplemented!(), cx));
|
||||||
let editor_b = workspace_b
|
let editor_b = workspace_b
|
||||||
.update(cx_b, |workspace, cx| {
|
.update(cx_b, |workspace, cx| {
|
||||||
workspace.open_path((worktree_id, "b.txt"), true, cx)
|
workspace.open_path((worktree_id, "b.txt"), None, true, cx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -3704,7 +3704,7 @@ async fn test_collaborating_with_code_actions(
|
||||||
cx_b.add_window(|cx| Workspace::new(project_b.clone(), |_, _| unimplemented!(), cx));
|
cx_b.add_window(|cx| Workspace::new(project_b.clone(), |_, _| unimplemented!(), cx));
|
||||||
let editor_b = workspace_b
|
let editor_b = workspace_b
|
||||||
.update(cx_b, |workspace, cx| {
|
.update(cx_b, |workspace, cx| {
|
||||||
workspace.open_path((worktree_id, "main.rs"), true, cx)
|
workspace.open_path((worktree_id, "main.rs"), None, true, cx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -3925,7 +3925,7 @@ async fn test_collaborating_with_renames(cx_a: &mut TestAppContext, cx_b: &mut T
|
||||||
cx_b.add_window(|cx| Workspace::new(project_b.clone(), |_, _| unimplemented!(), cx));
|
cx_b.add_window(|cx| Workspace::new(project_b.clone(), |_, _| unimplemented!(), cx));
|
||||||
let editor_b = workspace_b
|
let editor_b = workspace_b
|
||||||
.update(cx_b, |workspace, cx| {
|
.update(cx_b, |workspace, cx| {
|
||||||
workspace.open_path((worktree_id, "one.rs"), true, cx)
|
workspace.open_path((worktree_id, "one.rs"), None, true, cx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -5134,7 +5134,7 @@ async fn test_following(
|
||||||
let pane_a = workspace_a.read_with(cx_a, |workspace, _| workspace.active_pane().clone());
|
let pane_a = workspace_a.read_with(cx_a, |workspace, _| workspace.active_pane().clone());
|
||||||
let editor_a1 = workspace_a
|
let editor_a1 = workspace_a
|
||||||
.update(cx_a, |workspace, cx| {
|
.update(cx_a, |workspace, cx| {
|
||||||
workspace.open_path((worktree_id, "1.txt"), true, cx)
|
workspace.open_path((worktree_id, "1.txt"), None, true, cx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -5142,7 +5142,7 @@ async fn test_following(
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let editor_a2 = workspace_a
|
let editor_a2 = workspace_a
|
||||||
.update(cx_a, |workspace, cx| {
|
.update(cx_a, |workspace, cx| {
|
||||||
workspace.open_path((worktree_id, "2.txt"), true, cx)
|
workspace.open_path((worktree_id, "2.txt"), None, true, cx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -5153,7 +5153,7 @@ async fn test_following(
|
||||||
let workspace_b = client_b.build_workspace(&project_b, cx_b);
|
let workspace_b = client_b.build_workspace(&project_b, cx_b);
|
||||||
let editor_b1 = workspace_b
|
let editor_b1 = workspace_b
|
||||||
.update(cx_b, |workspace, cx| {
|
.update(cx_b, |workspace, cx| {
|
||||||
workspace.open_path((worktree_id, "1.txt"), true, cx)
|
workspace.open_path((worktree_id, "1.txt"), None, true, cx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -5411,7 +5411,7 @@ async fn test_peers_following_each_other(cx_a: &mut TestAppContext, cx_b: &mut T
|
||||||
let pane_a1 = workspace_a.read_with(cx_a, |workspace, _| workspace.active_pane().clone());
|
let pane_a1 = workspace_a.read_with(cx_a, |workspace, _| workspace.active_pane().clone());
|
||||||
let _editor_a1 = workspace_a
|
let _editor_a1 = workspace_a
|
||||||
.update(cx_a, |workspace, cx| {
|
.update(cx_a, |workspace, cx| {
|
||||||
workspace.open_path((worktree_id, "1.txt"), true, cx)
|
workspace.open_path((worktree_id, "1.txt"), None, true, cx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -5423,7 +5423,7 @@ async fn test_peers_following_each_other(cx_a: &mut TestAppContext, cx_b: &mut T
|
||||||
let pane_b1 = workspace_b.read_with(cx_b, |workspace, _| workspace.active_pane().clone());
|
let pane_b1 = workspace_b.read_with(cx_b, |workspace, _| workspace.active_pane().clone());
|
||||||
let _editor_b1 = workspace_b
|
let _editor_b1 = workspace_b
|
||||||
.update(cx_b, |workspace, cx| {
|
.update(cx_b, |workspace, cx| {
|
||||||
workspace.open_path((worktree_id, "2.txt"), true, cx)
|
workspace.open_path((worktree_id, "2.txt"), None, true, cx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -5474,7 +5474,7 @@ async fn test_peers_following_each_other(cx_a: &mut TestAppContext, cx_b: &mut T
|
||||||
|
|
||||||
workspace_a
|
workspace_a
|
||||||
.update(cx_a, |workspace, cx| {
|
.update(cx_a, |workspace, cx| {
|
||||||
workspace.open_path((worktree_id, "3.txt"), true, cx)
|
workspace.open_path((worktree_id, "3.txt"), None, true, cx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -5485,7 +5485,7 @@ async fn test_peers_following_each_other(cx_a: &mut TestAppContext, cx_b: &mut T
|
||||||
workspace_b
|
workspace_b
|
||||||
.update(cx_b, |workspace, cx| {
|
.update(cx_b, |workspace, cx| {
|
||||||
assert_eq!(*workspace.active_pane(), pane_b1);
|
assert_eq!(*workspace.active_pane(), pane_b1);
|
||||||
workspace.open_path((worktree_id, "4.txt"), true, cx)
|
workspace.open_path((worktree_id, "4.txt"), None, true, cx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -5586,7 +5586,7 @@ async fn test_auto_unfollowing(cx_a: &mut TestAppContext, cx_b: &mut TestAppCont
|
||||||
let workspace_a = client_a.build_workspace(&project_a, cx_a);
|
let workspace_a = client_a.build_workspace(&project_a, cx_a);
|
||||||
let _editor_a1 = workspace_a
|
let _editor_a1 = workspace_a
|
||||||
.update(cx_a, |workspace, cx| {
|
.update(cx_a, |workspace, cx| {
|
||||||
workspace.open_path((worktree_id, "1.txt"), true, cx)
|
workspace.open_path((worktree_id, "1.txt"), None, true, cx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -5699,7 +5699,7 @@ async fn test_auto_unfollowing(cx_a: &mut TestAppContext, cx_b: &mut TestAppCont
|
||||||
// When client B activates a different item in the original pane, it automatically stops following client A.
|
// When client B activates a different item in the original pane, it automatically stops following client A.
|
||||||
workspace_b
|
workspace_b
|
||||||
.update(cx_b, |workspace, cx| {
|
.update(cx_b, |workspace, cx| {
|
||||||
workspace.open_path((worktree_id, "2.txt"), true, cx)
|
workspace.open_path((worktree_id, "2.txt"), None, true, cx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
pub mod shared_payloads;
|
|
||||||
|
|
||||||
use std::{any::Any, rc::Rc};
|
use std::{any::Any, rc::Rc};
|
||||||
|
|
||||||
use collections::HashSet;
|
use collections::HashSet;
|
||||||
|
@ -149,7 +147,6 @@ impl<V: View> DragAndDrop<V> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbg!("Rendered dragging state");
|
|
||||||
let position = position + region_offset;
|
let position = position + region_offset;
|
||||||
Some(
|
Some(
|
||||||
Overlay::new(
|
Overlay::new(
|
||||||
|
@ -160,7 +157,6 @@ impl<V: View> DragAndDrop<V> {
|
||||||
.on_up(MouseButton::Left, |_, cx| {
|
.on_up(MouseButton::Left, |_, cx| {
|
||||||
cx.defer(|cx| {
|
cx.defer(|cx| {
|
||||||
cx.update_global::<Self, _, _>(|this, cx| {
|
cx.update_global::<Self, _, _>(|this, cx| {
|
||||||
dbg!("Up with dragging state");
|
|
||||||
this.finish_dragging(cx)
|
this.finish_dragging(cx)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -169,7 +165,6 @@ impl<V: View> DragAndDrop<V> {
|
||||||
.on_up_out(MouseButton::Left, |_, cx| {
|
.on_up_out(MouseButton::Left, |_, cx| {
|
||||||
cx.defer(|cx| {
|
cx.defer(|cx| {
|
||||||
cx.update_global::<Self, _, _>(|this, cx| {
|
cx.update_global::<Self, _, _>(|this, cx| {
|
||||||
dbg!("Up out with dragging state");
|
|
||||||
this.finish_dragging(cx)
|
this.finish_dragging(cx)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -186,35 +181,30 @@ impl<V: View> DragAndDrop<V> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
State::Canceled => {
|
State::Canceled => Some(
|
||||||
dbg!("Rendered canceled state");
|
MouseEventHandler::<DraggedElementHandler>::new(0, cx, |_, _| {
|
||||||
Some(
|
Empty::new()
|
||||||
MouseEventHandler::<DraggedElementHandler>::new(0, cx, |_, _| {
|
.constrained()
|
||||||
Empty::new()
|
.with_width(0.)
|
||||||
.constrained()
|
.with_height(0.)
|
||||||
.with_width(0.)
|
.boxed()
|
||||||
.with_height(0.)
|
})
|
||||||
.boxed()
|
.on_up(MouseButton::Left, |_, cx| {
|
||||||
})
|
cx.defer(|cx| {
|
||||||
.on_up(MouseButton::Left, |_, cx| {
|
cx.update_global::<Self, _, _>(|this, _| {
|
||||||
cx.defer(|cx| {
|
this.currently_dragged = None;
|
||||||
cx.update_global::<Self, _, _>(|this, _| {
|
|
||||||
dbg!("Up with canceled state");
|
|
||||||
this.currently_dragged = None;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
.on_up_out(MouseButton::Left, |_, cx| {
|
})
|
||||||
cx.defer(|cx| {
|
.on_up_out(MouseButton::Left, |_, cx| {
|
||||||
cx.update_global::<Self, _, _>(|this, _| {
|
cx.defer(|cx| {
|
||||||
dbg!("Up out with canceled state");
|
cx.update_global::<Self, _, _>(|this, _| {
|
||||||
this.currently_dragged = None;
|
this.currently_dragged = None;
|
||||||
});
|
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
.boxed(),
|
})
|
||||||
)
|
.boxed(),
|
||||||
}
|
),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -227,7 +217,6 @@ impl<V: View> DragAndDrop<V> {
|
||||||
if payload.is::<P>() {
|
if payload.is::<P>() {
|
||||||
let window_id = *window_id;
|
let window_id = *window_id;
|
||||||
self.currently_dragged = Some(State::Canceled);
|
self.currently_dragged = Some(State::Canceled);
|
||||||
dbg!("Canceled");
|
|
||||||
self.notify_containers_for_window(window_id, cx);
|
self.notify_containers_for_window(window_id, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
use std::{path::Path, sync::Arc};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct DraggedProjectEntry {
|
|
||||||
pub path: Arc<Path>,
|
|
||||||
}
|
|
|
@ -6394,7 +6394,7 @@ impl Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn jump(workspace: &mut Workspace, action: &Jump, cx: &mut ViewContext<Workspace>) {
|
fn jump(workspace: &mut Workspace, action: &Jump, cx: &mut ViewContext<Workspace>) {
|
||||||
let editor = workspace.open_path(action.path.clone(), true, cx);
|
let editor = workspace.open_path(action.path.clone(), None, true, cx);
|
||||||
let position = action.position;
|
let position = action.position;
|
||||||
let anchor = action.anchor;
|
let anchor = action.anchor;
|
||||||
cx.spawn_weak(|_, mut cx| async move {
|
cx.spawn_weak(|_, mut cx| async move {
|
||||||
|
|
|
@ -76,7 +76,9 @@ impl<'a> EditorLspTestContext<'a> {
|
||||||
|
|
||||||
let file = cx.read(|cx| workspace.file_project_paths(cx)[0].clone());
|
let file = cx.read(|cx| workspace.file_project_paths(cx)[0].clone());
|
||||||
let item = workspace
|
let item = workspace
|
||||||
.update(cx, |workspace, cx| workspace.open_path(file, true, cx))
|
.update(cx, |workspace, cx| {
|
||||||
|
workspace.open_path(file, None, true, cx)
|
||||||
|
})
|
||||||
.await
|
.await
|
||||||
.expect("Could not open test file");
|
.expect("Could not open test file");
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ impl FileFinder {
|
||||||
match event {
|
match event {
|
||||||
Event::Selected(project_path) => {
|
Event::Selected(project_path) => {
|
||||||
workspace
|
workspace
|
||||||
.open_path(project_path.clone(), true, cx)
|
.open_path(project_path.clone(), None, true, cx)
|
||||||
.detach_and_log_err(cx);
|
.detach_and_log_err(cx);
|
||||||
workspace.dismiss_modal(cx);
|
workspace.dismiss_modal(cx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use context_menu::{ContextMenu, ContextMenuItem};
|
use context_menu::{ContextMenu, ContextMenuItem};
|
||||||
use drag_and_drop::{shared_payloads::DraggedProjectEntry, DragAndDrop, Draggable};
|
use drag_and_drop::{DragAndDrop, Draggable};
|
||||||
use editor::{Cancel, Editor};
|
use editor::{Cancel, Editor};
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
|
@ -239,6 +239,7 @@ impl ProjectPanel {
|
||||||
worktree_id: worktree.read(cx).id(),
|
worktree_id: worktree.read(cx).id(),
|
||||||
path: entry.path.clone(),
|
path: entry.path.clone(),
|
||||||
},
|
},
|
||||||
|
None,
|
||||||
focus_opened_item,
|
focus_opened_item,
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
|
@ -607,7 +608,7 @@ impl ProjectPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
cx.update_global(|drag_and_drop: &mut DragAndDrop<Workspace>, cx| {
|
cx.update_global(|drag_and_drop: &mut DragAndDrop<Workspace>, cx| {
|
||||||
drag_and_drop.cancel_dragging::<DraggedProjectEntry>(cx);
|
drag_and_drop.cancel_dragging::<ProjectEntryId>(cx);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1127,26 +1128,21 @@ impl ProjectPanel {
|
||||||
position: e.position,
|
position: e.position,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.as_draggable(
|
.as_draggable(entry_id, {
|
||||||
DraggedProjectEntry {
|
let row_container_style = theme.dragged_entry.container;
|
||||||
path: details.path.clone(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
let row_container_style = theme.dragged_entry.container;
|
|
||||||
|
|
||||||
move |_, cx: &mut RenderContext<Workspace>| {
|
move |_, cx: &mut RenderContext<Workspace>| {
|
||||||
let theme = cx.global::<Settings>().theme.clone();
|
let theme = cx.global::<Settings>().theme.clone();
|
||||||
Self::render_entry_visual_element(
|
Self::render_entry_visual_element(
|
||||||
&details,
|
&details,
|
||||||
None,
|
None,
|
||||||
padding,
|
padding,
|
||||||
row_container_style,
|
row_container_style,
|
||||||
&theme.project_panel.dragged_entry,
|
&theme.project_panel.dragged_entry,
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
)
|
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,9 @@ impl<'a> VimTestContext<'a> {
|
||||||
|
|
||||||
let file = cx.read(|cx| workspace.file_project_paths(cx)[0].clone());
|
let file = cx.read(|cx| workspace.file_project_paths(cx)[0].clone());
|
||||||
let item = workspace
|
let item = workspace
|
||||||
.update(cx, |workspace, cx| workspace.open_path(file, true, cx))
|
.update(cx, |workspace, cx| {
|
||||||
|
workspace.open_path(file, None, true, cx)
|
||||||
|
})
|
||||||
.await
|
.await
|
||||||
.expect("Could not open test file");
|
.expect("Could not open test file");
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use drag_and_drop::{shared_payloads::DraggedProjectEntry, DragAndDrop};
|
use drag_and_drop::DragAndDrop;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
color::Color,
|
color::Color,
|
||||||
elements::{Canvas, MouseEventHandler, ParentElement, Stack},
|
elements::{Canvas, MouseEventHandler, ParentElement, Stack},
|
||||||
|
@ -7,9 +7,13 @@ use gpui::{
|
||||||
AppContext, Element, ElementBox, EventContext, MouseButton, MouseState, Quad, RenderContext,
|
AppContext, Element, ElementBox, EventContext, MouseButton, MouseState, Quad, RenderContext,
|
||||||
WeakViewHandle,
|
WeakViewHandle,
|
||||||
};
|
};
|
||||||
|
use project::ProjectEntryId;
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
|
|
||||||
use crate::{MoveItem, Pane, SplitDirection, SplitWithItem, Workspace};
|
use crate::{
|
||||||
|
MoveItem, OpenProjectEntryInPane, Pane, SplitDirection, SplitWithItem, SplitWithProjectEntry,
|
||||||
|
Workspace,
|
||||||
|
};
|
||||||
|
|
||||||
use super::DraggedItem;
|
use super::DraggedItem;
|
||||||
|
|
||||||
|
@ -34,7 +38,7 @@ where
|
||||||
.map(|(drag_position, _)| drag_position)
|
.map(|(drag_position, _)| drag_position)
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
cx.global::<DragAndDrop<Workspace>>()
|
cx.global::<DragAndDrop<Workspace>>()
|
||||||
.currently_dragged::<DraggedProjectEntry>(cx.window_id())
|
.currently_dragged::<ProjectEntryId>(cx.window_id())
|
||||||
.map(|(drag_position, _)| drag_position)
|
.map(|(drag_position, _)| drag_position)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -82,7 +86,7 @@ where
|
||||||
.currently_dragged::<DraggedItem>(cx.window_id())
|
.currently_dragged::<DraggedItem>(cx.window_id())
|
||||||
.is_some()
|
.is_some()
|
||||||
|| drag_and_drop
|
|| drag_and_drop
|
||||||
.currently_dragged::<DraggedProjectEntry>(cx.window_id())
|
.currently_dragged::<ProjectEntryId>(cx.window_id())
|
||||||
.is_some()
|
.is_some()
|
||||||
{
|
{
|
||||||
cx.notify();
|
cx.notify();
|
||||||
|
@ -100,30 +104,59 @@ pub fn handle_dropped_item(
|
||||||
split_margin: Option<f32>,
|
split_margin: Option<f32>,
|
||||||
cx: &mut EventContext,
|
cx: &mut EventContext,
|
||||||
) {
|
) {
|
||||||
if let Some((_, dragged_item)) = cx
|
enum Action {
|
||||||
.global::<DragAndDrop<Workspace>>()
|
Move(WeakViewHandle<Pane>, usize),
|
||||||
.currently_dragged::<DraggedItem>(cx.window_id)
|
Open(ProjectEntryId),
|
||||||
|
}
|
||||||
|
let drag_and_drop = cx.global::<DragAndDrop<Workspace>>();
|
||||||
|
let action = if let Some((_, dragged_item)) =
|
||||||
|
drag_and_drop.currently_dragged::<DraggedItem>(cx.window_id)
|
||||||
{
|
{
|
||||||
if let Some(split_direction) = split_margin
|
Action::Move(dragged_item.pane.clone(), dragged_item.item.id())
|
||||||
.and_then(|margin| drop_split_direction(event.position, event.region, margin))
|
} else if let Some((_, project_entry)) =
|
||||||
{
|
drag_and_drop.currently_dragged::<ProjectEntryId>(cx.window_id)
|
||||||
cx.dispatch_action(SplitWithItem {
|
{
|
||||||
from: dragged_item.pane.clone(),
|
Action::Open(*project_entry)
|
||||||
item_id_to_move: dragged_item.item.id(),
|
|
||||||
pane_to_split: pane.clone(),
|
|
||||||
split_direction,
|
|
||||||
});
|
|
||||||
} else if pane != &dragged_item.pane || allow_same_pane {
|
|
||||||
// If no split margin or not close enough to the edge, just move the item
|
|
||||||
cx.dispatch_action(MoveItem {
|
|
||||||
item_id: dragged_item.item.id(),
|
|
||||||
from: dragged_item.pane.clone(),
|
|
||||||
to: pane.clone(),
|
|
||||||
destination_index: index,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
cx.propagate_event();
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(split_direction) =
|
||||||
|
split_margin.and_then(|margin| drop_split_direction(event.position, event.region, margin))
|
||||||
|
{
|
||||||
|
let pane_to_split = pane.clone();
|
||||||
|
match action {
|
||||||
|
Action::Move(from, item_id_to_move) => cx.dispatch_action(SplitWithItem {
|
||||||
|
from,
|
||||||
|
item_id_to_move,
|
||||||
|
pane_to_split,
|
||||||
|
split_direction,
|
||||||
|
}),
|
||||||
|
Action::Open(project_entry) => cx.dispatch_action(SplitWithProjectEntry {
|
||||||
|
pane_to_split,
|
||||||
|
split_direction,
|
||||||
|
project_entry,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
match action {
|
||||||
|
Action::Move(from, item_id) => {
|
||||||
|
if pane != &from || allow_same_pane {
|
||||||
|
cx.dispatch_action(MoveItem {
|
||||||
|
item_id,
|
||||||
|
from,
|
||||||
|
to: pane.clone(),
|
||||||
|
destination_index: index,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
cx.propagate_event();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Action::Open(project_entry) => cx.dispatch_action(OpenProjectEntryInPane {
|
||||||
|
pane: pane.clone(),
|
||||||
|
project_entry,
|
||||||
|
}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,12 +128,25 @@ pub struct OpenSharedScreen {
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct SplitWithItem {
|
pub struct SplitWithItem {
|
||||||
from: WeakViewHandle<Pane>,
|
|
||||||
pane_to_split: WeakViewHandle<Pane>,
|
pane_to_split: WeakViewHandle<Pane>,
|
||||||
split_direction: SplitDirection,
|
split_direction: SplitDirection,
|
||||||
|
from: WeakViewHandle<Pane>,
|
||||||
item_id_to_move: usize,
|
item_id_to_move: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq)]
|
||||||
|
pub struct SplitWithProjectEntry {
|
||||||
|
pane_to_split: WeakViewHandle<Pane>,
|
||||||
|
split_direction: SplitDirection,
|
||||||
|
project_entry: ProjectEntryId,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq)]
|
||||||
|
pub struct OpenProjectEntryInPane {
|
||||||
|
pane: WeakViewHandle<Pane>,
|
||||||
|
project_entry: ProjectEntryId,
|
||||||
|
}
|
||||||
|
|
||||||
impl_internal_actions!(
|
impl_internal_actions!(
|
||||||
workspace,
|
workspace,
|
||||||
[
|
[
|
||||||
|
@ -143,6 +156,8 @@ impl_internal_actions!(
|
||||||
OpenSharedScreen,
|
OpenSharedScreen,
|
||||||
RemoveWorktreeFromProject,
|
RemoveWorktreeFromProject,
|
||||||
SplitWithItem,
|
SplitWithItem,
|
||||||
|
SplitWithProjectEntry,
|
||||||
|
OpenProjectEntryInPane,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
impl_actions!(workspace, [ActivatePane]);
|
impl_actions!(workspace, [ActivatePane]);
|
||||||
|
@ -234,6 +249,57 @@ pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
cx.add_async_action(
|
||||||
|
|workspace: &mut Workspace,
|
||||||
|
SplitWithProjectEntry {
|
||||||
|
pane_to_split,
|
||||||
|
split_direction,
|
||||||
|
project_entry,
|
||||||
|
}: &_,
|
||||||
|
cx| {
|
||||||
|
pane_to_split.upgrade(cx).and_then(|pane_to_split| {
|
||||||
|
let new_pane = workspace.add_pane(cx);
|
||||||
|
workspace
|
||||||
|
.center
|
||||||
|
.split(&pane_to_split, &new_pane, *split_direction)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
workspace
|
||||||
|
.project
|
||||||
|
.read(cx)
|
||||||
|
.path_for_entry(*project_entry, cx)
|
||||||
|
.map(|path| {
|
||||||
|
let task = workspace.open_path(path, Some(new_pane.downgrade()), true, cx);
|
||||||
|
cx.foreground().spawn(async move {
|
||||||
|
task.await?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
cx.add_async_action(
|
||||||
|
|workspace: &mut Workspace,
|
||||||
|
OpenProjectEntryInPane {
|
||||||
|
pane,
|
||||||
|
project_entry,
|
||||||
|
}: &_,
|
||||||
|
cx| {
|
||||||
|
workspace
|
||||||
|
.project
|
||||||
|
.read(cx)
|
||||||
|
.path_for_entry(*project_entry, cx)
|
||||||
|
.map(|path| {
|
||||||
|
let task = workspace.open_path(path, Some(pane.clone()), true, cx);
|
||||||
|
cx.foreground().spawn(async move {
|
||||||
|
task.await?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
let client = &app_state.client;
|
let client = &app_state.client;
|
||||||
client.add_view_request_handler(Workspace::handle_follow);
|
client.add_view_request_handler(Workspace::handle_follow);
|
||||||
client.add_view_message_handler(Workspace::handle_unfollow);
|
client.add_view_message_handler(Workspace::handle_unfollow);
|
||||||
|
@ -1399,7 +1465,7 @@ impl Workspace {
|
||||||
mut abs_paths: Vec<PathBuf>,
|
mut abs_paths: Vec<PathBuf>,
|
||||||
visible: bool,
|
visible: bool,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Task<Vec<Option<Result<Box<dyn ItemHandle>, Arc<anyhow::Error>>>>> {
|
) -> Task<Vec<Option<Result<Box<dyn ItemHandle>, anyhow::Error>>>> {
|
||||||
let fs = self.fs.clone();
|
let fs = self.fs.clone();
|
||||||
|
|
||||||
// Sort the paths to ensure we add worktrees for parents before their children.
|
// Sort the paths to ensure we add worktrees for parents before their children.
|
||||||
|
@ -1429,7 +1495,7 @@ impl Workspace {
|
||||||
if fs.is_file(&abs_path).await {
|
if fs.is_file(&abs_path).await {
|
||||||
Some(
|
Some(
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
this.open_path(project_path, true, cx)
|
this.open_path(project_path, None, true, cx)
|
||||||
})
|
})
|
||||||
.await,
|
.await,
|
||||||
)
|
)
|
||||||
|
@ -1749,10 +1815,11 @@ impl Workspace {
|
||||||
pub fn open_path(
|
pub fn open_path(
|
||||||
&mut self,
|
&mut self,
|
||||||
path: impl Into<ProjectPath>,
|
path: impl Into<ProjectPath>,
|
||||||
|
pane: Option<WeakViewHandle<Pane>>,
|
||||||
focus_item: bool,
|
focus_item: bool,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Task<Result<Box<dyn ItemHandle>, Arc<anyhow::Error>>> {
|
) -> Task<Result<Box<dyn ItemHandle>, anyhow::Error>> {
|
||||||
let pane = self.active_pane().downgrade();
|
let pane = pane.unwrap_or_else(|| self.active_pane().downgrade());
|
||||||
let task = self.load_path(path.into(), cx);
|
let task = self.load_path(path.into(), cx);
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
let (project_entry_id, build_item) = task.await?;
|
let (project_entry_id, build_item) = task.await?;
|
||||||
|
@ -2874,7 +2941,7 @@ pub fn open_paths(
|
||||||
cx: &mut MutableAppContext,
|
cx: &mut MutableAppContext,
|
||||||
) -> Task<(
|
) -> Task<(
|
||||||
ViewHandle<Workspace>,
|
ViewHandle<Workspace>,
|
||||||
Vec<Option<Result<Box<dyn ItemHandle>, Arc<anyhow::Error>>>>,
|
Vec<Option<Result<Box<dyn ItemHandle>, anyhow::Error>>>,
|
||||||
)> {
|
)> {
|
||||||
log::info!("open paths {:?}", abs_paths);
|
log::info!("open paths {:?}", abs_paths);
|
||||||
|
|
||||||
|
|
|
@ -818,7 +818,7 @@ mod tests {
|
||||||
|
|
||||||
// Open the first entry
|
// Open the first entry
|
||||||
let entry_1 = workspace
|
let entry_1 = workspace
|
||||||
.update(cx, |w, cx| w.open_path(file1.clone(), true, cx))
|
.update(cx, |w, cx| w.open_path(file1.clone(), None, true, cx))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
cx.read(|cx| {
|
cx.read(|cx| {
|
||||||
|
@ -832,7 +832,7 @@ mod tests {
|
||||||
|
|
||||||
// Open the second entry
|
// Open the second entry
|
||||||
workspace
|
workspace
|
||||||
.update(cx, |w, cx| w.open_path(file2.clone(), true, cx))
|
.update(cx, |w, cx| w.open_path(file2.clone(), None, true, cx))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
cx.read(|cx| {
|
cx.read(|cx| {
|
||||||
|
@ -846,7 +846,7 @@ mod tests {
|
||||||
|
|
||||||
// Open the first entry again. The existing pane item is activated.
|
// Open the first entry again. The existing pane item is activated.
|
||||||
let entry_1b = workspace
|
let entry_1b = workspace
|
||||||
.update(cx, |w, cx| w.open_path(file1.clone(), true, cx))
|
.update(cx, |w, cx| w.open_path(file1.clone(), None, true, cx))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(entry_1.id(), entry_1b.id());
|
assert_eq!(entry_1.id(), entry_1b.id());
|
||||||
|
@ -864,7 +864,7 @@ mod tests {
|
||||||
workspace
|
workspace
|
||||||
.update(cx, |w, cx| {
|
.update(cx, |w, cx| {
|
||||||
w.split_pane(w.active_pane().clone(), SplitDirection::Right, cx);
|
w.split_pane(w.active_pane().clone(), SplitDirection::Right, cx);
|
||||||
w.open_path(file2.clone(), true, cx)
|
w.open_path(file2.clone(), None, true, cx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -883,8 +883,8 @@ mod tests {
|
||||||
// Open the third entry twice concurrently. Only one pane item is added.
|
// Open the third entry twice concurrently. Only one pane item is added.
|
||||||
let (t1, t2) = workspace.update(cx, |w, cx| {
|
let (t1, t2) = workspace.update(cx, |w, cx| {
|
||||||
(
|
(
|
||||||
w.open_path(file3.clone(), true, cx),
|
w.open_path(file3.clone(), None, true, cx),
|
||||||
w.open_path(file3.clone(), true, cx),
|
w.open_path(file3.clone(), None, true, cx),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
t1.await.unwrap();
|
t1.await.unwrap();
|
||||||
|
@ -1195,7 +1195,7 @@ mod tests {
|
||||||
workspace
|
workspace
|
||||||
.update(cx, |workspace, cx| {
|
.update(cx, |workspace, cx| {
|
||||||
workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, cx);
|
workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, cx);
|
||||||
workspace.open_path((worktree.read(cx).id(), "the-new-name.rs"), true, cx)
|
workspace.open_path((worktree.read(cx).id(), "the-new-name.rs"), None, true, cx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -1284,7 +1284,7 @@ mod tests {
|
||||||
let pane_1 = cx.read(|cx| workspace.read(cx).active_pane().clone());
|
let pane_1 = cx.read(|cx| workspace.read(cx).active_pane().clone());
|
||||||
|
|
||||||
workspace
|
workspace
|
||||||
.update(cx, |w, cx| w.open_path(file1.clone(), true, cx))
|
.update(cx, |w, cx| w.open_path(file1.clone(), None, true, cx))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -1359,7 +1359,7 @@ mod tests {
|
||||||
let file3 = entries[2].clone();
|
let file3 = entries[2].clone();
|
||||||
|
|
||||||
let editor1 = workspace
|
let editor1 = workspace
|
||||||
.update(cx, |w, cx| w.open_path(file1.clone(), true, cx))
|
.update(cx, |w, cx| w.open_path(file1.clone(), None, true, cx))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.downcast::<Editor>()
|
.downcast::<Editor>()
|
||||||
|
@ -1370,13 +1370,13 @@ mod tests {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
let editor2 = workspace
|
let editor2 = workspace
|
||||||
.update(cx, |w, cx| w.open_path(file2.clone(), true, cx))
|
.update(cx, |w, cx| w.open_path(file2.clone(), None, true, cx))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.downcast::<Editor>()
|
.downcast::<Editor>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let editor3 = workspace
|
let editor3 = workspace
|
||||||
.update(cx, |w, cx| w.open_path(file3.clone(), true, cx))
|
.update(cx, |w, cx| w.open_path(file3.clone(), None, true, cx))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.downcast::<Editor>()
|
.downcast::<Editor>()
|
||||||
|
@ -1626,22 +1626,22 @@ mod tests {
|
||||||
let file4 = entries[3].clone();
|
let file4 = entries[3].clone();
|
||||||
|
|
||||||
let file1_item_id = workspace
|
let file1_item_id = workspace
|
||||||
.update(cx, |w, cx| w.open_path(file1.clone(), true, cx))
|
.update(cx, |w, cx| w.open_path(file1.clone(), None, true, cx))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.id();
|
.id();
|
||||||
let file2_item_id = workspace
|
let file2_item_id = workspace
|
||||||
.update(cx, |w, cx| w.open_path(file2.clone(), true, cx))
|
.update(cx, |w, cx| w.open_path(file2.clone(), None, true, cx))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.id();
|
.id();
|
||||||
let file3_item_id = workspace
|
let file3_item_id = workspace
|
||||||
.update(cx, |w, cx| w.open_path(file3.clone(), true, cx))
|
.update(cx, |w, cx| w.open_path(file3.clone(), None, true, cx))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.id();
|
.id();
|
||||||
let file4_item_id = workspace
|
let file4_item_id = workspace
|
||||||
.update(cx, |w, cx| w.open_path(file4.clone(), true, cx))
|
.update(cx, |w, cx| w.open_path(file4.clone(), None, true, cx))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.id();
|
.id();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue