Implement external file drop in pane

This commit is contained in:
Kirill Bulatov 2024-01-07 01:18:02 +02:00
parent 8ff05c6a72
commit c4e306162c
4 changed files with 24 additions and 29 deletions

View file

@ -100,7 +100,7 @@ pub fn new_journal_entry(app_state: Arc<AppState>, cx: &mut WindowContext) {
let opened = workspace let opened = workspace
.update(&mut cx, |workspace, cx| { .update(&mut cx, |workspace, cx| {
workspace.open_paths(vec![entry_path], true, cx) workspace.open_paths(vec![entry_path], true, None, cx)
})? })?
.await; .await;

View file

@ -197,7 +197,7 @@ impl TerminalView {
cx.spawn(|_, mut cx| async move { cx.spawn(|_, mut cx| async move {
let opened_items = task_workspace let opened_items = task_workspace
.update(&mut cx, |workspace, cx| { .update(&mut cx, |workspace, cx| {
workspace.open_paths(vec![path.path_like], is_dir, cx) workspace.open_paths(vec![path.path_like], is_dir, None, cx)
}) })
.context("workspace update")? .context("workspace update")?
.await; .await;

View file

@ -1869,28 +1869,21 @@ impl Pane {
paths: &ExternalPaths, paths: &ExternalPaths,
cx: &mut ViewContext<'_, Pane>, cx: &mut ViewContext<'_, Pane>,
) { ) {
// let mut to_pane = cx.view().clone(); let mut to_pane = cx.view().clone();
// let split_direction = self.drag_split_direction; let split_direction = self.drag_split_direction;
// let project_entry_id = *project_entry_id; let paths = paths.paths().to_vec();
// self.workspace self.workspace
// .update(cx, |_, cx| { .update(cx, |_, cx| {
// cx.defer(move |workspace, cx| { cx.defer(move |workspace, cx| {
// if let Some(path) = workspace if let Some(split_direction) = split_direction {
// .project() to_pane = workspace.split_pane(to_pane, split_direction, cx);
// .read(cx) }
// .path_for_entry(project_entry_id, cx) workspace
// { .open_paths(paths, true, Some(to_pane.downgrade()), cx)
// if let Some(split_direction) = split_direction { .detach();
// to_pane = workspace.split_pane(to_pane, split_direction, cx); });
// } })
// workspace .log_err();
// .open_path(path, Some(to_pane.downgrade()), true, cx)
// .detach_and_log_err(cx);
// }
// });
// })
// .log_err();
dbg!("@@@@@@@@@@@@@@", paths);
} }
pub fn display_nav_history_buttons(&mut self, display: bool) { pub fn display_nav_history_buttons(&mut self, display: bool) {

View file

@ -1322,6 +1322,7 @@ impl Workspace {
&mut self, &mut self,
mut abs_paths: Vec<PathBuf>, mut abs_paths: Vec<PathBuf>,
visible: bool, visible: bool,
pane: Option<WeakView<Pane>>,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Task<Vec<Option<Result<Box<dyn ItemHandle>, anyhow::Error>>>> { ) -> Task<Vec<Option<Result<Box<dyn ItemHandle>, anyhow::Error>>>> {
log::info!("open paths {abs_paths:?}"); log::info!("open paths {abs_paths:?}");
@ -1351,12 +1352,13 @@ impl Workspace {
let this = this.clone(); let this = this.clone();
let abs_path = abs_path.clone(); let abs_path = abs_path.clone();
let fs = fs.clone(); let fs = fs.clone();
let pane = pane.clone();
let task = cx.spawn(move |mut cx| async move { let task = cx.spawn(move |mut cx| async move {
let (worktree, project_path) = project_path?; let (worktree, project_path) = project_path?;
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, None, true, cx) this.open_path(project_path, pane, true, cx)
}) })
.log_err()? .log_err()?
.await, .await,
@ -1402,7 +1404,7 @@ impl Workspace {
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
if let Some(paths) = paths.await.log_err().flatten() { if let Some(paths) = paths.await.log_err().flatten() {
let results = this let results = this
.update(&mut cx, |this, cx| this.open_paths(paths, true, cx))? .update(&mut cx, |this, cx| this.open_paths(paths, true, None, cx))?
.await; .await;
for result in results.into_iter().flatten() { for result in results.into_iter().flatten() {
result.log_err(); result.log_err();
@ -1788,7 +1790,7 @@ impl Workspace {
cx.spawn(|workspace, mut cx| async move { cx.spawn(|workspace, mut cx| async move {
let open_paths_task_result = workspace let open_paths_task_result = workspace
.update(&mut cx, |workspace, cx| { .update(&mut cx, |workspace, cx| {
workspace.open_paths(vec![abs_path.clone()], visible, cx) workspace.open_paths(vec![abs_path.clone()], visible, None, cx)
}) })
.with_context(|| format!("open abs path {abs_path:?} task spawn"))? .with_context(|| format!("open abs path {abs_path:?} task spawn"))?
.await; .await;
@ -4087,7 +4089,7 @@ pub fn open_paths(
existing.clone(), existing.clone(),
existing existing
.update(&mut cx, |workspace, cx| { .update(&mut cx, |workspace, cx| {
workspace.open_paths(abs_paths, true, cx) workspace.open_paths(abs_paths, true, None, cx)
})? })?
.await, .await,
)) ))
@ -4135,7 +4137,7 @@ pub fn create_and_open_local_file(
let mut items = workspace let mut items = workspace
.update(&mut cx, |workspace, cx| { .update(&mut cx, |workspace, cx| {
workspace.with_local_workspace(cx, |workspace, cx| { workspace.with_local_workspace(cx, |workspace, cx| {
workspace.open_paths(vec![path.to_path_buf()], false, cx) workspace.open_paths(vec![path.to_path_buf()], false, None, cx)
}) })
})? })?
.await? .await?