Fix warnings

This commit is contained in:
Max Brunsfeld 2023-11-14 09:47:48 -08:00
parent b893ac2a02
commit 2c3c238c9d

View file

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