Fix warnings

Max Brunsfeld created

Change summary

crates/project_panel2/src/project_panel.rs | 252 +++++++++++------------
1 file changed, 122 insertions(+), 130 deletions(-)

Detailed changes

crates/project_panel2/src/project_panel.rs 🔗

@@ -9,8 +9,8 @@ use file_associations::FileAssociations;
 use anyhow::{anyhow, Result};
 use gpui::{
     actions, div, px, rems, svg, uniform_list, Action, AppContext, AssetSource, AsyncWindowContext,
-    ClipboardItem, Component, Div, Entity, EventEmitter, FocusHandle, FocusableKeyDispatch, Model,
-    ParentElement as _, Pixels, Point, PromptLevel, Render, StatefulInteractive,
+    ClipboardItem, Component, Div, EventEmitter, FocusHandle, FocusableKeyDispatch, Model,
+    MouseButton, ParentElement as _, Pixels, Point, PromptLevel, Render, StatefulInteractive,
     StatefulInteractivity, StatelessInteractive, Styled, Task, UniformListScrollHandle, View,
     ViewContext, VisualContext as _, WeakView, WindowContext,
 };
@@ -54,8 +54,8 @@ pub struct ProjectPanel {
     edit_state: Option<EditState>,
     filename_editor: View<Editor>,
     clipboard_entry: Option<ClipboardEntry>,
-    dragged_entry_destination: Option<Arc<Path>>,
-    workspace: WeakView<Workspace>,
+    _dragged_entry_destination: Option<Arc<Path>>,
+    _workspace: WeakView<Workspace>,
     has_focus: bool,
     width: Option<f32>,
     pending_serialization: Task<Option<()>>,
@@ -219,7 +219,6 @@ impl ProjectPanel {
             // })
             // .detach();
 
-            let view_id = cx.view().entity_id();
             let mut this = Self {
                 project: project.clone(),
                 fs: workspace.app_state().fs.clone(),
@@ -233,8 +232,8 @@ impl ProjectPanel {
                 filename_editor,
                 clipboard_entry: None,
                 // context_menu: cx.add_view(|cx| ContextMenu::new(view_id, cx)),
-                dragged_entry_destination: None,
-                workspace: workspace.weak_handle(),
+                _dragged_entry_destination: None,
+                _workspace: workspace.weak_handle(),
                 has_focus: false,
                 width: None,
                 pending_serialization: Task::ready(None),
@@ -286,19 +285,19 @@ impl ProjectPanel {
                     }
                 }
                 &Event::SplitEntry { entry_id } => {
-                    // if let Some(worktree) = project.read(cx).worktree_for_entry(entry_id, cx) {
-                    //     if let Some(entry) = worktree.read(cx).entry_for_id(entry_id) {
-                    //         workspace
-                    //             .split_path(
-                    //                 ProjectPath {
-                    //                     worktree_id: worktree.read(cx).id(),
-                    //                     path: entry.path.clone(),
-                    //                 },
-                    //                 cx,
-                    //             )
-                    //             .detach_and_log_err(cx);
-                    //     }
-                    // }
+                    if let Some(worktree) = project.read(cx).worktree_for_entry(entry_id, cx) {
+                        if let Some(_entry) = worktree.read(cx).entry_for_id(entry_id) {
+                            // workspace
+                            //     .split_path(
+                            //         ProjectPath {
+                            //             worktree_id: worktree.read(cx).id(),
+                            //             path: entry.path.clone(),
+                            //         },
+                            //         cx,
+                            //     )
+                            //     .detach_and_log_err(cx);
+                        }
+                    }
                 }
                 _ => {}
             }
@@ -366,79 +365,80 @@ impl ProjectPanel {
 
     fn deploy_context_menu(
         &mut self,
-        position: Point<Pixels>,
-        entry_id: ProjectEntryId,
-        cx: &mut ViewContext<Self>,
+        _position: Point<Pixels>,
+        _entry_id: ProjectEntryId,
+        _cx: &mut ViewContext<Self>,
     ) {
-        // let project = self.project.read(cx);
-
-        // let worktree_id = if let Some(id) = project.worktree_id_for_entry(entry_id, cx) {
-        //     id
-        // } else {
-        //     return;
-        // };
+        todo!()
+        //     let project = self.project.read(cx);
 
-        // self.selection = Some(Selection {
-        //     worktree_id,
-        //     entry_id,
-        // });
+        //     let worktree_id = if let Some(id) = project.worktree_id_for_entry(entry_id, cx) {
+        //         id
+        //     } else {
+        //         return;
+        //     };
 
-        // let mut menu_entries = Vec::new();
-        // if let Some((worktree, entry)) = self.selected_entry(cx) {
-        //     let is_root = Some(entry) == worktree.root_entry();
-        //     if !project.is_remote() {
-        //         menu_entries.push(ContextMenuItem::action(
-        //             "Add Folder to Project",
-        //             workspace::AddFolderToProject,
-        //         ));
-        //         if is_root {
-        //             let project = self.project.clone();
-        //             menu_entries.push(ContextMenuItem::handler("Remove from Project", move |cx| {
-        //                 project.update(cx, |project, cx| project.remove_worktree(worktree_id, cx));
-        //             }));
+        //     self.selection = Some(Selection {
+        //         worktree_id,
+        //         entry_id,
+        //     });
+
+        //     let mut menu_entries = Vec::new();
+        //     if let Some((worktree, entry)) = self.selected_entry(cx) {
+        //         let is_root = Some(entry) == worktree.root_entry();
+        //         if !project.is_remote() {
+        //             menu_entries.push(ContextMenuItem::action(
+        //                 "Add Folder to Project",
+        //                 workspace::AddFolderToProject,
+        //             ));
+        //             if is_root {
+        //                 let project = self.project.clone();
+        //                 menu_entries.push(ContextMenuItem::handler("Remove from Project", move |cx| {
+        //                     project.update(cx, |project, cx| project.remove_worktree(worktree_id, cx));
+        //                 }));
+        //             }
         //         }
-        //     }
-        //     menu_entries.push(ContextMenuItem::action("New File", NewFile));
-        //     menu_entries.push(ContextMenuItem::action("New Folder", NewDirectory));
-        //     menu_entries.push(ContextMenuItem::Separator);
-        //     menu_entries.push(ContextMenuItem::action("Cut", Cut));
-        //     menu_entries.push(ContextMenuItem::action("Copy", Copy));
-        //     if let Some(clipboard_entry) = self.clipboard_entry {
-        //         if clipboard_entry.worktree_id() == worktree.id() {
-        //             menu_entries.push(ContextMenuItem::action("Paste", Paste));
+        //         menu_entries.push(ContextMenuItem::action("New File", NewFile));
+        //         menu_entries.push(ContextMenuItem::action("New Folder", NewDirectory));
+        //         menu_entries.push(ContextMenuItem::Separator);
+        //         menu_entries.push(ContextMenuItem::action("Cut", Cut));
+        //         menu_entries.push(ContextMenuItem::action("Copy", Copy));
+        //         if let Some(clipboard_entry) = self.clipboard_entry {
+        //             if clipboard_entry.worktree_id() == worktree.id() {
+        //                 menu_entries.push(ContextMenuItem::action("Paste", Paste));
+        //             }
         //         }
-        //     }
-        //     menu_entries.push(ContextMenuItem::Separator);
-        //     menu_entries.push(ContextMenuItem::action("Copy Path", CopyPath));
-        //     menu_entries.push(ContextMenuItem::action(
-        //         "Copy Relative Path",
-        //         CopyRelativePath,
-        //     ));
-
-        //     if entry.is_dir() {
         //         menu_entries.push(ContextMenuItem::Separator);
-        //     }
-        //     menu_entries.push(ContextMenuItem::action("Reveal in Finder", RevealInFinder));
-        //     if entry.is_dir() {
-        //         menu_entries.push(ContextMenuItem::action("Open in Terminal", OpenInTerminal));
+        //         menu_entries.push(ContextMenuItem::action("Copy Path", CopyPath));
         //         menu_entries.push(ContextMenuItem::action(
-        //             "Search Inside",
-        //             NewSearchInDirectory,
+        //             "Copy Relative Path",
+        //             CopyRelativePath,
         //         ));
-        //     }
 
-        //     menu_entries.push(ContextMenuItem::Separator);
-        //     menu_entries.push(ContextMenuItem::action("Rename", Rename));
-        //     if !is_root {
-        //         menu_entries.push(ContextMenuItem::action("Delete", Delete));
+        //         if entry.is_dir() {
+        //             menu_entries.push(ContextMenuItem::Separator);
+        //         }
+        //         menu_entries.push(ContextMenuItem::action("Reveal in Finder", RevealInFinder));
+        //         if entry.is_dir() {
+        //             menu_entries.push(ContextMenuItem::action("Open in Terminal", OpenInTerminal));
+        //             menu_entries.push(ContextMenuItem::action(
+        //                 "Search Inside",
+        //                 NewSearchInDirectory,
+        //             ));
+        //         }
+
+        //         menu_entries.push(ContextMenuItem::Separator);
+        //         menu_entries.push(ContextMenuItem::action("Rename", Rename));
+        //         if !is_root {
+        //             menu_entries.push(ContextMenuItem::action("Delete", Delete));
+        //         }
         //     }
-        // }
 
-        // // self.context_menu.update(cx, |menu, cx| {
-        // //     menu.show(position, AnchorCorner::TopLeft, menu_entries, cx);
-        // // });
+        //     // self.context_menu.update(cx, |menu, cx| {
+        //     //     menu.show(position, AnchorCorner::TopLeft, menu_entries, cx);
+        //     // });
 
-        // cx.notify();
+        //     cx.notify();
     }
 
     fn expand_selected_entry(&mut self, _: &ExpandSelectedEntry, cx: &mut ViewContext<Self>) {
@@ -955,7 +955,7 @@ impl ProjectPanel {
         }
     }
 
-    fn open_in_terminal(&mut self, _: &OpenInTerminal, cx: &mut ViewContext<Self>) {
+    fn open_in_terminal(&mut self, _: &OpenInTerminal, _cx: &mut ViewContext<Self>) {
         todo!()
         // if let Some((worktree, entry)) = self.selected_entry(cx) {
         //     let window = cx.window();
@@ -990,36 +990,37 @@ impl ProjectPanel {
         }
     }
 
-    fn move_entry(
-        &mut self,
-        entry_to_move: ProjectEntryId,
-        destination: ProjectEntryId,
-        destination_is_file: bool,
-        cx: &mut ViewContext<Self>,
-    ) {
-        let destination_worktree = self.project.update(cx, |project, cx| {
-            let entry_path = project.path_for_entry(entry_to_move, cx)?;
-            let destination_entry_path = project.path_for_entry(destination, cx)?.path.clone();
-
-            let mut destination_path = destination_entry_path.as_ref();
-            if destination_is_file {
-                destination_path = destination_path.parent()?;
-            }
-
-            let mut new_path = destination_path.to_path_buf();
-            new_path.push(entry_path.path.file_name()?);
-            if new_path != entry_path.path.as_ref() {
-                let task = project.rename_entry(entry_to_move, new_path, cx)?;
-                cx.foreground_executor().spawn(task).detach_and_log_err(cx);
-            }
-
-            Some(project.worktree_id_for_entry(destination, cx)?)
-        });
-
-        if let Some(destination_worktree) = destination_worktree {
-            self.expand_entry(destination_worktree, destination, cx);
-        }
-    }
+    // todo!()
+    // fn move_entry(
+    //     &mut self,
+    //     entry_to_move: ProjectEntryId,
+    //     destination: ProjectEntryId,
+    //     destination_is_file: bool,
+    //     cx: &mut ViewContext<Self>,
+    // ) {
+    //     let destination_worktree = self.project.update(cx, |project, cx| {
+    //         let entry_path = project.path_for_entry(entry_to_move, cx)?;
+    //         let destination_entry_path = project.path_for_entry(destination, cx)?.path.clone();
+
+    //         let mut destination_path = destination_entry_path.as_ref();
+    //         if destination_is_file {
+    //             destination_path = destination_path.parent()?;
+    //         }
+
+    //         let mut new_path = destination_path.to_path_buf();
+    //         new_path.push(entry_path.path.file_name()?);
+    //         if new_path != entry_path.path.as_ref() {
+    //             let task = project.rename_entry(entry_to_move, new_path, cx)?;
+    //             cx.foreground_executor().spawn(task).detach_and_log_err(cx);
+    //         }
+
+    //         Some(project.worktree_id_for_entry(destination, cx)?)
+    //     });
+
+    //     if let Some(destination_worktree) = destination_worktree {
+    //         self.expand_entry(destination_worktree, destination, cx);
+    //     }
+    // }
 
     fn index_for_selection(&self, selection: Selection) -> Option<(usize, usize, usize)> {
         let mut entry_index = 0;
@@ -1367,7 +1368,9 @@ impl ProjectPanel {
                 if let (Some(editor), true) = (editor, show_editor) {
                     div().w_full().child(editor.clone())
                 } else {
-                    div().child(Label::new(details.filename.clone()))
+                    div()
+                        .text_color(filename_text_color)
+                        .child(Label::new(details.filename.clone()))
                 }
                 .ml_1(),
             )
@@ -1411,21 +1414,16 @@ impl ProjectPanel {
                     }
                 }
             })
-        // .on_down(MouseButton::Right, move |event, this, cx| {
-        //     this.deploy_context_menu(event.position, entry_id, cx);
-        // })
-        // .on_up(MouseButton::Left, move |_, this, cx| {
-        // if let Some((_, dragged_entry)) = cx
-        //     .global::<DragAndDrop<Workspace>>()
-        //     .currently_dragged::<ProjectEntryId>(cx.window())
-        // {
+            .on_mouse_down(MouseButton::Right, move |this, event, cx| {
+                this.deploy_context_menu(event.position, entry_id, cx);
+            })
+        // .on_drop::<ProjectEntryId>(|this, event, cx| {
         //     this.move_entry(
         //         *dragged_entry,
         //         entry_id,
         //         matches!(details.kind, EntryKind::File(_)),
         //         cx,
         //     );
-        // }
         // })
     }
 }
@@ -1433,10 +1431,7 @@ impl ProjectPanel {
 impl Render for ProjectPanel {
     type Element = Div<Self, StatefulInteractivity<Self>, FocusableKeyDispatch<Self>>;
 
-    fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> Self::Element {
-        let theme = cx.theme();
-        let last_worktree_root_id = self.last_worktree_root_id;
-
+    fn render(&mut self, _cx: &mut gpui::ViewContext<Self>) -> Self::Element {
         let has_worktree = self.visible_entries.len() != 0;
 
         if has_worktree {
@@ -1475,10 +1470,7 @@ impl Render for ProjectPanel {
                         |this: &mut Self, range, cx| {
                             let mut items = SmallVec::new();
                             this.for_each_visible_entry(range, cx, |id, details, cx| {
-                                items.push(this.render_entry(
-                                    id, details, // &mut dragged_entry_destination,
-                                    cx,
-                                ));
+                                items.push(this.render_entry(id, details, cx));
                             });
                             items
                         },