perf: reuse rendered elements across repaints
This commit is contained in:
@@ -75,18 +75,18 @@ impl ExploreView {
|
||||
|
||||
let search_subscription = cx.subscribe(&search, |this, _search, event, cx| {
|
||||
if matches!(event, InputStateEvent::TextChanged) {
|
||||
this.rebuild_rows(cx);
|
||||
this.rebuild_rows(false, cx);
|
||||
}
|
||||
});
|
||||
|
||||
let store_subscription = cx.observe(&store, |this, _store, cx| {
|
||||
this.rebuild_rows(cx);
|
||||
this.rebuild_rows(true, cx);
|
||||
});
|
||||
|
||||
// The root and the stack are still being updated while this view is built.
|
||||
cx.defer(move |cx| {
|
||||
if let Err(error) = weak.update(cx, |this, cx| {
|
||||
this.rebuild_rows(cx);
|
||||
this.rebuild_rows(false, cx);
|
||||
this.watch_stack(cx);
|
||||
}) {
|
||||
log::warn!("failed to set up the explore panel: {error}");
|
||||
@@ -107,7 +107,8 @@ impl ExploreView {
|
||||
}
|
||||
}
|
||||
|
||||
fn rebuild_rows(&mut self, cx: &mut Context<Self>) {
|
||||
/// `anchor` keeps the scroll position while the row count is unchanged.
|
||||
fn rebuild_rows(&mut self, anchor: bool, cx: &mut Context<Self>) {
|
||||
let filter = self.filter;
|
||||
let query = self.search.read(cx).value().to_string();
|
||||
let store = self.store.read(cx);
|
||||
@@ -125,7 +126,11 @@ impl ExploreView {
|
||||
directory.track(owners, cx);
|
||||
});
|
||||
|
||||
self.scroll_handle.reset(self.item_count());
|
||||
let count = self.item_count();
|
||||
if !anchor || count != self.scroll_handle.item_count() {
|
||||
self.scroll_handle.reset(count);
|
||||
}
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
@@ -223,7 +228,7 @@ impl ExploreView {
|
||||
.on_change(move |filter, _, cx| {
|
||||
if let Err(error) = weak.update(cx, |this, cx| {
|
||||
this.filter = filter;
|
||||
this.rebuild_rows(cx);
|
||||
this.rebuild_rows(false, cx);
|
||||
}) {
|
||||
log::warn!("failed to change explore filter: {error}");
|
||||
}
|
||||
|
||||
@@ -33,16 +33,18 @@ pub struct IssueDetailView {
|
||||
impl IssueDetailView {
|
||||
pub fn new(store: Entity<RepoStore>, issue_id: EventId, cx: &mut Context<Self>) -> Self {
|
||||
let comment_input = InputState::builder().multiline().build(cx);
|
||||
let directory = ProfileDirectory::new(cx);
|
||||
let weak = cx.entity().downgrade();
|
||||
|
||||
let subscription = cx.observe(&store, |this, _store, cx| {
|
||||
this.track_participants(cx);
|
||||
cx.notify();
|
||||
});
|
||||
|
||||
let directory = ProfileDirectory::new(cx);
|
||||
let weak = cx.entity().downgrade();
|
||||
cx.defer(move |cx| {
|
||||
log_dropped(weak.update(cx, |this, cx| this.track_participants(cx)));
|
||||
log_dropped(weak.update(cx, |this, cx| {
|
||||
this.track_participants(cx);
|
||||
}));
|
||||
});
|
||||
|
||||
Self {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use std::rc::Rc;
|
||||
|
||||
use gpui::{
|
||||
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
|
||||
SharedString, Styled as _, Subscription, UniformListScrollHandle, WeakEntity, Window, div,
|
||||
@@ -12,18 +13,17 @@ use ui::button::Button;
|
||||
use ui::common::v_flex;
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::layout::root::RootContext as _;
|
||||
use ui::segmented::{Segmented, SegmentedOption};
|
||||
use ui::theme::ActiveTheme as _;
|
||||
use utils::relative_time;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
use self::detail::IssueDetailView;
|
||||
use crate::app::AppRoot;
|
||||
use crate::issues::new_issue::NewIssueDialog;
|
||||
use crate::repo::helpers::short_id;
|
||||
use crate::shared::event_list::{EventHandler, EventList, EventRow, filter_toolbar};
|
||||
use crate::shared::log_dropped;
|
||||
use crate::shared::panels;
|
||||
use crate::shared::{log_dropped, panels};
|
||||
|
||||
pub mod detail;
|
||||
pub(crate) mod helpers;
|
||||
@@ -32,7 +32,6 @@ pub mod new_issue;
|
||||
pub struct IssuesView {
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
store: Entity<RepoStore>,
|
||||
new_issue: Option<Entity<new_issue::NewIssueDialog>>,
|
||||
filter: IssueFilter,
|
||||
visible_issues: Vec<usize>,
|
||||
counts: StatusCounts,
|
||||
@@ -50,18 +49,20 @@ impl IssuesView {
|
||||
store: Entity<RepoStore>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let weak = cx.entity().downgrade();
|
||||
let subscription = cx.observe(&store, |this, _store, cx| {
|
||||
this.rebuild(cx);
|
||||
});
|
||||
let weak = cx.entity().downgrade();
|
||||
|
||||
cx.defer(move |cx| {
|
||||
log_dropped(weak.update(cx, |this, cx| this.rebuild(cx)));
|
||||
log_dropped(weak.update(cx, |this, cx| {
|
||||
this.rebuild(cx);
|
||||
}));
|
||||
});
|
||||
|
||||
Self {
|
||||
workspace,
|
||||
store: store.clone(),
|
||||
new_issue: None,
|
||||
filter: IssueFilter::Open,
|
||||
visible_issues: Vec::new(),
|
||||
counts: StatusCounts::default(),
|
||||
@@ -73,8 +74,8 @@ impl IssuesView {
|
||||
}
|
||||
|
||||
fn open_new_issue(&mut self, cx: &mut Context<Self>) {
|
||||
self.new_issue = Some(new_issue::NewIssueDialog::new(self.store.clone(), cx));
|
||||
cx.notify();
|
||||
let dialog = NewIssueDialog::new(self.store.clone(), cx);
|
||||
cx.open_dialog(dialog);
|
||||
}
|
||||
|
||||
/// Total number of issues across all statuses, for the sidebar label.
|
||||
@@ -230,7 +231,6 @@ impl Render for IssuesView {
|
||||
|
||||
v_flex()
|
||||
.size_full()
|
||||
.when_some(self.new_issue.clone(), |el, view| el.child(view))
|
||||
.child(
|
||||
EventList::new("issues")
|
||||
.toolbar(self.render_header(cx))
|
||||
|
||||
@@ -4,14 +4,14 @@ use std::sync::Arc;
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, Render, SharedString, Styled as _, Subscription, UniformListScrollHandle,
|
||||
WeakEntity, Window, div,
|
||||
ParentElement as _, Render, SharedString, StyleRefinement, Styled as _, Subscription,
|
||||
UniformListScrollHandle, WeakEntity, Window, div,
|
||||
};
|
||||
use metadata::ProfileDirectory;
|
||||
use nostr::prelude::{EventId, Kind, Url};
|
||||
use signed_core::{GitEvent, PullRequest, RepoAddr};
|
||||
use signed_git::{FileCommit, PatchParser};
|
||||
use signed_state::{Backend, Mirrors, RepoStore};
|
||||
use signed_state::{Backend, BackendEvent, Mirrors, RepoStore};
|
||||
use ui::avatar::Avatar;
|
||||
use ui::button::Button;
|
||||
use ui::clipboard::ClipboardButton;
|
||||
@@ -20,15 +20,16 @@ use ui::empty_state::EmptyState;
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::input::InputState;
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::layout::root::RootContext as _;
|
||||
use ui::scroll_area::ScrollArea;
|
||||
use ui::spinner::Spinner;
|
||||
use ui::tabs::{Tab, Tabs};
|
||||
use ui::theme::ActiveTheme as _;
|
||||
use utils::relative_time;
|
||||
|
||||
use super::dialogs;
|
||||
use crate::app::AppRoot;
|
||||
use crate::issues::helpers::{comment_form, comments_section, sidebar_section};
|
||||
use crate::pull_requests::dialogs::update::UpdatePrDialog;
|
||||
use crate::repo::commit_diff::{CommitDiffView, DiffPane};
|
||||
use crate::shared::event_list::commit_list;
|
||||
use crate::shared::log_dropped;
|
||||
@@ -52,7 +53,6 @@ pub struct PullRequestDetailView {
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
store: Entity<RepoStore>,
|
||||
pr_id: EventId,
|
||||
update_dialog: Option<Entity<dialogs::update::UpdatePrDialog>>,
|
||||
comment_input: Entity<InputState>,
|
||||
worktree: Option<PathBuf>,
|
||||
description: SharedString,
|
||||
@@ -67,7 +67,7 @@ pub struct PullRequestDetailView {
|
||||
commit_scroll_handle: UniformListScrollHandle,
|
||||
tasks: Vec<gpui::Task<Result<(), anyhow::Error>>>,
|
||||
directory: Entity<ProfileDirectory>,
|
||||
_subscription: Subscription,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
impl PullRequestDetailView {
|
||||
@@ -78,23 +78,35 @@ impl PullRequestDetailView {
|
||||
_window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let pane = cx.new(DiffPane::new);
|
||||
let comment_input = InputState::builder().multiline().build(cx);
|
||||
let directory = ProfileDirectory::new(cx);
|
||||
|
||||
let pane = cx.new(DiffPane::new);
|
||||
let weak = cx.entity().downgrade();
|
||||
|
||||
let subscription = cx.observe(&store, |this, _store, cx| {
|
||||
let backend = Backend::global(cx);
|
||||
let mut subscriptions = vec![];
|
||||
|
||||
subscriptions.push(cx.observe(&store, |this, _store, cx| {
|
||||
this.sync(cx);
|
||||
});
|
||||
}));
|
||||
|
||||
subscriptions.push(cx.subscribe(&backend, |_, _, event, cx| {
|
||||
if matches!(event, BackendEvent::SignerChanged) {
|
||||
cx.notify();
|
||||
}
|
||||
}));
|
||||
|
||||
cx.defer(move |cx| {
|
||||
log_dropped(weak.update(cx, |this, cx| this.sync(cx)));
|
||||
log_dropped(weak.update(cx, |this, cx| {
|
||||
this.sync(cx);
|
||||
}));
|
||||
});
|
||||
|
||||
Self {
|
||||
workspace,
|
||||
store,
|
||||
pr_id,
|
||||
update_dialog: None,
|
||||
comment_input,
|
||||
worktree: None,
|
||||
description: SharedString::default(),
|
||||
@@ -108,8 +120,8 @@ impl PullRequestDetailView {
|
||||
pane,
|
||||
commit_scroll_handle: UniformListScrollHandle::new(),
|
||||
tasks: Vec::new(),
|
||||
directory: ProfileDirectory::new(cx),
|
||||
_subscription: subscription,
|
||||
directory,
|
||||
_subscriptions: subscriptions,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,10 +457,15 @@ impl PullRequestDetailView {
|
||||
if self.loading {
|
||||
return Spinner::centered("pr-loading");
|
||||
}
|
||||
|
||||
if let Some(error) = self.error.clone() {
|
||||
return EmptyState::centered(error);
|
||||
}
|
||||
self.pane.clone().into_any_element()
|
||||
|
||||
self.pane
|
||||
.clone()
|
||||
.cached(StyleRefinement::default().size_full().min_h_0())
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
fn render_commits(&self, cx: &mut Context<Self>) -> AnyElement {
|
||||
@@ -545,14 +562,11 @@ impl PullRequestDetailView {
|
||||
pr.id == this.pr_id && pr.kind == Kind::GitPullRequest
|
||||
})
|
||||
.cloned();
|
||||
|
||||
if let Some(root) = root {
|
||||
this.update_dialog =
|
||||
Some(dialogs::update::UpdatePrDialog::new(
|
||||
this.store.clone(),
|
||||
root,
|
||||
cx,
|
||||
));
|
||||
cx.notify();
|
||||
let dialog =
|
||||
UpdatePrDialog::new(this.store.clone(), root, cx);
|
||||
cx.open_dialog(dialog);
|
||||
}
|
||||
}));
|
||||
},
|
||||
@@ -597,7 +611,6 @@ impl Render for PullRequestDetailView {
|
||||
.size_full()
|
||||
.min_h_0()
|
||||
.child(self.render_header(cx))
|
||||
.when_some(self.update_dialog.clone(), |el, view| el.child(view))
|
||||
.child(self.render_tabs(cx))
|
||||
.map(|this| match self.active_tab {
|
||||
0 => this.child(self.render_discussion(cx)),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::{SharedString, WeakEntity};
|
||||
use nostr::prelude::PublicKey;
|
||||
@@ -66,27 +67,29 @@ pub fn truncate_label(label: &str) -> SharedString {
|
||||
|
||||
pub fn source_menu_items(
|
||||
view: WeakEntity<NewPullRequestView>,
|
||||
associated: Vec<PathBuf>,
|
||||
associated: Arc<Vec<PathBuf>>,
|
||||
active_path: Option<PathBuf>,
|
||||
candidates: Vec<Announcement>,
|
||||
candidates: Arc<Vec<Announcement>>,
|
||||
user: Option<PublicKey>,
|
||||
active_fork: Option<RepoAddr>,
|
||||
) -> Vec<MenuItem> {
|
||||
let mut items = Vec::new();
|
||||
for path in associated {
|
||||
for (index, path) in associated.iter().enumerate() {
|
||||
let label = path
|
||||
.file_name()
|
||||
.map(|name| name.to_string_lossy().into_owned())
|
||||
.unwrap_or_else(|| path.display().to_string());
|
||||
|
||||
let target = view.clone();
|
||||
let path_for_action = path.clone();
|
||||
let associated = Arc::clone(&associated);
|
||||
|
||||
items.push(
|
||||
MenuItem::new(truncate_label(&label))
|
||||
.checked(active_path.as_ref() == Some(&path))
|
||||
.checked(active_path.as_ref() == Some(path))
|
||||
.handler(move |window, cx| {
|
||||
let path = path_for_action.clone();
|
||||
let Some(path) = associated.get(index).cloned() else {
|
||||
return;
|
||||
};
|
||||
if let Err(error) =
|
||||
target.update(cx, |this, cx| this.apply_folder_path(path, window, cx))
|
||||
{
|
||||
@@ -110,23 +113,25 @@ pub fn source_menu_items(
|
||||
if candidates.is_empty() {
|
||||
items.push(MenuItem::new("No announced forks of this repository").disabled(true));
|
||||
} else {
|
||||
for candidate in candidates {
|
||||
for (index, candidate) in candidates.iter().enumerate() {
|
||||
let subtitle = if Some(candidate.owner) == user {
|
||||
SharedString::from("Your fork")
|
||||
} else {
|
||||
SharedString::from(format!("by {}", shorten_owner(&candidate.owner)))
|
||||
};
|
||||
|
||||
let title = format!("{} — {}", announcement_display_name(&candidate), subtitle);
|
||||
let title = format!("{} — {}", announcement_display_name(candidate), subtitle);
|
||||
let target = view.clone();
|
||||
let candidates = Arc::clone(&candidates);
|
||||
let checked = active_fork == Some(candidate.addr());
|
||||
let announcement = candidate;
|
||||
|
||||
items.push(
|
||||
MenuItem::new(truncate_label(&title))
|
||||
.checked(checked)
|
||||
.handler(move |window, cx| {
|
||||
let announcement = announcement.clone();
|
||||
let Some(announcement) = candidates.get(index).cloned() else {
|
||||
return;
|
||||
};
|
||||
if let Err(error) =
|
||||
target.update(cx, |this, cx| this.choose_fork(announcement, window, cx))
|
||||
{
|
||||
|
||||
@@ -4,13 +4,13 @@ use std::sync::Arc;
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, PathPromptOptions, Render, SharedString, Styled as _,
|
||||
UniformListScrollHandle, WeakEntity, Window, div, px,
|
||||
ParentElement as _, PathPromptOptions, Render, SharedString, StyleRefinement, Styled as _,
|
||||
Subscription, UniformListScrollHandle, WeakEntity, Window, div, px,
|
||||
};
|
||||
use nostr::prelude::Url;
|
||||
use nostr::prelude::{PublicKey, Url};
|
||||
use signed_core::Announcement;
|
||||
use signed_git::{GitCache, Repo};
|
||||
use signed_state::{Backend, CheckoutsStore, Mirrors, RepoListStore, RepoStore};
|
||||
use signed_state::{Backend, BackendEvent, CheckoutsStore, Mirrors, RepoListStore, RepoStore};
|
||||
use ui::button::{Button, ButtonVariant};
|
||||
use ui::combobox::{Combobox, ComboboxState};
|
||||
use ui::common::{StyledExt as _, h_flex, v_flex};
|
||||
@@ -56,6 +56,11 @@ pub struct NewPullRequestView {
|
||||
scroll_handle: UniformListScrollHandle,
|
||||
pub(super) tasks: Vec<gpui::Task<Result<(), anyhow::Error>>>,
|
||||
source_open: bool,
|
||||
/// The checkouts, forks, and user the source menu lists.
|
||||
checkouts: Arc<Vec<PathBuf>>,
|
||||
forks: Arc<Vec<Announcement>>,
|
||||
user: Option<PublicKey>,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
impl NewPullRequestView {
|
||||
@@ -66,12 +71,16 @@ impl NewPullRequestView {
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let pane = cx.new(DiffPane::new);
|
||||
let checkouts = CheckoutsStore::global(cx);
|
||||
let repositories = RepoListStore::global(cx);
|
||||
let backend = Backend::global(cx);
|
||||
|
||||
let weak = cx.entity().downgrade();
|
||||
let subject = InputState::new(cx);
|
||||
let description = InputState::builder().multiline().build(cx);
|
||||
|
||||
let pane = cx.new(DiffPane::new);
|
||||
let weak = cx.entity().downgrade();
|
||||
|
||||
let base_select = cx.new(|cx| {
|
||||
ComboboxState::new(
|
||||
Combobox::new("pr-base", "Base", Vec::new()).on_change({
|
||||
@@ -114,23 +123,42 @@ impl NewPullRequestView {
|
||||
)
|
||||
});
|
||||
|
||||
window.defer(cx, move |window, cx| {
|
||||
log_dropped(weak.update(cx, |this, cx| {
|
||||
let Some(addr) = this.store.read(cx).addr().cloned() else {
|
||||
return;
|
||||
};
|
||||
let mut subscriptions = vec![];
|
||||
|
||||
let Some(path) = CheckoutsStore::global(cx)
|
||||
.read(cx)
|
||||
.associations_of(&addr)
|
||||
.into_iter()
|
||||
.next()
|
||||
else {
|
||||
return;
|
||||
};
|
||||
subscriptions.push(cx.observe(&checkouts, |this, _, cx| {
|
||||
this.refresh_sources(cx);
|
||||
}));
|
||||
|
||||
this.apply_folder_path(path, window, cx);
|
||||
}));
|
||||
subscriptions.push(cx.observe(&repositories, |this, _, cx| {
|
||||
this.refresh_sources(cx);
|
||||
}));
|
||||
|
||||
subscriptions.push(cx.observe(&store, |this, _, cx| {
|
||||
this.refresh_sources(cx);
|
||||
}));
|
||||
|
||||
subscriptions.push(cx.subscribe(&backend, |this, _, event, cx| {
|
||||
if matches!(event, BackendEvent::SignerChanged) {
|
||||
this.refresh_sources(cx);
|
||||
}
|
||||
}));
|
||||
|
||||
cx.defer_in(window, move |this, window, cx| {
|
||||
let Some(addr) = this.store.read(cx).addr().cloned() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let Some(path) = CheckoutsStore::global(cx)
|
||||
.read(cx)
|
||||
.associations_of(&addr)
|
||||
.into_iter()
|
||||
.next()
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
this.apply_folder_path(path, window, cx);
|
||||
this.refresh_sources(cx);
|
||||
});
|
||||
|
||||
Self {
|
||||
@@ -158,6 +186,10 @@ impl NewPullRequestView {
|
||||
scroll_handle: UniformListScrollHandle::new(),
|
||||
tasks: Vec::new(),
|
||||
source_open: false,
|
||||
checkouts: Arc::default(),
|
||||
forks: Arc::default(),
|
||||
user: None,
|
||||
_subscriptions: subscriptions,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,19 +290,17 @@ impl NewPullRequestView {
|
||||
let weak = cx.entity().downgrade();
|
||||
let weak_menu = cx.entity().downgrade();
|
||||
let source_view = cx.entity().downgrade();
|
||||
let associated = self
|
||||
.store
|
||||
.read(cx)
|
||||
.addr()
|
||||
.map(|addr| CheckoutsStore::global(cx).read(cx).associations_of(addr))
|
||||
.unwrap_or_default();
|
||||
let associated = Arc::clone(&self.checkouts);
|
||||
|
||||
let active_path = (self.fork.is_none())
|
||||
.then(|| self.repo_path.clone())
|
||||
.flatten();
|
||||
let candidates = self.fork_candidates(cx);
|
||||
|
||||
let candidates = Arc::clone(&self.forks);
|
||||
let user = signed_state::Backend::global(cx).read(cx).current_user();
|
||||
let active_fork = self.fork.as_ref().map(|fork| fork.announcement.addr());
|
||||
let can_submit = self.submit_enabled(cx);
|
||||
|
||||
let source_label = match &self.fork {
|
||||
Some(fork) => truncate_label(&announcement_display_name(&fork.announcement)),
|
||||
None => self.repo_path.as_ref().map_or_else(
|
||||
@@ -379,14 +409,21 @@ impl NewPullRequestView {
|
||||
if self.loading {
|
||||
return Spinner::centered("new-pr-loading");
|
||||
}
|
||||
|
||||
if !self.has_source() {
|
||||
return EmptyState::centered("Choose a local checkout or an announced fork to compare");
|
||||
}
|
||||
|
||||
if self.commits.is_none() && self.error.is_some() {
|
||||
return EmptyState::centered("Nothing to compare");
|
||||
}
|
||||
|
||||
match self.active_tab {
|
||||
0 => self.pane.clone().into_any_element(),
|
||||
0 => self
|
||||
.pane
|
||||
.clone()
|
||||
.cached(StyleRefinement::default().size_full().min_h_0())
|
||||
.into_any_element(),
|
||||
_ => self.render_commits(cx),
|
||||
}
|
||||
}
|
||||
@@ -575,22 +612,51 @@ impl NewPullRequestView {
|
||||
});
|
||||
}
|
||||
|
||||
pub(super) fn fork_candidates(&self, cx: &App) -> Vec<Announcement> {
|
||||
let Some(addr) = self.store.read(cx).addr().cloned() else {
|
||||
return Vec::new();
|
||||
/// Rebuilds the source menu's checkouts, forks, and user when their inputs changed.
|
||||
fn refresh_sources(&mut self, cx: &mut Context<Self>) {
|
||||
let (addr, euc) = {
|
||||
let store = self.store.read(cx);
|
||||
(
|
||||
store.addr().cloned(),
|
||||
store
|
||||
.announcement
|
||||
.as_ref()
|
||||
.and_then(|announcement| announcement.euc.clone()),
|
||||
)
|
||||
};
|
||||
let euc = self
|
||||
.store
|
||||
.read(cx)
|
||||
.announcement
|
||||
|
||||
let checkouts = CheckoutsStore::global(cx);
|
||||
let repositories = RepoListStore::global(cx);
|
||||
let backend = Backend::global(cx);
|
||||
let user = backend.read(cx).current_user();
|
||||
let checkouts = addr
|
||||
.as_ref()
|
||||
.and_then(|a| a.euc.clone());
|
||||
let user = Backend::global(cx).read(cx).current_user();
|
||||
let announcements = RepoListStore::global(cx).read(cx).announcements.clone();
|
||||
Announcement::forks_in(&announcements, &addr, euc.as_deref(), user)
|
||||
.map_or_else(Vec::new, |addr| checkouts.read(cx).associations_of(addr));
|
||||
|
||||
let forks: Vec<Announcement> = addr.as_ref().map_or_else(Vec::new, |addr| {
|
||||
Announcement::forks_in(
|
||||
&repositories.read(cx).announcements,
|
||||
addr,
|
||||
euc.as_deref(),
|
||||
user,
|
||||
)
|
||||
.into_iter()
|
||||
.cloned()
|
||||
.collect()
|
||||
});
|
||||
|
||||
if self.user == user
|
||||
&& self.checkouts.as_slice() == checkouts.as_slice()
|
||||
&& self.forks.as_slice() == forks.as_slice()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
self.user = user;
|
||||
self.checkouts = Arc::new(checkouts);
|
||||
self.forks = Arc::new(forks);
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub(crate) fn choose_fork(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::collections::HashSet;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
@@ -57,15 +58,15 @@ enum PaneRow {
|
||||
}
|
||||
|
||||
pub struct DiffPane {
|
||||
diff: Option<CommitDiff>,
|
||||
diff: Option<Arc<CommitDiff>>,
|
||||
seeds: Vec<TreeItemSeed>,
|
||||
expanded: HashSet<String>,
|
||||
rows: Vec<TreeItem>,
|
||||
rows: Arc<Vec<TreeItem>>,
|
||||
selected_index: Option<usize>,
|
||||
tree_visible: bool,
|
||||
split: Entity<ResizableState>,
|
||||
expanded_files: HashSet<String>,
|
||||
pane_rows: Vec<PaneRow>,
|
||||
pane_rows: Arc<Vec<PaneRow>>,
|
||||
list: ListState,
|
||||
wrap: bool,
|
||||
downloadable: bool,
|
||||
@@ -74,18 +75,20 @@ pub struct DiffPane {
|
||||
impl DiffPane {
|
||||
pub fn new(cx: &mut Context<Self>) -> Self {
|
||||
let split = ResizableState::new(cx);
|
||||
split.update(cx, |split, cx| split.set_sizes([px(260.)], cx));
|
||||
split.update(cx, |split, cx| {
|
||||
split.set_sizes([px(260.)], cx);
|
||||
});
|
||||
|
||||
Self {
|
||||
diff: None,
|
||||
seeds: Vec::new(),
|
||||
expanded: HashSet::new(),
|
||||
rows: Vec::new(),
|
||||
rows: Arc::default(),
|
||||
selected_index: None,
|
||||
tree_visible: false,
|
||||
split,
|
||||
expanded_files: HashSet::new(),
|
||||
pane_rows: Vec::new(),
|
||||
pane_rows: Arc::default(),
|
||||
list: ListState::new(0, ListAlignment::Top, px(320.)),
|
||||
wrap: false,
|
||||
downloadable: false,
|
||||
@@ -93,7 +96,7 @@ impl DiffPane {
|
||||
}
|
||||
|
||||
pub fn diff(&self) -> Option<&CommitDiff> {
|
||||
self.diff.as_ref()
|
||||
self.diff.as_deref()
|
||||
}
|
||||
|
||||
pub fn set_diff(&mut self, diff: CommitDiff, cx: &mut Context<Self>) {
|
||||
@@ -106,9 +109,9 @@ impl DiffPane {
|
||||
|
||||
self.seeds = TreeItemSeed::from_paths(&paths);
|
||||
self.expanded = TreeItemSeed::collect_expanded(&self.seeds);
|
||||
self.rows = TreeItemSeed::flatten_all(&self.seeds, &self.expanded);
|
||||
self.rows = Arc::new(TreeItemSeed::flatten_all(&self.seeds, &self.expanded));
|
||||
self.selected_index = None;
|
||||
self.diff = Some(diff);
|
||||
self.diff = Some(Arc::new(diff));
|
||||
|
||||
self.expanded_files.clear();
|
||||
self.rebuild_rows();
|
||||
@@ -120,10 +123,10 @@ impl DiffPane {
|
||||
self.diff = None;
|
||||
self.seeds.clear();
|
||||
self.expanded.clear();
|
||||
self.rows.clear();
|
||||
self.rows = Arc::default();
|
||||
self.selected_index = None;
|
||||
self.expanded_files.clear();
|
||||
self.pane_rows.clear();
|
||||
self.pane_rows = Arc::default();
|
||||
self.list = ListState::new(0, ListAlignment::Top, px(320.));
|
||||
cx.notify();
|
||||
}
|
||||
@@ -197,7 +200,7 @@ impl DiffPane {
|
||||
|
||||
fn rebuild_rows(&mut self) {
|
||||
let Some(diff) = self.diff.as_ref() else {
|
||||
self.pane_rows.clear();
|
||||
self.pane_rows = Arc::default();
|
||||
self.list.reset(0);
|
||||
return;
|
||||
};
|
||||
@@ -245,7 +248,7 @@ impl DiffPane {
|
||||
);
|
||||
}
|
||||
|
||||
self.pane_rows = pane_rows;
|
||||
self.pane_rows = Arc::new(pane_rows);
|
||||
self.list.reset(self.pane_rows.len());
|
||||
}
|
||||
|
||||
@@ -253,15 +256,17 @@ impl DiffPane {
|
||||
if !self.expanded.remove(id) {
|
||||
self.expanded.insert(id.to_owned());
|
||||
}
|
||||
self.rows = TreeItemSeed::flatten_all(&self.seeds, &self.expanded);
|
||||
|
||||
self.rows = Arc::new(TreeItemSeed::flatten_all(&self.seeds, &self.expanded));
|
||||
self.selected_index = self
|
||||
.selected_index
|
||||
.and_then(|index| self.rows.get(index).map(|_| index));
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn render_tree_column(&self, cx: &mut Context<Self>) -> AnyElement {
|
||||
let rows = self.rows.clone();
|
||||
let rows = Arc::clone(&self.rows);
|
||||
let selected = self.selected_index;
|
||||
let view = cx.entity().downgrade();
|
||||
let change_view = view.clone();
|
||||
@@ -273,7 +278,7 @@ impl DiffPane {
|
||||
.child(
|
||||
Tree::new("commit-diff-tree")
|
||||
.selected(selected)
|
||||
.items(move |_, _| rows.clone())
|
||||
.items(move |_, _| Arc::clone(&rows))
|
||||
.on_change(move |index, window, cx| {
|
||||
if let Some(index) = index
|
||||
&& let Err(error) = change_view.update(cx, |this, cx| {
|
||||
@@ -419,8 +424,8 @@ impl DiffPane {
|
||||
return EmptyState::centered("No changes");
|
||||
};
|
||||
|
||||
let files = diff.files.clone();
|
||||
let pane_rows = self.pane_rows.clone();
|
||||
let diff = Arc::clone(diff);
|
||||
let pane_rows = Arc::clone(&self.pane_rows);
|
||||
let wrap = self.wrap;
|
||||
let view = cx.entity().downgrade();
|
||||
|
||||
@@ -433,7 +438,7 @@ impl DiffPane {
|
||||
.child(
|
||||
list(self.list.clone(), move |ix, _, cx| {
|
||||
match pane_rows.get(ix) {
|
||||
Some(row) => render_pane_row(row, &files, &view, wrap, cx),
|
||||
Some(row) => render_pane_row(row, &diff.files, &view, wrap, cx),
|
||||
None => div().into_any_element(),
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::{
|
||||
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
|
||||
SharedString, Styled as _, Window, div, px,
|
||||
@@ -14,13 +16,13 @@ use utils::middle_truncate;
|
||||
|
||||
pub struct AboutDialog {
|
||||
handle: DialogHandle,
|
||||
announcement: Announcement,
|
||||
announcement: Arc<Announcement>,
|
||||
directory: Entity<ProfileDirectory>,
|
||||
}
|
||||
|
||||
impl AboutDialog {
|
||||
pub fn new(
|
||||
announcement: Announcement,
|
||||
announcement: Arc<Announcement>,
|
||||
directory: Entity<ProfileDirectory>,
|
||||
cx: &mut App,
|
||||
) -> Entity<Self> {
|
||||
|
||||
@@ -108,8 +108,7 @@ pub fn grasp_servers_field(
|
||||
v_flex().gap_1().children(
|
||||
servers
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(ix, relay)| render_server_row(ix, relay, state.clone(), cx)),
|
||||
.map(|relay| render_server_row(relay, state.clone(), cx)),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
@@ -144,12 +143,7 @@ pub fn grasp_servers_field(
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
fn render_server_row(
|
||||
ix: usize,
|
||||
relay: &RelayUrl,
|
||||
state: Entity<GraspServersState>,
|
||||
cx: &App,
|
||||
) -> AnyElement {
|
||||
fn render_server_row(relay: &RelayUrl, state: Entity<GraspServersState>, cx: &App) -> AnyElement {
|
||||
let relay = relay.clone();
|
||||
h_flex()
|
||||
.w_full()
|
||||
@@ -167,19 +161,14 @@ fn render_server_row(
|
||||
.child(server_host(&relay)),
|
||||
)
|
||||
.child(
|
||||
Button::new(SharedString::from(format!("remove-relay:{ix}")))
|
||||
Button::new(SharedString::from(format!("remove-relay:{relay}")))
|
||||
.icon(Icon::named(IconRole::Close))
|
||||
.variant(ButtonVariant::Ghost)
|
||||
.tooltip(Tooltip::text("Remove"))
|
||||
.on_click(move |_, _, cx| {
|
||||
// A row's index can desync after a prior removal; match by value.
|
||||
state.update(cx, |state, cx| {
|
||||
if let Some(at) =
|
||||
state.grasp_servers.iter().position(|known| known == &relay)
|
||||
{
|
||||
state.grasp_servers.remove(at);
|
||||
cx.notify();
|
||||
}
|
||||
state.grasp_servers.retain(|known| known != &relay);
|
||||
cx.notify();
|
||||
});
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -3,3 +3,118 @@ pub mod create;
|
||||
pub mod grasp_servers;
|
||||
pub mod init;
|
||||
pub mod reset;
|
||||
|
||||
use gpui::{
|
||||
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
|
||||
SharedString, Styled as _, WeakEntity, Window, div,
|
||||
};
|
||||
use ui::button::{Button, ButtonVariant};
|
||||
use ui::dialog::{Dialog, DialogHandle};
|
||||
use ui::theme::ActiveTheme as _;
|
||||
|
||||
use crate::repo::RepoDetailView;
|
||||
use crate::shared::log_dropped;
|
||||
|
||||
/// A sync failed; explains why.
|
||||
pub struct SyncErrorDialog {
|
||||
handle: DialogHandle,
|
||||
message: SharedString,
|
||||
}
|
||||
|
||||
impl SyncErrorDialog {
|
||||
pub fn new(message: SharedString, cx: &mut App) -> Entity<Self> {
|
||||
cx.new(|_| Self {
|
||||
handle: DialogHandle::new(true),
|
||||
message,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for SyncErrorDialog {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let close = self.handle.clone();
|
||||
let message = self.message.clone();
|
||||
|
||||
Dialog::new("sync-error-dialog")
|
||||
.handle(self.handle.clone())
|
||||
.alert(true)
|
||||
.title("Sync failed")
|
||||
.content(move |_, cx| {
|
||||
div()
|
||||
.text_base()
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.child(message.clone())
|
||||
.into_any_element()
|
||||
})
|
||||
.actions(move |_, _| {
|
||||
let close = close.clone();
|
||||
vec![
|
||||
Button::new("close-sync-error")
|
||||
.label("Close")
|
||||
.variant(ButtonVariant::Secondary)
|
||||
.on_click(move |_, _, cx| close.close(cx))
|
||||
.into_any_element(),
|
||||
]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Asks before the repository's events are deleted from Nostr.
|
||||
pub struct DeleteRepositoryDialog {
|
||||
handle: DialogHandle,
|
||||
view: WeakEntity<RepoDetailView>,
|
||||
}
|
||||
|
||||
impl DeleteRepositoryDialog {
|
||||
pub fn new(view: WeakEntity<RepoDetailView>, cx: &mut App) -> Entity<Self> {
|
||||
cx.new(|_| Self {
|
||||
handle: DialogHandle::new(true),
|
||||
view,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for DeleteRepositoryDialog {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
const WARNING: &str = "This removes the repository's announcement, state, and activity from Nostr. This cannot be undone.";
|
||||
|
||||
let cancel_close = self.handle.clone();
|
||||
let confirm_close = self.handle.clone();
|
||||
let view = self.view.clone();
|
||||
|
||||
Dialog::new("delete-repository-dialog")
|
||||
.handle(self.handle.clone())
|
||||
.alert(true)
|
||||
.title("Delete repository")
|
||||
.content(|_, cx| {
|
||||
div()
|
||||
.text_base()
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.child(WARNING)
|
||||
.into_any_element()
|
||||
})
|
||||
.actions(move |_, _| {
|
||||
let cancel_close = cancel_close.clone();
|
||||
let confirm_close = confirm_close.clone();
|
||||
let cancel: AnyElement = Button::new("cancel-delete")
|
||||
.label("Cancel")
|
||||
.variant(ButtonVariant::Secondary)
|
||||
.on_click(move |_, _, cx| cancel_close.close(cx))
|
||||
.into_any_element();
|
||||
|
||||
let delete: AnyElement = Button::new("confirm-delete")
|
||||
.label("Delete")
|
||||
.variant(ButtonVariant::Destructive)
|
||||
.on_click({
|
||||
let view = view.clone();
|
||||
move |_, _, cx| {
|
||||
confirm_close.close(cx);
|
||||
log_dropped(view.update(cx, |this, cx| this.delete_repository(cx)));
|
||||
}
|
||||
})
|
||||
.into_any_element();
|
||||
|
||||
vec![cancel, delete]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Error;
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, App, AppContext as _, Context, Entity, EventEmitter, IntoElement,
|
||||
ParentElement as _, SharedString, Styled as _, Task, WeakEntity, Window, div, px,
|
||||
ParentElement as _, Render, SharedString, StyleRefinement, Styled as _, Task, WeakEntity,
|
||||
Window, div, px,
|
||||
};
|
||||
use signed_git::{FileCommit, Repo, WorktreeSnapshot};
|
||||
use ui::code::CodeViewState;
|
||||
@@ -55,7 +57,7 @@ struct CodeView {
|
||||
pub struct RepoFilesView {
|
||||
seeds: Vec<TreeItemSeed>,
|
||||
expanded: HashSet<String>,
|
||||
rows: Vec<TreeItem>,
|
||||
rows: Arc<Vec<TreeItem>>,
|
||||
selected_index: Option<usize>,
|
||||
worktree: Option<PathBuf>,
|
||||
worktree_paths: Vec<String>,
|
||||
@@ -82,7 +84,7 @@ impl RepoFilesView {
|
||||
Self {
|
||||
seeds: Vec::new(),
|
||||
expanded: HashSet::new(),
|
||||
rows: Vec::new(),
|
||||
rows: Arc::default(),
|
||||
selected_index: None,
|
||||
worktree: None,
|
||||
worktree_paths: Vec::new(),
|
||||
@@ -121,7 +123,7 @@ impl RepoFilesView {
|
||||
}
|
||||
|
||||
fn rebuild_rows(&mut self) {
|
||||
self.rows = TreeItemSeed::flatten_all(&self.seeds, &self.expanded);
|
||||
self.rows = Arc::new(TreeItemSeed::flatten_all(&self.seeds, &self.expanded));
|
||||
self.selected_index = self.selected_file.as_ref().and_then(|path| {
|
||||
self.rows
|
||||
.iter()
|
||||
@@ -253,7 +255,7 @@ impl RepoFilesView {
|
||||
}
|
||||
|
||||
pub fn render_tree(&self, view: WeakEntity<Self>) -> AnyElement {
|
||||
let rows = self.rows.clone();
|
||||
let rows = Arc::clone(&self.rows);
|
||||
let selected = self.selected_index;
|
||||
let change_view = view.clone();
|
||||
let disclosure_view = view;
|
||||
@@ -265,7 +267,7 @@ impl RepoFilesView {
|
||||
.child(
|
||||
Tree::new("repo-tree")
|
||||
.selected(selected)
|
||||
.items(move |_, _| rows.clone())
|
||||
.items(move |_, _| Arc::clone(&rows))
|
||||
.on_change({
|
||||
let view = change_view;
|
||||
move |index, window, cx| {
|
||||
@@ -434,7 +436,11 @@ impl RepoFilesView {
|
||||
.p_4()
|
||||
.size_full()
|
||||
.overflow_hidden()
|
||||
.child(md.state.clone())
|
||||
.child(
|
||||
md.state
|
||||
.clone()
|
||||
.cached(StyleRefinement::default().size_full()),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
@@ -482,7 +488,11 @@ impl RepoFilesView {
|
||||
div()
|
||||
.size_full()
|
||||
.overflow_hidden()
|
||||
.child(code.state.clone())
|
||||
.child(
|
||||
code.state
|
||||
.clone()
|
||||
.cached(StyleRefinement::default().size_full()),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
@@ -726,3 +736,9 @@ impl RepoFilesView {
|
||||
self.push_task(task);
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for RepoFilesView {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
self.render_tree(cx.entity().downgrade())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
use std::collections::HashSet;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Error;
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, PathPromptOptions, Render, SharedString, StatefulInteractiveElement as _,
|
||||
Styled as _, Subscription, SystemNotification, Task, WeakEntity, Window, div, px,
|
||||
StyleRefinement, Styled as _, Subscription, SystemNotification, Task, WeakEntity, Window, div,
|
||||
px,
|
||||
};
|
||||
use metadata::ProfileDirectory;
|
||||
use nostr::prelude::{PublicKey, Url};
|
||||
@@ -22,10 +24,10 @@ use ui::badge::Badge;
|
||||
use ui::button::{Button, ButtonVariant};
|
||||
use ui::clipboard::CopyRow;
|
||||
use ui::common::{Sizable as _, StyledExt as _, h_flex, v_flex};
|
||||
use ui::dialog::Dialog;
|
||||
use ui::dropdown_menu::DropdownMenu;
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::layout::root::RootContext as _;
|
||||
use ui::menu::MenuItem;
|
||||
use ui::popover::Popover;
|
||||
use ui::sidebar::{Sidebar, SidebarEntry};
|
||||
@@ -53,6 +55,8 @@ use utils::relative_time_secs;
|
||||
use crate::app::AppRoot;
|
||||
use crate::issues::IssuesView;
|
||||
use crate::pull_requests::PullRequestsView;
|
||||
use crate::repo::dialogs::DeleteRepositoryDialog;
|
||||
use crate::repo::dialogs::init::InitRepoDialog;
|
||||
use crate::repo::helpers::{short_id, sorted_worktree_paths};
|
||||
use crate::shared::log_dropped;
|
||||
|
||||
@@ -72,12 +76,31 @@ pub enum RefKind {
|
||||
Tag,
|
||||
}
|
||||
|
||||
/// The announcement and clone commands the repository header renders.
|
||||
struct AboutModel {
|
||||
announcement: Arc<Announcement>,
|
||||
git_commands: Arc<Vec<String>>,
|
||||
}
|
||||
|
||||
impl AboutModel {
|
||||
/// Rebuilds the model only when the store's announcement changed.
|
||||
fn sync(header: &mut Option<Self>, store: &Entity<RepoStore>, cx: &App) {
|
||||
let announcement = store.read(cx).announcement.as_ref();
|
||||
if header.as_ref().map(|header| header.announcement.as_ref()) == announcement {
|
||||
return;
|
||||
}
|
||||
*header = announcement.map(|announcement| Self {
|
||||
announcement: Arc::new(announcement.clone()),
|
||||
git_commands: Arc::new(announcement.clone_urls()),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RepoDetailView {
|
||||
pub(super) workspace: WeakEntity<AppRoot>,
|
||||
pub(super) store: Entity<RepoStore>,
|
||||
about: Option<Entity<dialogs::about::AboutDialog>>,
|
||||
init: Option<Entity<dialogs::init::InitRepoDialog>>,
|
||||
reset: Option<Entity<dialogs::reset::ResetRemoteDialog>>,
|
||||
/// The announcement data the header renders, synced from the store.
|
||||
header: Option<AboutModel>,
|
||||
/// A repository opened by address alone starts without an announcement.
|
||||
repo_started: bool,
|
||||
/// The file explorer and preview.
|
||||
@@ -103,8 +126,6 @@ pub struct RepoDetailView {
|
||||
sync_directory: Entity<SyncStatusDirectory>,
|
||||
/// Only a commit sync reports push steps; republish stays silent.
|
||||
sync_progress: bool,
|
||||
/// The push error shown by the modal alert dialog.
|
||||
sync_error: Option<SharedString>,
|
||||
pub(super) repo_menu_open: bool,
|
||||
pub(super) clone_open: bool,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
@@ -199,6 +220,9 @@ impl RepoDetailView {
|
||||
}),
|
||||
];
|
||||
|
||||
let mut header = None;
|
||||
AboutModel::sync(&mut header, &store, cx);
|
||||
|
||||
let store_for_attach = store.clone();
|
||||
window.defer(cx, move |window, cx| {
|
||||
log_dropped(weak.update(cx, |this, cx| {
|
||||
@@ -210,9 +234,7 @@ impl RepoDetailView {
|
||||
Self {
|
||||
workspace,
|
||||
store: store.clone(),
|
||||
about: None,
|
||||
init: None,
|
||||
reset: None,
|
||||
header,
|
||||
repo_started: false,
|
||||
files,
|
||||
history,
|
||||
@@ -228,7 +250,6 @@ impl RepoDetailView {
|
||||
directory: ProfileDirectory::new(cx),
|
||||
sync_directory,
|
||||
sync_progress: false,
|
||||
sync_error: None,
|
||||
repo_menu_open: false,
|
||||
clone_open: false,
|
||||
_subscriptions: subscriptions,
|
||||
@@ -260,6 +281,7 @@ impl RepoDetailView {
|
||||
) {
|
||||
self._subscriptions
|
||||
.push(cx.observe_in(store, window, |this, store, window, cx| {
|
||||
AboutModel::sync(&mut this.header, &store, cx);
|
||||
this.track_profiles(cx);
|
||||
this.track_sync_status(cx);
|
||||
if !this.repo_started && store.read(cx).announcement.is_some() {
|
||||
@@ -827,7 +849,6 @@ impl RepoDetailView {
|
||||
}
|
||||
|
||||
self.error = None;
|
||||
self.sync_error = None;
|
||||
self.sync_progress = true;
|
||||
|
||||
let tag = store
|
||||
@@ -879,7 +900,8 @@ impl RepoDetailView {
|
||||
cx.dismiss_system_notification(tag.as_ref()).detach();
|
||||
}
|
||||
store.update(cx, |store, _| store.last_error = None);
|
||||
this.sync_error = Some(format!("{error:#}").into());
|
||||
let dialog = dialogs::SyncErrorDialog::new(format!("{error:#}").into(), cx);
|
||||
cx.open_dialog(dialog);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -940,13 +962,9 @@ impl RepoDetailView {
|
||||
|
||||
this.update_in(cx, |this, _window, cx| match probe {
|
||||
Ok((deleted, unreachable)) => {
|
||||
this.reset = Some(dialogs::reset::ResetRemoteDialog::new(
|
||||
store,
|
||||
deleted,
|
||||
unreachable,
|
||||
cx,
|
||||
));
|
||||
cx.notify();
|
||||
let dialog =
|
||||
dialogs::reset::ResetRemoteDialog::new(store, deleted, unreachable, cx);
|
||||
cx.open_dialog(dialog);
|
||||
}
|
||||
Err(error) => {
|
||||
this.error = Some(error.to_string().into());
|
||||
@@ -960,7 +978,7 @@ impl RepoDetailView {
|
||||
}
|
||||
|
||||
/// Delete the repository from nostr, announcement, state and activity.
|
||||
fn delete_repository(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
|
||||
fn delete_repository(&mut self, cx: &mut Context<Self>) {
|
||||
let task = self
|
||||
.store
|
||||
.update(cx, |store, cx| store.delete_repository(cx));
|
||||
@@ -974,7 +992,6 @@ impl RepoDetailView {
|
||||
} else {
|
||||
"Cloning repository..."
|
||||
};
|
||||
|
||||
return v_flex()
|
||||
.flex_1()
|
||||
.size_full()
|
||||
@@ -1024,7 +1041,7 @@ impl RepoDetailView {
|
||||
cx.notify();
|
||||
}));
|
||||
})
|
||||
.entries(move |_, cx| {
|
||||
.entries(move |_, _| {
|
||||
let mut entries = vec![
|
||||
SidebarEntry::row("repo-nav-commits", "Commits")
|
||||
.prefix(Icon::named(IconRole::GitCommit))
|
||||
@@ -1053,7 +1070,10 @@ impl RepoDetailView {
|
||||
entries.push(SidebarEntry::header("Files"));
|
||||
|
||||
entries.push(SidebarEntry::custom(
|
||||
files.read(cx).render_tree(files.downgrade()),
|
||||
files
|
||||
.clone()
|
||||
.cached(StyleRefinement::default().flex_1().min_h_0().w_full())
|
||||
.into_any_element(),
|
||||
));
|
||||
|
||||
entries
|
||||
@@ -1078,7 +1098,6 @@ impl RepoDetailView {
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
actions::open_repo_panel(&self.workspace, &addr, None, window, cx);
|
||||
}
|
||||
|
||||
@@ -1087,13 +1106,9 @@ impl RepoDetailView {
|
||||
let Some(local_path) = self.store.read(cx).path.clone() else {
|
||||
return;
|
||||
};
|
||||
self.init = Some(dialogs::init::InitRepoDialog::new(
|
||||
local_path,
|
||||
cx.entity().downgrade(),
|
||||
window,
|
||||
cx,
|
||||
));
|
||||
cx.notify();
|
||||
let view = cx.entity().downgrade();
|
||||
let dialog = InitRepoDialog::new(local_path, view, window, cx);
|
||||
cx.open_dialog(dialog);
|
||||
}
|
||||
|
||||
pub(super) fn render_about(&mut self, cx: &mut Context<Self>) -> AnyElement {
|
||||
@@ -1106,9 +1121,10 @@ impl RepoDetailView {
|
||||
let pushing = store.pushing;
|
||||
let cloning = store.cloning;
|
||||
|
||||
let Some(announcement) = store.announcement.clone() else {
|
||||
let Some(header) = &self.header else {
|
||||
return div().into_any_element();
|
||||
};
|
||||
let announcement = header.announcement.as_ref();
|
||||
|
||||
let nip05 = self
|
||||
.directory
|
||||
@@ -1119,23 +1135,22 @@ impl RepoDetailView {
|
||||
.clone()
|
||||
.filter(|nip05| !nip05.trim().is_empty());
|
||||
|
||||
let nostr_url = nostr_clone_url(&announcement, nip05.as_deref());
|
||||
let nostr_url = nostr_clone_url(announcement, nip05.as_deref());
|
||||
let ngit_command = SharedString::from(format!("git clone {nostr_url}"));
|
||||
let nak_command = SharedString::from(format!("nak git clone {nostr_url}"));
|
||||
let git_commands: Vec<String> = announcement.clone_urls();
|
||||
|
||||
let name = repo_display_name(self.store.read(cx));
|
||||
let description = announcement.description();
|
||||
let avatar = Avatar::new(format!("{}:{}", announcement.owner, announcement.id));
|
||||
|
||||
let announcement_for_menu = announcement.clone();
|
||||
let announcement_for_menu = Arc::clone(&header.announcement);
|
||||
let weak_menu_open = cx.entity().downgrade();
|
||||
let weak_menu_items = cx.entity().downgrade();
|
||||
let weak_clone = cx.entity().downgrade();
|
||||
let weak_download = cx.entity().downgrade();
|
||||
let ngit_for_popover = ngit_command.clone();
|
||||
let nak_for_popover = nak_command.clone();
|
||||
let git_for_popover = git_commands.clone();
|
||||
let git_for_popover = Arc::clone(&header.git_commands);
|
||||
|
||||
h_flex()
|
||||
.p_6()
|
||||
@@ -1170,7 +1185,7 @@ impl RepoDetailView {
|
||||
.line_clamp(3)
|
||||
.child(description),
|
||||
)
|
||||
.when_some(fork_row(&announcement, cx), |this, row| this.child(row)),
|
||||
.when_some(fork_row(announcement, cx), |this, row| this.child(row)),
|
||||
)
|
||||
.child(
|
||||
h_flex()
|
||||
@@ -1280,20 +1295,21 @@ impl RepoDetailView {
|
||||
}
|
||||
})
|
||||
.items(move |_, cx| {
|
||||
let owner = backend.read(cx).current_user()
|
||||
== Some(announcement_for_menu.owner);
|
||||
let current_user = backend.read(cx).current_user();
|
||||
let owner = current_user == Some(announcement_for_menu.owner);
|
||||
|
||||
let mut items = vec![MenuItem::new("About").handler({
|
||||
let weak = weak_menu_items.clone();
|
||||
let announcement = announcement_for_menu.clone();
|
||||
let announcement = Arc::clone(&announcement_for_menu);
|
||||
|
||||
move |_, cx| {
|
||||
if let Err(error) = weak.update(cx, |this, cx| {
|
||||
this.about = Some(dialogs::about::AboutDialog::new(
|
||||
announcement.clone(),
|
||||
let dialog = dialogs::about::AboutDialog::new(
|
||||
Arc::clone(&announcement),
|
||||
this.directory.clone(),
|
||||
cx,
|
||||
));
|
||||
cx.notify();
|
||||
);
|
||||
cx.open_dialog(dialog);
|
||||
}) {
|
||||
log::warn!("failed to open about: {error}");
|
||||
}
|
||||
@@ -1325,11 +1341,14 @@ impl RepoDetailView {
|
||||
items.push(MenuItem::new("Delete").destructive(true).handler(
|
||||
{
|
||||
let weak = weak_menu_items.clone();
|
||||
move |window, cx| {
|
||||
if let Err(error) = weak.update(cx, |this, cx| {
|
||||
this.delete_repository(window, cx);
|
||||
move |_window, cx| {
|
||||
if let Err(error) = weak.update(cx, |_, cx| {
|
||||
let view = cx.entity().downgrade();
|
||||
let dialog =
|
||||
DeleteRepositoryDialog::new(view, cx);
|
||||
cx.open_dialog(dialog);
|
||||
}) {
|
||||
log::warn!("failed to delete: {error}");
|
||||
log::warn!("failed to ask to delete: {error}");
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1553,9 +1572,6 @@ impl Panel for RepoDetailView {
|
||||
|
||||
impl Render for RepoDetailView {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let weak = cx.entity().downgrade();
|
||||
let sync_weak = cx.entity().downgrade();
|
||||
|
||||
let error = self.error.clone().or_else(|| {
|
||||
self.store
|
||||
.read(cx)
|
||||
@@ -1570,6 +1586,7 @@ impl Render for RepoDetailView {
|
||||
.child(self.render_about(cx))
|
||||
.child(self.render_metadata(cx))
|
||||
.when_some(error, |this, error| {
|
||||
let weak = cx.entity().downgrade();
|
||||
this.child(
|
||||
Alert::new("repo-error")
|
||||
.severity(AlertSeverity::Danger)
|
||||
@@ -1605,38 +1622,5 @@ impl Render for RepoDetailView {
|
||||
.child(self.render_pane(cx)),
|
||||
),
|
||||
)
|
||||
.when_some(self.about.clone(), |el, view| el.child(view))
|
||||
.when_some(self.init.clone(), |el, view| el.child(view))
|
||||
.when_some(self.reset.clone(), |el, view| el.child(view))
|
||||
.when_some(self.sync_error.clone(), |el, error| {
|
||||
el.child(
|
||||
Dialog::new("sync-error-dialog")
|
||||
.alert(true)
|
||||
.open(true)
|
||||
.title("Sync failed")
|
||||
.content(move |_, cx| {
|
||||
div()
|
||||
.text_base()
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.child(error.clone())
|
||||
.into_any_element()
|
||||
})
|
||||
.actions(move |_, _| {
|
||||
let sync_weak = sync_weak.clone();
|
||||
vec![
|
||||
Button::new("close-sync-error")
|
||||
.label("Close")
|
||||
.variant(ButtonVariant::Secondary)
|
||||
.on_click(move |_, _, cx| {
|
||||
log_dropped(sync_weak.update(cx, |this, cx| {
|
||||
this.sync_error = None;
|
||||
cx.notify();
|
||||
}));
|
||||
})
|
||||
.into_any_element(),
|
||||
]
|
||||
}),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,25 +141,20 @@ pub fn grasp_servers_editor(input: &Entity<InputState>, cx: &App) -> AnyElement
|
||||
|
||||
v_flex()
|
||||
.gap_2()
|
||||
.children(servers.iter().enumerate().map(|(ix, server)| {
|
||||
.children(servers.iter().map(|server| {
|
||||
let server = server.clone();
|
||||
editor_value_row(
|
||||
format!("settings-remove-server:{ix}"),
|
||||
format!("settings-remove-server:{server}"),
|
||||
display_server(&server),
|
||||
move |cx| {
|
||||
let store = SettingsStore::global(cx);
|
||||
store.update(cx, |store, cx| {
|
||||
store.edit(
|
||||
|settings| {
|
||||
// A row's index can desync after a prior removal; match by value.
|
||||
if let Some(at) = settings
|
||||
settings
|
||||
.grasp_servers
|
||||
.default_servers
|
||||
.iter()
|
||||
.position(|known| known == &server)
|
||||
{
|
||||
settings.grasp_servers.default_servers.remove(at);
|
||||
}
|
||||
.retain(|known| known != &server);
|
||||
},
|
||||
cx,
|
||||
);
|
||||
@@ -233,25 +228,20 @@ pub fn scan_paths_editor(cx: &App) -> AnyElement {
|
||||
|
||||
v_flex()
|
||||
.gap_2()
|
||||
.children(scan_paths.iter().enumerate().map(|(ix, path)| {
|
||||
.children(scan_paths.iter().map(|path| {
|
||||
let path = path.clone();
|
||||
editor_value_row(
|
||||
format!("settings-remove-path:{ix}"),
|
||||
format!("settings-remove-path:{}", path.display()),
|
||||
SharedString::from(path.display().to_string()),
|
||||
move |cx| {
|
||||
let store = SettingsStore::global(cx);
|
||||
store.update(cx, |store, cx| {
|
||||
store.edit(
|
||||
|settings| {
|
||||
// A row's index can desync after a prior removal; match by value.
|
||||
if let Some(at) = settings
|
||||
settings
|
||||
.local_repos
|
||||
.scan_paths
|
||||
.iter()
|
||||
.position(|known| known == &path)
|
||||
{
|
||||
settings.local_repos.scan_paths.remove(at);
|
||||
}
|
||||
.retain(|known| known != &path);
|
||||
},
|
||||
cx,
|
||||
);
|
||||
|
||||
@@ -312,6 +312,9 @@ impl RenderOnce for Dialog {
|
||||
.read(cx)
|
||||
.clone();
|
||||
|
||||
// The panel takes focus when it first paints, and again whenever nothing else holds it.
|
||||
let painted = window.use_keyed_state((self.id.clone(), "dialog-painted"), cx, |_, _| false);
|
||||
|
||||
deferred(
|
||||
root.flex()
|
||||
.items_center()
|
||||
@@ -442,8 +445,11 @@ impl RenderOnce for Dialog {
|
||||
})
|
||||
.child(
|
||||
canvas(|_, _, _| {}, {
|
||||
let painted = painted.clone();
|
||||
move |_, _, window, cx| {
|
||||
if !focus.contains_focused(window, cx) {
|
||||
let first_paint = painted
|
||||
.update(cx, |painted, _| !std::mem::replace(painted, true));
|
||||
if first_paint || window.focused(cx).is_none() {
|
||||
window.focus(&focus, cx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1005,11 +1005,6 @@ impl InputState {
|
||||
/// with the paint-time text style. Reuses the previous result while the
|
||||
/// text, wrap width, and text style are unchanged.
|
||||
fn shape_current_text(&self, wrap_width: Option<Pixels>, window: &Window) -> ShapedText {
|
||||
let (text, mask_map) = if self.masked() {
|
||||
masked_display(&self.text)
|
||||
} else {
|
||||
(self.text.clone(), None)
|
||||
};
|
||||
let text_style = window.text_style();
|
||||
|
||||
let font = Font {
|
||||
@@ -1022,6 +1017,23 @@ impl InputState {
|
||||
|
||||
let font_size = text_style.font_size.to_pixels(window.rem_size());
|
||||
|
||||
if !self.masked()
|
||||
&& let Some((cached_key, shaped)) = self.shaped_cache.borrow().as_ref()
|
||||
&& cached_key.text == self.text
|
||||
&& cached_key.wrap_width == wrap_width
|
||||
&& cached_key.font_size == font_size
|
||||
&& cached_key.font == font
|
||||
&& cached_key.color == text_style.color
|
||||
{
|
||||
return shaped.clone();
|
||||
}
|
||||
|
||||
let (text, mask_map) = if self.masked() {
|
||||
masked_display(&self.text)
|
||||
} else {
|
||||
(self.text.clone(), None)
|
||||
};
|
||||
|
||||
let key = ShapeCacheKey {
|
||||
text: text.clone(),
|
||||
wrap_width,
|
||||
@@ -1030,12 +1042,6 @@ impl InputState {
|
||||
color: text_style.color,
|
||||
};
|
||||
|
||||
if let Some((cached_key, shaped)) = self.shaped_cache.borrow().as_ref()
|
||||
&& *cached_key == key
|
||||
{
|
||||
return shaped.clone();
|
||||
}
|
||||
|
||||
let runs = [TextRun {
|
||||
len: text.len(),
|
||||
font,
|
||||
@@ -2022,6 +2028,13 @@ impl RenderOnce for Input {
|
||||
let padding_x = self.size.padding_x_rems().to_pixels(rem);
|
||||
let dense_padding_x = self.size.dense_padding_x_rems().to_pixels(rem);
|
||||
let focus_handle = self.state.read(cx).focus_handle.clone();
|
||||
let owner = window.current_view();
|
||||
let state = self.state.clone();
|
||||
|
||||
window.use_keyed_state((self.id.clone(), "input-owner"), cx, |_, cx| {
|
||||
// Edits must repaint the view that renders the field, even below a cached view.
|
||||
App::observe(cx, &state, move |_, cx| cx.notify(owner))
|
||||
});
|
||||
let focused = focus_handle.is_focused(window);
|
||||
|
||||
let is_empty = self.state.read(cx).text.is_empty();
|
||||
@@ -2634,35 +2647,3 @@ fn floor_to_char_boundary(text: &str, index: usize) -> usize {
|
||||
}
|
||||
index
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
#[allow(clippy::reversed_empty_ranges)] // The fixture is intentionally reversed.
|
||||
fn utf16_range_to_utf8_orders_reversed_endpoints() {
|
||||
// "héllo": h 0, é 1, l 2, l 3, o 4 in UTF-16 units.
|
||||
let text = "héllo";
|
||||
assert_eq!(utf16_range_to_utf8(text, 4..2), 3..5);
|
||||
assert_eq!(utf16_range_to_utf8(text, 2..4), 3..5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(clippy::reversed_empty_ranges)] // The fixture is intentionally reversed.
|
||||
fn utf8_range_to_utf16_floors_off_boundary_offsets() {
|
||||
let text = "héllo";
|
||||
// Byte 2 sits inside `é`; a reversed, off-boundary range must not panic.
|
||||
let range = utf8_range_to_utf16(text, 4..2);
|
||||
assert!(range.start <= range.end);
|
||||
assert_eq!(range, 1..3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn char_boundary_floor_clamps_to_len() {
|
||||
// "héllo" is six bytes.
|
||||
assert_eq!(floor_to_char_boundary("héllo", 7), 6);
|
||||
assert_eq!(floor_to_char_boundary("héllo", 2), 1);
|
||||
assert_eq!(floor_to_char_boundary("héllo", 0), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -460,7 +460,14 @@ impl Tab {
|
||||
.group_hover(group.clone(), |style| style.visible()),
|
||||
)
|
||||
})
|
||||
.when(!titlebar, |label| label.child(self.label.clone()));
|
||||
.when(!titlebar, |label| {
|
||||
label
|
||||
.min_w_0()
|
||||
.whitespace_nowrap()
|
||||
.overflow_hidden()
|
||||
.text_ellipsis()
|
||||
.child(self.label.clone())
|
||||
});
|
||||
|
||||
let strip_tab = div()
|
||||
.id((self.key.clone(), "tab"))
|
||||
@@ -485,9 +492,9 @@ impl Tab {
|
||||
})
|
||||
})
|
||||
.map(|strip_tab| {
|
||||
apply_tab_chrome(strip_tab, ctx.variant, active, cx).when(titlebar, |strip_tab| {
|
||||
strip_tab.min_w(TAB_MIN_WIDTH).max_w(TAB_MAX_WIDTH)
|
||||
})
|
||||
apply_tab_chrome(strip_tab, ctx.variant, active, cx)
|
||||
.max_w(TAB_MAX_WIDTH)
|
||||
.when(titlebar, |strip_tab| strip_tab.min_w(TAB_MIN_WIDTH))
|
||||
})
|
||||
.when_some(self.lead.take(), |strip_tab, lead| strip_tab.child(lead))
|
||||
.child(label)
|
||||
|
||||
@@ -3,14 +3,16 @@
|
||||
//! # Examples
|
||||
//!
|
||||
//! ```no_run
|
||||
//! use std::sync::Arc;
|
||||
//!
|
||||
//! use ui::tree::{Tree, TreeItem};
|
||||
//!
|
||||
//! let project = Tree::new("project")
|
||||
//! .items(|_, _| {
|
||||
//! vec![
|
||||
//! Arc::new(vec![
|
||||
//! TreeItem::new("src", "src").expandable(true).expanded(true),
|
||||
//! TreeItem::new("main", "main.rs").depth(1),
|
||||
//! ]
|
||||
//! ])
|
||||
//! })
|
||||
//! .on_change(|_selected, _window, _cx| println!("selection changed"));
|
||||
//! ```
|
||||
@@ -18,6 +20,7 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::prelude::FluentBuilder;
|
||||
use gpui::{
|
||||
@@ -37,7 +40,7 @@ type ChangeHandler = Rc<dyn Fn(Option<usize>, &mut Window, &mut App)>;
|
||||
/// The disclosure reporter, fired with the toggled row's index.
|
||||
type DisclosureHandler = Rc<dyn Fn(usize, &mut Window, &mut App)>;
|
||||
/// The visible row builder, run during render.
|
||||
type ItemsFn = Box<dyn Fn(&mut Window, &mut App) -> Vec<TreeItem>>;
|
||||
type ItemsFn = Box<dyn Fn(&mut Window, &mut App) -> Arc<Vec<TreeItem>>>;
|
||||
|
||||
/// The deepest indent the tree paints, bounding misbuilt item trees.
|
||||
const TREE_MAX_DEPTH: usize = 16;
|
||||
@@ -192,6 +195,10 @@ impl TreeItem {
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.whitespace_nowrap()
|
||||
.overflow_hidden()
|
||||
.text_ellipsis()
|
||||
.text_color(label_color)
|
||||
.child(self.label.clone()),
|
||||
)
|
||||
@@ -465,7 +472,7 @@ impl Tree {
|
||||
/// Sets the visible rows; the closure runs during render and must not mutate entities or notify.
|
||||
pub fn items<F>(mut self, items: F) -> Self
|
||||
where
|
||||
F: Fn(&mut Window, &mut App) -> Vec<TreeItem> + 'static,
|
||||
F: Fn(&mut Window, &mut App) -> Arc<Vec<TreeItem>> + 'static,
|
||||
{
|
||||
self.items = Some(Box::new(items));
|
||||
self
|
||||
@@ -546,7 +553,7 @@ impl RenderOnce for Tree {
|
||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let items = match self.items {
|
||||
Some(build) => build(window, cx),
|
||||
None => Vec::new(),
|
||||
None => Arc::default(),
|
||||
};
|
||||
|
||||
let selectable: Vec<usize> = items
|
||||
|
||||
@@ -401,19 +401,16 @@ impl PanelStack {
|
||||
|
||||
/// The main stack's tab strip for the titlebar; `None` while the stack is empty.
|
||||
pub fn main_tabs(stack: Entity<Self>, cx: &App) -> Option<Tabs> {
|
||||
let (id, panels, selected) = {
|
||||
let (id, selected) = {
|
||||
let this = stack.read(cx);
|
||||
if this.main.is_empty() {
|
||||
return None;
|
||||
}
|
||||
(
|
||||
this.id.clone(),
|
||||
this.main.panels.clone(),
|
||||
this.main.selected().unwrap_or(usize::MAX),
|
||||
)
|
||||
(this.id.clone(), this.main.selected().unwrap_or(usize::MAX))
|
||||
};
|
||||
let change = stack.downgrade();
|
||||
let close = change.clone();
|
||||
let tabs = change.clone();
|
||||
|
||||
Some(
|
||||
Tabs::new((id, "main-tabs"))
|
||||
@@ -421,10 +418,15 @@ impl PanelStack {
|
||||
.overflow_scroll(true)
|
||||
.selected(selected)
|
||||
.tabs(move |_, cx| {
|
||||
panels
|
||||
.iter()
|
||||
.map(|(id, panel)| panel.tab(id.clone().into(), cx).closeable(true))
|
||||
.collect()
|
||||
tabs.read_with(cx, |stack, cx| {
|
||||
stack
|
||||
.main
|
||||
.panels
|
||||
.iter()
|
||||
.map(|(id, panel)| panel.tab(id.clone().into(), cx).closeable(true))
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.on_change(move |index, _, cx| {
|
||||
change
|
||||
@@ -539,10 +541,10 @@ impl PanelStack {
|
||||
|
||||
/// The split pane's content: the split stack's tabs over its shown panel.
|
||||
fn split_pane(&self, cx: &mut Context<Self>) -> AnyElement {
|
||||
let panels: Vec<(SharedString, Arc<dyn PanelView>)> = self.split.panels.clone();
|
||||
let selected = self.split.selected().unwrap_or(usize::MAX);
|
||||
let change = cx.weak_entity();
|
||||
let close = change.clone();
|
||||
let tabs = change.clone();
|
||||
|
||||
v_flex()
|
||||
.size_full()
|
||||
@@ -554,10 +556,17 @@ impl PanelStack {
|
||||
.overflow_scroll(true)
|
||||
.selected(selected)
|
||||
.tabs(move |_, cx| {
|
||||
panels
|
||||
.iter()
|
||||
.map(|(id, panel)| panel.tab(id.clone().into(), cx).closeable(true))
|
||||
.collect()
|
||||
tabs.read_with(cx, |stack, cx| {
|
||||
stack
|
||||
.split
|
||||
.panels
|
||||
.iter()
|
||||
.map(|(id, panel)| {
|
||||
panel.tab(id.clone().into(), cx).closeable(true)
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.on_change(move |index, _, cx| {
|
||||
change
|
||||
@@ -574,11 +583,11 @@ impl PanelStack {
|
||||
)
|
||||
})
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_h_0()
|
||||
.w_full()
|
||||
.children(self.split.active().map(|panel| panel.view())),
|
||||
div().flex_1().min_h_0().w_full().children(
|
||||
self.split
|
||||
.active()
|
||||
.map(|panel| panel.view().cached(content_style()).into_any_element()),
|
||||
),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
@@ -504,8 +504,12 @@ pub(crate) fn reapply(cx: &mut App) {
|
||||
let resolved = resolve::resolve(&system, preset.as_ref(), mode_override, custom);
|
||||
|
||||
cx.set_reduce_motion(resolved.accessibility.reduce_motion);
|
||||
cx.set_global(Theme::from_resolved(resolved));
|
||||
cx.refresh_windows();
|
||||
let theme = Theme::from_resolved(resolved);
|
||||
let theme_changed = cx.try_global::<Theme>() != Some(&theme);
|
||||
cx.set_global(theme);
|
||||
if theme_changed {
|
||||
cx.refresh_windows();
|
||||
}
|
||||
}
|
||||
|
||||
/// Forces a variant, independent of the OS. `None` follows the system.
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
//! The panel stack: the main island fills the window; splitting makes two
|
||||
//! half-width islands with a drag divider that resizes them.
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::{
|
||||
@@ -10,6 +12,7 @@ use gpui::{
|
||||
size,
|
||||
};
|
||||
use ui::common::v_flex;
|
||||
use ui::input::{Input, InputState};
|
||||
use ui::layout::panel::{Panel, PanelSlot, PanelStack, PanelView, SplitSide};
|
||||
use ui::tabs::Tabs;
|
||||
use ui::theme::Theme;
|
||||
@@ -69,6 +72,28 @@ impl Render for PanelHarness {
|
||||
}
|
||||
}
|
||||
|
||||
/// A split panel that counts its renders around a field.
|
||||
struct FieldView {
|
||||
input: Entity<InputState>,
|
||||
renders: Rc<Cell<usize>>,
|
||||
}
|
||||
|
||||
impl Render for FieldView {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
self.renders.set(self.renders.get() + 1);
|
||||
div()
|
||||
.debug_selector(|| "panel-test-field".to_string())
|
||||
.size_full()
|
||||
.child(Input::new("split-field", self.input.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for FieldView {
|
||||
fn title(&self, _cx: &App) -> SharedString {
|
||||
"Field".into()
|
||||
}
|
||||
}
|
||||
|
||||
/// A marker view.
|
||||
fn tag(cx: &mut App, selector: &'static str) -> Entity<TagView> {
|
||||
cx.new(|_| TagView::new(selector))
|
||||
@@ -989,3 +1014,49 @@ fn zoom_ends_when_another_split_panel_is_shown(cx: &mut TestAppContext) {
|
||||
"the split is back once another panel is shown"
|
||||
);
|
||||
}
|
||||
|
||||
/// The split panel is cached: it repaints for its own changes, not for other panels'.
|
||||
#[gpui::test]
|
||||
fn a_split_panel_repaints_for_its_own_changes_only(cx: &mut TestAppContext) {
|
||||
let renders = Rc::new(Cell::new(0));
|
||||
let (input, main, field) = cx.update(|cx| {
|
||||
let input = InputState::new(cx);
|
||||
let field = cx.new(|_| FieldView {
|
||||
input: input.clone(),
|
||||
renders: Rc::clone(&renders),
|
||||
});
|
||||
(input, tag(cx, "panel-test-main"), field)
|
||||
});
|
||||
let seeded_main = main.clone();
|
||||
let seeded_field = field.clone();
|
||||
let (mut cx, _stack) = stack_window(cx, move |stack, cx| {
|
||||
stack.insert(PanelSlot::Main, "main", Arc::new(seeded_main), cx);
|
||||
stack.insert(PanelSlot::Split, "split", Arc::new(seeded_field), cx);
|
||||
});
|
||||
let rendered = renders.get();
|
||||
|
||||
cx.update(|window, cx| input.update(cx, |input, cx| input.set_value("hey", window, cx)));
|
||||
cx.run_until_parked();
|
||||
let typed = cx.update(|_, cx| input.read(cx).value().to_string());
|
||||
assert_eq!(typed, "hey");
|
||||
assert!(
|
||||
renders.get() > rendered,
|
||||
"an edit in the split panel repaints it"
|
||||
);
|
||||
|
||||
let rendered = renders.get();
|
||||
cx.update(|_, cx| main.update(cx, |_, cx| cx.notify()));
|
||||
cx.run_until_parked();
|
||||
assert_eq!(
|
||||
renders.get(),
|
||||
rendered,
|
||||
"another panel's change leaves the split panel as it was"
|
||||
);
|
||||
|
||||
cx.update(|_, cx| field.update(cx, |_, cx| cx.notify()));
|
||||
cx.run_until_parked();
|
||||
assert!(
|
||||
renders.get() > rendered,
|
||||
"the split panel's own change repaints it"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user