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
.update(&mut cx, |workspace, cx| {
workspace.open_paths(vec![entry_path], true, cx)
workspace.open_paths(vec![entry_path], true, None, cx)
})?
.await;

View file

@ -197,7 +197,7 @@ impl TerminalView {
cx.spawn(|_, mut cx| async move {
let opened_items = task_workspace
.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")?
.await;

View file

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

View file

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