Remove popup code
This commit is contained in:
parent
0725df87cd
commit
50f721ebd4
2 changed files with 10 additions and 42 deletions
|
@ -149,6 +149,7 @@ fn git_panel_context_menu(
|
||||||
StashAll.boxed_clone(),
|
StashAll.boxed_clone(),
|
||||||
)
|
)
|
||||||
.action_disabled_when(!state.has_stash_items, "Stash Pop", StashPop.boxed_clone())
|
.action_disabled_when(!state.has_stash_items, "Stash Pop", StashPop.boxed_clone())
|
||||||
|
.action("View Stash", zed_actions::git::StashEntries.boxed_clone())
|
||||||
.separator()
|
.separator()
|
||||||
.action("Open Diff", project_diff::Diff.boxed_clone())
|
.action("Open Diff", project_diff::Diff.boxed_clone())
|
||||||
.separator()
|
.separator()
|
||||||
|
|
|
@ -7,7 +7,7 @@ use gpui::{
|
||||||
InteractiveElement, IntoElement, Modifiers, ModifiersChangedEvent, ParentElement, Render,
|
InteractiveElement, IntoElement, Modifiers, ModifiersChangedEvent, ParentElement, Render,
|
||||||
SharedString, Styled, Subscription, Task, Window, actions, px, rems,
|
SharedString, Styled, Subscription, Task, Window, actions, px, rems,
|
||||||
};
|
};
|
||||||
use picker::{Picker, PickerDelegate, PickerEditorPosition};
|
use picker::{Picker, PickerDelegate};
|
||||||
use project::git_store::{Repository, RepositoryEvent};
|
use project::git_store::{Repository, RepositoryEvent};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use time::{OffsetDateTime, UtcOffset};
|
use time::{OffsetDateTime, UtcOffset};
|
||||||
|
@ -38,30 +38,11 @@ pub fn open(
|
||||||
cx: &mut Context<Workspace>,
|
cx: &mut Context<Workspace>,
|
||||||
) {
|
) {
|
||||||
let repository = workspace.project().read(cx).active_repository(cx).clone();
|
let repository = workspace.project().read(cx).active_repository(cx).clone();
|
||||||
let style = StashListStyle::Modal;
|
|
||||||
workspace.toggle_modal(window, cx, |window, cx| {
|
workspace.toggle_modal(window, cx, |window, cx| {
|
||||||
StashList::new(repository, style, rems(34.), window, cx)
|
StashList::new(repository, rems(34.), window, cx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn popover(
|
|
||||||
repository: Option<Entity<Repository>>,
|
|
||||||
window: &mut Window,
|
|
||||||
cx: &mut App,
|
|
||||||
) -> Entity<StashList> {
|
|
||||||
cx.new(|cx| {
|
|
||||||
let list = StashList::new(repository, StashListStyle::Popover, rems(20.), window, cx);
|
|
||||||
list.focus_handle(cx).focus(window);
|
|
||||||
list
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
||||||
enum StashListStyle {
|
|
||||||
Modal,
|
|
||||||
Popover,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct StashList {
|
pub struct StashList {
|
||||||
width: Rems,
|
width: Rems,
|
||||||
pub picker: Entity<Picker<StashListDelegate>>,
|
pub picker: Entity<Picker<StashListDelegate>>,
|
||||||
|
@ -72,7 +53,6 @@ pub struct StashList {
|
||||||
impl StashList {
|
impl StashList {
|
||||||
fn new(
|
fn new(
|
||||||
repository: Option<Entity<Repository>>,
|
repository: Option<Entity<Repository>>,
|
||||||
style: StashListStyle,
|
|
||||||
width: Rems,
|
width: Rems,
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
|
@ -80,21 +60,18 @@ impl StashList {
|
||||||
let mut _subscriptions = Vec::new();
|
let mut _subscriptions = Vec::new();
|
||||||
let stash_request = repository
|
let stash_request = repository
|
||||||
.clone()
|
.clone()
|
||||||
.map(|repository| repository.read_with(cx, |repo, _| repo.stash_entries.clone()));
|
.map(|repository| repository.read_with(cx, |repo, _| repo.cached_stash()));
|
||||||
|
|
||||||
if let Some(repo) = repository.clone() {
|
if let Some(repo) = repository.clone() {
|
||||||
_subscriptions.push(
|
_subscriptions.push(
|
||||||
cx.subscribe_in(&repo, window, |this, _, event, window, cx| {
|
cx.subscribe_in(&repo, window, |this, _, event, window, cx| {
|
||||||
if matches!(event, RepositoryEvent::Updated { .. }) {
|
if matches!(event, RepositoryEvent::Updated { .. }) {
|
||||||
let stash_entries = this.picker.read_with(cx, |picker, cx| {
|
let stash_entries = this.picker.read_with(cx, |picker, cx| {
|
||||||
picker.delegate.repo.clone().map(|repo| {
|
picker
|
||||||
repo.read(cx)
|
.delegate
|
||||||
.snapshot()
|
.repo
|
||||||
.stash_entries
|
|
||||||
.entries
|
|
||||||
.to_vec()
|
|
||||||
.clone()
|
.clone()
|
||||||
})
|
.map(|repo| repo.read(cx).cached_stash().entries.to_vec())
|
||||||
});
|
});
|
||||||
this.picker.update(cx, |this, cx| {
|
this.picker.update(cx, |this, cx| {
|
||||||
this.delegate.all_stash_entries = stash_entries;
|
this.delegate.all_stash_entries = stash_entries;
|
||||||
|
@ -121,7 +98,7 @@ impl StashList {
|
||||||
})
|
})
|
||||||
.detach_and_log_err(cx);
|
.detach_and_log_err(cx);
|
||||||
|
|
||||||
let delegate = StashListDelegate::new(repository.clone(), style, width, window, cx);
|
let delegate = StashListDelegate::new(repository.clone(), width, window, cx);
|
||||||
let picker = cx.new(|cx| Picker::uniform_list(delegate, window, cx));
|
let picker = cx.new(|cx| Picker::uniform_list(delegate, window, cx));
|
||||||
let picker_focus_handle = picker.focus_handle(cx);
|
let picker_focus_handle = picker.focus_handle(cx);
|
||||||
picker.update(cx, |picker, _| {
|
picker.update(cx, |picker, _| {
|
||||||
|
@ -195,7 +172,6 @@ pub struct StashListDelegate {
|
||||||
matches: Vec<StashEntryMatch>,
|
matches: Vec<StashEntryMatch>,
|
||||||
all_stash_entries: Option<Vec<StashEntry>>,
|
all_stash_entries: Option<Vec<StashEntry>>,
|
||||||
repo: Option<Entity<Repository>>,
|
repo: Option<Entity<Repository>>,
|
||||||
style: StashListStyle,
|
|
||||||
selected_index: usize,
|
selected_index: usize,
|
||||||
last_query: String,
|
last_query: String,
|
||||||
modifiers: Modifiers,
|
modifiers: Modifiers,
|
||||||
|
@ -207,7 +183,6 @@ pub struct StashListDelegate {
|
||||||
impl StashListDelegate {
|
impl StashListDelegate {
|
||||||
fn new(
|
fn new(
|
||||||
repo: Option<Entity<Repository>>,
|
repo: Option<Entity<Repository>>,
|
||||||
style: StashListStyle,
|
|
||||||
max_width: Rems,
|
max_width: Rems,
|
||||||
_window: &mut Window,
|
_window: &mut Window,
|
||||||
cx: &mut Context<StashList>,
|
cx: &mut Context<StashList>,
|
||||||
|
@ -219,7 +194,6 @@ impl StashListDelegate {
|
||||||
Self {
|
Self {
|
||||||
matches: vec![],
|
matches: vec![],
|
||||||
repo,
|
repo,
|
||||||
style,
|
|
||||||
all_stash_entries: None,
|
all_stash_entries: None,
|
||||||
selected_index: 0,
|
selected_index: 0,
|
||||||
last_query: Default::default(),
|
last_query: Default::default(),
|
||||||
|
@ -288,13 +262,6 @@ impl PickerDelegate for StashListDelegate {
|
||||||
"Select a stash…".into()
|
"Select a stash…".into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn editor_position(&self) -> PickerEditorPosition {
|
|
||||||
match self.style {
|
|
||||||
StashListStyle::Modal => PickerEditorPosition::Start,
|
|
||||||
StashListStyle::Popover => PickerEditorPosition::End,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn match_count(&self) -> usize {
|
fn match_count(&self) -> usize {
|
||||||
self.matches.len()
|
self.matches.len()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue