Do not allow drag and drop of FS entries into the remote projects (#19565)
Release Notes: - N/A
This commit is contained in:
parent
23ad470daf
commit
7a6550c1d1
4 changed files with 87 additions and 71 deletions
|
@ -356,8 +356,10 @@ impl AssistantPanel {
|
||||||
let project = workspace.project().clone();
|
let project = workspace.project().clone();
|
||||||
pane.set_custom_drop_handle(cx, move |_, dropped_item, cx| {
|
pane.set_custom_drop_handle(cx, move |_, dropped_item, cx| {
|
||||||
let action = maybe!({
|
let action = maybe!({
|
||||||
if let Some(paths) = dropped_item.downcast_ref::<ExternalPaths>() {
|
if project.read(cx).is_local() {
|
||||||
return Some(InsertDraggedFiles::ExternalFiles(paths.paths().to_vec()));
|
if let Some(paths) = dropped_item.downcast_ref::<ExternalPaths>() {
|
||||||
|
return Some(InsertDraggedFiles::ExternalFiles(paths.paths().to_vec()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let project_paths = if let Some(tab) = dropped_item.downcast_ref::<DraggedTab>()
|
let project_paths = if let Some(tab) = dropped_item.downcast_ref::<DraggedTab>()
|
||||||
|
|
|
@ -2327,6 +2327,7 @@ impl ProjectPanel {
|
||||||
let depth = details.depth;
|
let depth = details.depth;
|
||||||
let worktree_id = details.worktree_id;
|
let worktree_id = details.worktree_id;
|
||||||
let selections = Arc::new(self.marked_entries.clone());
|
let selections = Arc::new(self.marked_entries.clone());
|
||||||
|
let is_local = self.project.read(cx).is_local();
|
||||||
|
|
||||||
let dragged_selection = DraggedSelection {
|
let dragged_selection = DraggedSelection {
|
||||||
active_selection: selection,
|
active_selection: selection,
|
||||||
|
@ -2334,57 +2335,59 @@ impl ProjectPanel {
|
||||||
};
|
};
|
||||||
div()
|
div()
|
||||||
.id(entry_id.to_proto() as usize)
|
.id(entry_id.to_proto() as usize)
|
||||||
.on_drag_move::<ExternalPaths>(cx.listener(
|
.when(is_local, |div| {
|
||||||
move |this, event: &DragMoveEvent<ExternalPaths>, cx| {
|
div.on_drag_move::<ExternalPaths>(cx.listener(
|
||||||
if event.bounds.contains(&event.event.position) {
|
move |this, event: &DragMoveEvent<ExternalPaths>, cx| {
|
||||||
if this.last_external_paths_drag_over_entry == Some(entry_id) {
|
if event.bounds.contains(&event.event.position) {
|
||||||
return;
|
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();
|
this.last_external_paths_drag_over_entry = Some(entry_id);
|
||||||
|
this.marked_entries.clear();
|
||||||
|
|
||||||
let Some((worktree, path, entry)) = maybe!({
|
let Some((worktree, path, entry)) = maybe!({
|
||||||
let worktree = this
|
let worktree = this
|
||||||
.project
|
.project
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.worktree_for_id(selection.worktree_id, cx)?;
|
.worktree_for_id(selection.worktree_id, cx)?;
|
||||||
let worktree = worktree.read(cx);
|
let worktree = worktree.read(cx);
|
||||||
let abs_path = worktree.absolutize(&path).log_err()?;
|
let abs_path = worktree.absolutize(&path).log_err()?;
|
||||||
let path = if abs_path.is_dir() {
|
let path = if abs_path.is_dir() {
|
||||||
path.as_ref()
|
path.as_ref()
|
||||||
} else {
|
} else {
|
||||||
path.parent()?
|
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 {
|
this.marked_entries.insert(SelectedEntry {
|
||||||
entry_id: entry.id,
|
entry_id: entry.id,
|
||||||
worktree_id: worktree.id(),
|
worktree_id: worktree.id(),
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
cx.notify();
|
for entry in worktree.child_entries(path) {
|
||||||
}
|
this.marked_entries.insert(SelectedEntry {
|
||||||
},
|
entry_id: entry.id,
|
||||||
))
|
worktree_id: worktree.id(),
|
||||||
.on_drop(
|
});
|
||||||
cx.listener(move |this, external_paths: &ExternalPaths, cx| {
|
}
|
||||||
this.last_external_paths_drag_over_entry = None;
|
|
||||||
this.marked_entries.clear();
|
cx.notify();
|
||||||
this.drop_external_files(external_paths.paths(), entry_id, 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();
|
||||||
|
this.drop_external_files(external_paths.paths(), entry_id, cx);
|
||||||
|
cx.stop_propagation();
|
||||||
|
},
|
||||||
|
))
|
||||||
|
})
|
||||||
.on_drag(dragged_selection, move |selection, cx| {
|
.on_drag(dragged_selection, move |selection, cx| {
|
||||||
cx.new_view(|_| DraggedProjectEntryView {
|
cx.new_view(|_| DraggedProjectEntryView {
|
||||||
details: details.clone(),
|
details: details.clone(),
|
||||||
|
@ -2802,6 +2805,7 @@ impl Render for ProjectPanel {
|
||||||
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> impl IntoElement {
|
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> impl IntoElement {
|
||||||
let has_worktree = !self.visible_entries.is_empty();
|
let has_worktree = !self.visible_entries.is_empty();
|
||||||
let project = self.project.read(cx);
|
let project = self.project.read(cx);
|
||||||
|
let is_local = project.is_local();
|
||||||
|
|
||||||
if has_worktree {
|
if has_worktree {
|
||||||
let item_count = self
|
let item_count = self
|
||||||
|
@ -2939,29 +2943,31 @@ impl Render for ProjectPanel {
|
||||||
.log_err();
|
.log_err();
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
.drag_over::<ExternalPaths>(|style, _, cx| {
|
.when(is_local, |div| {
|
||||||
style.bg(cx.theme().colors().drop_target_background)
|
div.drag_over::<ExternalPaths>(|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();
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,7 @@ impl TerminalPanel {
|
||||||
pane.display_nav_history_buttons(None);
|
pane.display_nav_history_buttons(None);
|
||||||
pane.set_should_display_tab_bar(|_| true);
|
pane.set_should_display_tab_bar(|_| true);
|
||||||
|
|
||||||
|
let is_local = workspace.project().read(cx).is_local();
|
||||||
let workspace = workspace.weak_handle();
|
let workspace = workspace.weak_handle();
|
||||||
pane.set_custom_drop_handle(cx, move |pane, dropped_item, cx| {
|
pane.set_custom_drop_handle(cx, move |pane, dropped_item, cx| {
|
||||||
if let Some(tab) = dropped_item.downcast_ref::<DraggedTab>() {
|
if let Some(tab) = dropped_item.downcast_ref::<DraggedTab>() {
|
||||||
|
@ -128,8 +129,10 @@ impl TerminalPanel {
|
||||||
{
|
{
|
||||||
add_paths_to_terminal(pane, &[entry_path], cx);
|
add_paths_to_terminal(pane, &[entry_path], cx);
|
||||||
}
|
}
|
||||||
} else if let Some(paths) = dropped_item.downcast_ref::<ExternalPaths>() {
|
} else if is_local {
|
||||||
add_paths_to_terminal(pane, paths.paths(), cx);
|
if let Some(paths) = dropped_item.downcast_ref::<ExternalPaths>() {
|
||||||
|
add_paths_to_terminal(pane, paths.paths(), cx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlFlow::Break(())
|
ControlFlow::Break(())
|
||||||
|
|
|
@ -2570,6 +2570,7 @@ impl Render for Pane {
|
||||||
|
|
||||||
let should_display_tab_bar = self.should_display_tab_bar.clone();
|
let should_display_tab_bar = self.should_display_tab_bar.clone();
|
||||||
let display_tab_bar = should_display_tab_bar(cx);
|
let display_tab_bar = should_display_tab_bar(cx);
|
||||||
|
let is_local = self.project.read(cx).is_local();
|
||||||
|
|
||||||
v_flex()
|
v_flex()
|
||||||
.key_context(key_context)
|
.key_context(key_context)
|
||||||
|
@ -2697,7 +2698,9 @@ impl Render for Pane {
|
||||||
.group("")
|
.group("")
|
||||||
.on_drag_move::<DraggedTab>(cx.listener(Self::handle_drag_move))
|
.on_drag_move::<DraggedTab>(cx.listener(Self::handle_drag_move))
|
||||||
.on_drag_move::<DraggedSelection>(cx.listener(Self::handle_drag_move))
|
.on_drag_move::<DraggedSelection>(cx.listener(Self::handle_drag_move))
|
||||||
.on_drag_move::<ExternalPaths>(cx.listener(Self::handle_drag_move))
|
.when(is_local, |div| {
|
||||||
|
div.on_drag_move::<ExternalPaths>(cx.listener(Self::handle_drag_move))
|
||||||
|
})
|
||||||
.map(|div| {
|
.map(|div| {
|
||||||
if let Some(item) = self.active_item() {
|
if let Some(item) = self.active_item() {
|
||||||
div.v_flex()
|
div.v_flex()
|
||||||
|
@ -2723,7 +2726,9 @@ impl Render for Pane {
|
||||||
.bg(cx.theme().colors().drop_target_background)
|
.bg(cx.theme().colors().drop_target_background)
|
||||||
.group_drag_over::<DraggedTab>("", |style| style.visible())
|
.group_drag_over::<DraggedTab>("", |style| style.visible())
|
||||||
.group_drag_over::<DraggedSelection>("", |style| style.visible())
|
.group_drag_over::<DraggedSelection>("", |style| style.visible())
|
||||||
.group_drag_over::<ExternalPaths>("", |style| style.visible())
|
.when(is_local, |div| {
|
||||||
|
div.group_drag_over::<ExternalPaths>("", |style| style.visible())
|
||||||
|
})
|
||||||
.when_some(self.can_drop_predicate.clone(), |this, p| {
|
.when_some(self.can_drop_predicate.clone(), |this, p| {
|
||||||
this.can_drop(move |a, cx| p(a, cx))
|
this.can_drop(move |a, cx| p(a, cx))
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue