WIP
This commit is contained in:
parent
580f1a4125
commit
a5044ccbba
2 changed files with 56 additions and 39 deletions
|
@ -13,9 +13,9 @@ pub enum ContextMenuItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ContextMenuItem {
|
impl ContextMenuItem {
|
||||||
pub fn item(label: String, action: impl 'static + Action) -> Self {
|
pub fn item(label: impl ToString, action: impl 'static + Action) -> Self {
|
||||||
Self::Item {
|
Self::Item {
|
||||||
label,
|
label: label.to_string(),
|
||||||
action: Box::new(action),
|
action: Box::new(action),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,10 @@ actions!(
|
||||||
CollapseSelectedEntry,
|
CollapseSelectedEntry,
|
||||||
AddDirectory,
|
AddDirectory,
|
||||||
AddFile,
|
AddFile,
|
||||||
|
Copy,
|
||||||
|
CopyPath,
|
||||||
|
Cut,
|
||||||
|
Paste,
|
||||||
Delete,
|
Delete,
|
||||||
Rename
|
Rename
|
||||||
]
|
]
|
||||||
|
@ -207,27 +211,25 @@ impl ProjectPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deploy_context_menu(&mut self, action: &DeployContextMenu, cx: &mut ViewContext<Self>) {
|
fn deploy_context_menu(&mut self, action: &DeployContextMenu, cx: &mut ViewContext<Self>) {
|
||||||
|
let mut menu_entries = Vec::new();
|
||||||
|
menu_entries.push(ContextMenuItem::item("New File", AddFile));
|
||||||
|
menu_entries.push(ContextMenuItem::item("New Directory", AddDirectory));
|
||||||
if let Some(entry_id) = action.entry_id {
|
if let Some(entry_id) = action.entry_id {
|
||||||
if let Some(worktree_id) = self.project.read(cx).worktree_id_for_entry(entry_id, cx) {
|
if let Some(worktree_id) = self.project.read(cx).worktree_id_for_entry(entry_id, cx) {
|
||||||
self.selection = Some(Selection {
|
self.selection = Some(Selection {
|
||||||
worktree_id,
|
worktree_id,
|
||||||
entry_id,
|
entry_id,
|
||||||
});
|
});
|
||||||
|
menu_entries.push(ContextMenuItem::Separator);
|
||||||
|
menu_entries.push(ContextMenuItem::item("Copy", Copy));
|
||||||
|
menu_entries.push(ContextMenuItem::item("Copy Path", CopyPath));
|
||||||
|
menu_entries.push(ContextMenuItem::item("Cut", Cut));
|
||||||
|
menu_entries.push(ContextMenuItem::item("Rename", Rename));
|
||||||
|
menu_entries.push(ContextMenuItem::item("Delete", Delete));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.context_menu.update(cx, |menu, cx| {
|
self.context_menu.update(cx, |menu, cx| {
|
||||||
menu.show(
|
menu.show(action.position, menu_entries, cx);
|
||||||
action.position,
|
|
||||||
[
|
|
||||||
ContextMenuItem::item("New File".to_string(), AddFile),
|
|
||||||
ContextMenuItem::item("New Directory".to_string(), AddDirectory),
|
|
||||||
ContextMenuItem::Separator,
|
|
||||||
ContextMenuItem::item("Rename".to_string(), Rename),
|
|
||||||
ContextMenuItem::item("Delete".to_string(), Delete),
|
|
||||||
],
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
|
@ -906,38 +908,53 @@ impl View for ProjectPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> gpui::ElementBox {
|
fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> gpui::ElementBox {
|
||||||
|
enum Tag {}
|
||||||
let theme = &cx.global::<Settings>().theme.project_panel;
|
let theme = &cx.global::<Settings>().theme.project_panel;
|
||||||
let mut container_style = theme.container;
|
let mut container_style = theme.container;
|
||||||
let padding = std::mem::take(&mut container_style.padding);
|
let padding = std::mem::take(&mut container_style.padding);
|
||||||
let handle = self.handle.clone();
|
let handle = self.handle.clone();
|
||||||
Stack::new()
|
Stack::new()
|
||||||
.with_child(
|
.with_child(
|
||||||
UniformList::new(
|
MouseEventHandler::new::<Tag, _, _>(0, cx, |_, _| {
|
||||||
self.list.clone(),
|
UniformList::new(
|
||||||
self.visible_entries
|
self.list.clone(),
|
||||||
.iter()
|
self.visible_entries
|
||||||
.map(|(_, worktree_entries)| worktree_entries.len())
|
.iter()
|
||||||
.sum(),
|
.map(|(_, worktree_entries)| worktree_entries.len())
|
||||||
move |range, items, cx| {
|
.sum(),
|
||||||
let theme = cx.global::<Settings>().theme.clone();
|
move |range, items, cx| {
|
||||||
let this = handle.upgrade(cx).unwrap();
|
let theme = cx.global::<Settings>().theme.clone();
|
||||||
this.update(cx.app, |this, cx| {
|
let this = handle.upgrade(cx).unwrap();
|
||||||
this.for_each_visible_entry(range.clone(), cx, |id, details, cx| {
|
this.update(cx.app, |this, cx| {
|
||||||
items.push(Self::render_entry(
|
this.for_each_visible_entry(
|
||||||
id,
|
range.clone(),
|
||||||
details,
|
|
||||||
&this.filename_editor,
|
|
||||||
&theme.project_panel,
|
|
||||||
cx,
|
cx,
|
||||||
));
|
|id, details, cx| {
|
||||||
});
|
items.push(Self::render_entry(
|
||||||
})
|
id,
|
||||||
},
|
details,
|
||||||
)
|
&this.filename_editor,
|
||||||
.with_padding_top(padding.top)
|
&theme.project_panel,
|
||||||
.with_padding_bottom(padding.bottom)
|
cx,
|
||||||
.contained()
|
));
|
||||||
.with_style(container_style)
|
},
|
||||||
|
);
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.with_padding_top(padding.top)
|
||||||
|
.with_padding_bottom(padding.bottom)
|
||||||
|
.contained()
|
||||||
|
.with_style(container_style)
|
||||||
|
.expanded()
|
||||||
|
.boxed()
|
||||||
|
})
|
||||||
|
.on_right_mouse_down(move |position, cx| {
|
||||||
|
cx.dispatch_action(DeployContextMenu {
|
||||||
|
entry_id: None,
|
||||||
|
position,
|
||||||
|
})
|
||||||
|
})
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
)
|
||||||
.with_child(ChildView::new(&self.context_menu).boxed())
|
.with_child(ChildView::new(&self.context_menu).boxed())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue