Select the last root when right-clicking below all project panel entries
This commit is contained in:
parent
ea1f6d6e00
commit
4aa19c1a7f
2 changed files with 64 additions and 62 deletions
|
@ -1042,7 +1042,7 @@ impl Project {
|
||||||
pub fn worktrees<'a>(
|
pub fn worktrees<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
cx: &'a AppContext,
|
cx: &'a AppContext,
|
||||||
) -> impl 'a + Iterator<Item = ModelHandle<Worktree>> {
|
) -> impl 'a + DoubleEndedIterator<Item = ModelHandle<Worktree>> {
|
||||||
self.worktrees
|
self.worktrees
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(move |worktree| worktree.upgrade(cx))
|
.filter_map(move |worktree| worktree.upgrade(cx))
|
||||||
|
@ -1051,7 +1051,7 @@ impl Project {
|
||||||
pub fn visible_worktrees<'a>(
|
pub fn visible_worktrees<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
cx: &'a AppContext,
|
cx: &'a AppContext,
|
||||||
) -> impl 'a + Iterator<Item = ModelHandle<Worktree>> {
|
) -> impl 'a + DoubleEndedIterator<Item = ModelHandle<Worktree>> {
|
||||||
self.worktrees.iter().filter_map(|worktree| {
|
self.worktrees.iter().filter_map(|worktree| {
|
||||||
worktree.upgrade(cx).and_then(|worktree| {
|
worktree.upgrade(cx).and_then(|worktree| {
|
||||||
if worktree.read(cx).is_visible() {
|
if worktree.read(cx).is_visible() {
|
||||||
|
|
|
@ -33,6 +33,7 @@ pub struct ProjectPanel {
|
||||||
project: ModelHandle<Project>,
|
project: ModelHandle<Project>,
|
||||||
list: UniformListState,
|
list: UniformListState,
|
||||||
visible_entries: Vec<(WorktreeId, Vec<Entry>)>,
|
visible_entries: Vec<(WorktreeId, Vec<Entry>)>,
|
||||||
|
last_worktree_root_id: Option<ProjectEntryId>,
|
||||||
expanded_dir_ids: HashMap<WorktreeId, Vec<ProjectEntryId>>,
|
expanded_dir_ids: HashMap<WorktreeId, Vec<ProjectEntryId>>,
|
||||||
selection: Option<Selection>,
|
selection: Option<Selection>,
|
||||||
edit_state: Option<EditState>,
|
edit_state: Option<EditState>,
|
||||||
|
@ -93,7 +94,7 @@ pub struct Open {
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct DeployContextMenu {
|
pub struct DeployContextMenu {
|
||||||
pub position: Vector2F,
|
pub position: Vector2F,
|
||||||
pub entry_id: Option<ProjectEntryId>,
|
pub entry_id: ProjectEntryId,
|
||||||
}
|
}
|
||||||
|
|
||||||
actions!(
|
actions!(
|
||||||
|
@ -187,6 +188,7 @@ impl ProjectPanel {
|
||||||
project: project.clone(),
|
project: project.clone(),
|
||||||
list: Default::default(),
|
list: Default::default(),
|
||||||
visible_entries: Default::default(),
|
visible_entries: Default::default(),
|
||||||
|
last_worktree_root_id: Default::default(),
|
||||||
expanded_dir_ids: Default::default(),
|
expanded_dir_ids: Default::default(),
|
||||||
selection: None,
|
selection: None,
|
||||||
edit_state: None,
|
edit_state: None,
|
||||||
|
@ -232,18 +234,24 @@ 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();
|
let project = self.project.read(cx);
|
||||||
|
|
||||||
|
let entry_id = action.entry_id;
|
||||||
|
let worktree_id = if let Some(id) = project.worktree_id_for_entry(entry_id, cx) {
|
||||||
|
id
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(entry_id) = action.entry_id {
|
|
||||||
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,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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 !self.project.read(cx).is_remote() {
|
if !project.is_remote() {
|
||||||
menu_entries.push(ContextMenuItem::item(
|
menu_entries.push(ContextMenuItem::item(
|
||||||
"Add Folder to Project",
|
"Add Folder to Project",
|
||||||
workspace::AddFolderToProject,
|
workspace::AddFolderToProject,
|
||||||
|
@ -272,14 +280,6 @@ impl ProjectPanel {
|
||||||
menu_entries.push(ContextMenuItem::item("Delete", Delete));
|
menu_entries.push(ContextMenuItem::item("Delete", Delete));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
self.selection.take();
|
|
||||||
menu_entries.push(ContextMenuItem::item(
|
|
||||||
"Add Folder to Project",
|
|
||||||
workspace::AddFolderToProject,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
self.context_menu.update(cx, |menu, cx| {
|
self.context_menu.update(cx, |menu, cx| {
|
||||||
menu.show(action.position, menu_entries, cx);
|
menu.show(action.position, menu_entries, cx);
|
||||||
|
@ -779,14 +779,16 @@ impl ProjectPanel {
|
||||||
new_selected_entry: Option<(WorktreeId, ProjectEntryId)>,
|
new_selected_entry: Option<(WorktreeId, ProjectEntryId)>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
let worktrees = self
|
let project = self.project.read(cx);
|
||||||
.project
|
self.last_worktree_root_id = project
|
||||||
.read(cx)
|
.visible_worktrees(cx)
|
||||||
.worktrees(cx)
|
.rev()
|
||||||
.filter(|worktree| worktree.read(cx).is_visible());
|
.next()
|
||||||
self.visible_entries.clear();
|
.and_then(|worktree| worktree.read(cx).root_entry())
|
||||||
|
.map(|entry| entry.id);
|
||||||
|
|
||||||
for worktree in worktrees {
|
self.visible_entries.clear();
|
||||||
|
for worktree in project.visible_worktrees(cx) {
|
||||||
let snapshot = worktree.read(cx).snapshot();
|
let snapshot = worktree.read(cx).snapshot();
|
||||||
let worktree_id = snapshot.id();
|
let worktree_id = snapshot.id();
|
||||||
|
|
||||||
|
@ -818,6 +820,7 @@ impl ProjectPanel {
|
||||||
|
|
||||||
let mut visible_worktree_entries = Vec::new();
|
let mut visible_worktree_entries = Vec::new();
|
||||||
let mut entry_iter = snapshot.entries(true);
|
let mut entry_iter = snapshot.entries(true);
|
||||||
|
|
||||||
while let Some(entry) = entry_iter.entry() {
|
while let Some(entry) = entry_iter.entry() {
|
||||||
visible_worktree_entries.push(entry.clone());
|
visible_worktree_entries.push(entry.clone());
|
||||||
if Some(entry.id) == new_entry_parent_id {
|
if Some(entry.id) == new_entry_parent_id {
|
||||||
|
@ -1062,10 +1065,7 @@ impl ProjectPanel {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on_right_mouse_down(move |position, cx| {
|
.on_right_mouse_down(move |position, cx| {
|
||||||
cx.dispatch_action(DeployContextMenu {
|
cx.dispatch_action(DeployContextMenu { entry_id, position })
|
||||||
entry_id: Some(entry_id),
|
|
||||||
position,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
.boxed()
|
.boxed()
|
||||||
|
@ -1082,6 +1082,7 @@ impl View for ProjectPanel {
|
||||||
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 last_worktree_root_id = self.last_worktree_root_id;
|
||||||
Stack::new()
|
Stack::new()
|
||||||
.with_child(
|
.with_child(
|
||||||
MouseEventHandler::new::<Tag, _, _>(0, cx, |_, cx| {
|
MouseEventHandler::new::<Tag, _, _>(0, cx, |_, cx| {
|
||||||
|
@ -1113,10 +1114,11 @@ impl View for ProjectPanel {
|
||||||
.boxed()
|
.boxed()
|
||||||
})
|
})
|
||||||
.on_right_mouse_down(move |position, cx| {
|
.on_right_mouse_down(move |position, cx| {
|
||||||
cx.dispatch_action(DeployContextMenu {
|
// When deploying the context menu anywhere below the last project entry,
|
||||||
entry_id: None,
|
// act as if the user clicked the root of the last worktree.
|
||||||
position,
|
if let Some(entry_id) = last_worktree_root_id {
|
||||||
})
|
cx.dispatch_action(DeployContextMenu { entry_id, position })
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue