project panel: Add Duplicate action (#12081)

This fixes #5304 by adding a new Duplicate action to the project panel
context menu.

It really is implemented on top of copy&paste.



Release Notes:

- Added a Duplicate action to the project panel.
([#5304](https://github.com/zed-industries/zed/issues/5304)).



https://github.com/zed-industries/zed/assets/1185253/f0fa6a4b-f066-47df-84f0-257a049800d1
This commit is contained in:
Thorsten Ball 2024-05-21 09:58:10 +02:00 committed by GitHub
parent ba1d28f160
commit a5b14de401
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -130,6 +130,7 @@ actions!(
Copy, Copy,
CopyPath, CopyPath,
CopyRelativePath, CopyRelativePath,
Duplicate,
RevealInFinder, RevealInFinder,
Cut, Cut,
Paste, Paste,
@ -460,6 +461,7 @@ impl ProjectPanel {
.separator() .separator()
.action("Cut", Box::new(Cut)) .action("Cut", Box::new(Cut))
.action("Copy", Box::new(Copy)) .action("Copy", Box::new(Copy))
.action("Duplicate", Box::new(Duplicate))
// TODO: Paste should always be visible, but disabled when clipboard is empty // TODO: Paste should always be visible, but disabled when clipboard is empty
.when_some(self.clipboard_entry, |menu, entry| { .when_some(self.clipboard_entry, |menu, entry| {
menu.when(entry.worktree_id() == worktree_id, |menu| { menu.when(entry.worktree_id() == worktree_id, |menu| {
@ -1156,6 +1158,11 @@ impl ProjectPanel {
}); });
} }
fn duplicate(&mut self, _: &Duplicate, cx: &mut ViewContext<Self>) {
self.copy(&Copy {}, cx);
self.paste(&Paste {}, cx);
}
fn copy_path(&mut self, _: &CopyPath, cx: &mut ViewContext<Self>) { fn copy_path(&mut self, _: &CopyPath, cx: &mut ViewContext<Self>) {
if let Some((worktree, entry)) = self.selected_entry(cx) { if let Some((worktree, entry)) = self.selected_entry(cx) {
cx.write_to_clipboard(ClipboardItem::new( cx.write_to_clipboard(ClipboardItem::new(
@ -1831,6 +1838,7 @@ impl Render for ProjectPanel {
.on_action(cx.listener(Self::cut)) .on_action(cx.listener(Self::cut))
.on_action(cx.listener(Self::copy)) .on_action(cx.listener(Self::copy))
.on_action(cx.listener(Self::paste)) .on_action(cx.listener(Self::paste))
.on_action(cx.listener(Self::duplicate))
}) })
.when(project.is_local(), |el| { .when(project.is_local(), |el| {
el.on_action(cx.listener(Self::reveal_in_finder)) el.on_action(cx.listener(Self::reveal_in_finder))