project_panel: Add rename, delete and duplicate actions to workspace (#34478)

Smit Barmase and Danilo Leal created

Release Notes:

- Added `project panel: rename`, `project panel: delete` and `project
panel: duplicate` actions to workspace.

Co-authored-by: Danilo Leal <daniloleal09@gmail.com>

Change summary

crates/project_panel/src/project_panel.rs | 27 +++++++++++++++++++++++++
1 file changed, 27 insertions(+)

Detailed changes

crates/project_panel/src/project_panel.rs 🔗

@@ -320,6 +320,33 @@ pub fn init(cx: &mut App) {
                 });
             }
         });
+
+        workspace.register_action(|workspace, action: &Rename, window, cx| {
+            if let Some(panel) = workspace.panel::<ProjectPanel>(cx) {
+                panel.update(cx, |panel, cx| {
+                    if let Some(first_marked) = panel.marked_entries.first() {
+                        let first_marked = *first_marked;
+                        panel.marked_entries.clear();
+                        panel.selection = Some(first_marked);
+                    }
+                    panel.rename(action, window, cx);
+                });
+            }
+        });
+
+        workspace.register_action(|workspace, action: &Duplicate, window, cx| {
+            if let Some(panel) = workspace.panel::<ProjectPanel>(cx) {
+                panel.update(cx, |panel, cx| {
+                    panel.duplicate(action, window, cx);
+                });
+            }
+        });
+
+        workspace.register_action(|workspace, action: &Delete, window, cx| {
+            if let Some(panel) = workspace.panel::<ProjectPanel>(cx) {
+                panel.update(cx, |panel, cx| panel.delete(action, window, cx));
+            }
+        });
     })
     .detach();
 }