From 7a6550c1d15adb32838e5bd74dbf62eac38637b3 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 22 Oct 2024 22:34:54 +0300 Subject: [PATCH] Do not allow drag and drop of FS entries into the remote projects (#19565) Release Notes: - N/A --- crates/assistant/src/assistant_panel.rs | 6 +- crates/project_panel/src/project_panel.rs | 138 +++++++++++---------- crates/terminal_view/src/terminal_panel.rs | 7 +- crates/workspace/src/pane.rs | 9 +- 4 files changed, 88 insertions(+), 72 deletions(-) diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs index dea0cd85968a321098d2ba4bc254b7b05a2ee4a4..f9a277f8277d770d6481e08c5b5d8c621db49cea 100644 --- a/crates/assistant/src/assistant_panel.rs +++ b/crates/assistant/src/assistant_panel.rs @@ -356,8 +356,10 @@ impl AssistantPanel { let project = workspace.project().clone(); pane.set_custom_drop_handle(cx, move |_, dropped_item, cx| { let action = maybe!({ - if let Some(paths) = dropped_item.downcast_ref::() { - return Some(InsertDraggedFiles::ExternalFiles(paths.paths().to_vec())); + if project.read(cx).is_local() { + if let Some(paths) = dropped_item.downcast_ref::() { + return Some(InsertDraggedFiles::ExternalFiles(paths.paths().to_vec())); + } } let project_paths = if let Some(tab) = dropped_item.downcast_ref::() diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index aca5cc7beeaf25bb32e6aa4a3f041690c6bea500..2f3a3162500a149ad9934b1f4eeca73b923fbe8b 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -2327,6 +2327,7 @@ impl ProjectPanel { let depth = details.depth; let worktree_id = details.worktree_id; let selections = Arc::new(self.marked_entries.clone()); + let is_local = self.project.read(cx).is_local(); let dragged_selection = DraggedSelection { active_selection: selection, @@ -2334,57 +2335,59 @@ impl ProjectPanel { }; div() .id(entry_id.to_proto() as usize) - .on_drag_move::(cx.listener( - move |this, event: &DragMoveEvent, cx| { - if event.bounds.contains(&event.event.position) { - if this.last_external_paths_drag_over_entry == Some(entry_id) { - return; - } - this.last_external_paths_drag_over_entry = Some(entry_id); - this.marked_entries.clear(); - - let Some((worktree, path, entry)) = maybe!({ - let worktree = this - .project - .read(cx) - .worktree_for_id(selection.worktree_id, cx)?; - let worktree = worktree.read(cx); - let abs_path = worktree.absolutize(&path).log_err()?; - let path = if abs_path.is_dir() { - path.as_ref() - } else { - path.parent()? + .when(is_local, |div| { + div.on_drag_move::(cx.listener( + move |this, event: &DragMoveEvent, cx| { + if event.bounds.contains(&event.event.position) { + if this.last_external_paths_drag_over_entry == Some(entry_id) { + return; + } + this.last_external_paths_drag_over_entry = Some(entry_id); + this.marked_entries.clear(); + + let Some((worktree, path, entry)) = maybe!({ + let worktree = this + .project + .read(cx) + .worktree_for_id(selection.worktree_id, cx)?; + let worktree = worktree.read(cx); + let abs_path = worktree.absolutize(&path).log_err()?; + let path = if abs_path.is_dir() { + path.as_ref() + } else { + path.parent()? + }; + let entry = worktree.entry_for_path(path)?; + Some((worktree, path, entry)) + }) else { + return; }; - let entry = worktree.entry_for_path(path)?; - Some((worktree, path, entry)) - }) else { - return; - }; - - this.marked_entries.insert(SelectedEntry { - entry_id: entry.id, - worktree_id: worktree.id(), - }); - for entry in worktree.child_entries(path) { this.marked_entries.insert(SelectedEntry { entry_id: entry.id, worktree_id: worktree.id(), }); - } - cx.notify(); - } - }, - )) - .on_drop( - cx.listener(move |this, external_paths: &ExternalPaths, cx| { - this.last_external_paths_drag_over_entry = None; - this.marked_entries.clear(); - this.drop_external_files(external_paths.paths(), entry_id, cx); - cx.stop_propagation(); - }), - ) + for entry in worktree.child_entries(path) { + this.marked_entries.insert(SelectedEntry { + entry_id: entry.id, + worktree_id: worktree.id(), + }); + } + + cx.notify(); + } + }, + )) + .on_drop(cx.listener( + move |this, external_paths: &ExternalPaths, cx| { + this.last_external_paths_drag_over_entry = None; + this.marked_entries.clear(); + this.drop_external_files(external_paths.paths(), entry_id, cx); + cx.stop_propagation(); + }, + )) + }) .on_drag(dragged_selection, move |selection, cx| { cx.new_view(|_| DraggedProjectEntryView { details: details.clone(), @@ -2802,6 +2805,7 @@ impl Render for ProjectPanel { fn render(&mut self, cx: &mut gpui::ViewContext) -> impl IntoElement { let has_worktree = !self.visible_entries.is_empty(); let project = self.project.read(cx); + let is_local = project.is_local(); if has_worktree { let item_count = self @@ -2939,29 +2943,31 @@ impl Render for ProjectPanel { .log_err(); })), ) - .drag_over::(|style, _, cx| { - style.bg(cx.theme().colors().drop_target_background) + .when(is_local, |div| { + div.drag_over::(|style, _, cx| { + style.bg(cx.theme().colors().drop_target_background) + }) + .on_drop(cx.listener( + move |this, external_paths: &ExternalPaths, cx| { + this.last_external_paths_drag_over_entry = None; + this.marked_entries.clear(); + if let Some(task) = this + .workspace + .update(cx, |workspace, cx| { + workspace.open_workspace_for_paths( + true, + external_paths.paths().to_owned(), + cx, + ) + }) + .log_err() + { + task.detach_and_log_err(cx); + } + cx.stop_propagation(); + }, + )) }) - .on_drop( - cx.listener(move |this, external_paths: &ExternalPaths, cx| { - this.last_external_paths_drag_over_entry = None; - this.marked_entries.clear(); - if let Some(task) = this - .workspace - .update(cx, |workspace, cx| { - workspace.open_workspace_for_paths( - true, - external_paths.paths().to_owned(), - cx, - ) - }) - .log_err() - { - task.detach_and_log_err(cx); - } - cx.stop_propagation(); - }), - ) } } } diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rs index 5097cbc28a4ae39ad8d9c94f10394a31cb66e7c8..df6fdec3080efbf799b9d211c63c576f2a1a92ce 100644 --- a/crates/terminal_view/src/terminal_panel.rs +++ b/crates/terminal_view/src/terminal_panel.rs @@ -89,6 +89,7 @@ impl TerminalPanel { pane.display_nav_history_buttons(None); pane.set_should_display_tab_bar(|_| true); + let is_local = workspace.project().read(cx).is_local(); let workspace = workspace.weak_handle(); pane.set_custom_drop_handle(cx, move |pane, dropped_item, cx| { if let Some(tab) = dropped_item.downcast_ref::() { @@ -128,8 +129,10 @@ impl TerminalPanel { { add_paths_to_terminal(pane, &[entry_path], cx); } - } else if let Some(paths) = dropped_item.downcast_ref::() { - add_paths_to_terminal(pane, paths.paths(), cx); + } else if is_local { + if let Some(paths) = dropped_item.downcast_ref::() { + add_paths_to_terminal(pane, paths.paths(), cx); + } } ControlFlow::Break(()) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index f7e9dba9658c1d3292cb3e6f30c37d63e519adc2..6b99401f050e8e268bc6079eefdfe286dc2f85a9 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -2570,6 +2570,7 @@ impl Render for Pane { let should_display_tab_bar = self.should_display_tab_bar.clone(); let display_tab_bar = should_display_tab_bar(cx); + let is_local = self.project.read(cx).is_local(); v_flex() .key_context(key_context) @@ -2697,7 +2698,9 @@ impl Render for Pane { .group("") .on_drag_move::(cx.listener(Self::handle_drag_move)) .on_drag_move::(cx.listener(Self::handle_drag_move)) - .on_drag_move::(cx.listener(Self::handle_drag_move)) + .when(is_local, |div| { + div.on_drag_move::(cx.listener(Self::handle_drag_move)) + }) .map(|div| { if let Some(item) = self.active_item() { div.v_flex() @@ -2723,7 +2726,9 @@ impl Render for Pane { .bg(cx.theme().colors().drop_target_background) .group_drag_over::("", |style| style.visible()) .group_drag_over::("", |style| style.visible()) - .group_drag_over::("", |style| style.visible()) + .when(is_local, |div| { + div.group_drag_over::("", |style| style.visible()) + }) .when_some(self.can_drop_predicate.clone(), |this, p| { this.can_drop(move |a, cx| p(a, cx)) })