Merge pull request #1388 from zed-industries/mouse-region-refactor

Mouse Region Refactor
This commit is contained in:
Keith Simmons 2022-07-19 16:50:12 -07:00 committed by GitHub
commit c2868a39e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 728 additions and 440 deletions

View file

@ -11,8 +11,9 @@ use gpui::{
geometry::vector::Vector2F,
impl_internal_actions, keymap,
platform::CursorStyle,
AppContext, ClipboardItem, Element, ElementBox, Entity, ModelHandle, MutableAppContext,
PromptLevel, RenderContext, Task, View, ViewContext, ViewHandle,
AppContext, ClipboardItem, Element, ElementBox, Entity, ModelHandle, MouseButton,
MouseButtonEvent, MutableAppContext, PromptLevel, RenderContext, Task, View, ViewContext,
ViewHandle,
};
use menu::{Confirm, SelectNext, SelectPrev};
use project::{Entry, EntryKind, Project, ProjectEntryId, ProjectPath, Worktree, WorktreeId};
@ -1068,19 +1069,25 @@ impl ProjectPanel {
.with_padding_left(padding)
.boxed()
})
.on_click(move |_, click_count, cx| {
if kind == EntryKind::Dir {
cx.dispatch_action(ToggleExpanded(entry_id))
} else {
cx.dispatch_action(Open {
entry_id,
change_focus: click_count > 1,
})
}
})
.on_right_mouse_down(move |position, cx| {
cx.dispatch_action(DeployContextMenu { entry_id, position })
})
.on_click(
MouseButton::Left,
move |MouseButtonEvent { click_count, .. }, cx| {
if kind == EntryKind::Dir {
cx.dispatch_action(ToggleExpanded(entry_id))
} else {
cx.dispatch_action(Open {
entry_id,
change_focus: click_count > 1,
})
}
},
)
.on_mouse_down(
MouseButton::Right,
move |MouseButtonEvent { position, .. }, cx| {
cx.dispatch_action(DeployContextMenu { entry_id, position })
},
)
.with_cursor_style(CursorStyle::PointingHand)
.boxed()
}
@ -1127,13 +1134,16 @@ impl View for ProjectPanel {
.expanded()
.boxed()
})
.on_right_mouse_down(move |position, cx| {
// When deploying the context menu anywhere below the last project entry,
// act as if the user clicked the root of the last worktree.
if let Some(entry_id) = last_worktree_root_id {
cx.dispatch_action(DeployContextMenu { entry_id, position })
}
})
.on_mouse_down(
MouseButton::Right,
move |MouseButtonEvent { position, .. }, cx| {
// When deploying the context menu anywhere below the last project entry,
// act as if the user clicked the root of the last worktree.
if let Some(entry_id) = last_worktree_root_id {
cx.dispatch_action(DeployContextMenu { entry_id, position })
}
},
)
.boxed(),
)
.with_child(ChildView::new(&self.context_menu).boxed())