Update nostr-sdk and adapt to new EventBuilder API
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run
This commit is contained in:
@@ -6,6 +6,7 @@ use gpui::{
|
||||
};
|
||||
use gpui_native_kit::avatar::Avatar;
|
||||
use gpui_native_kit::button::{Button, ButtonVariant};
|
||||
use gpui_native_kit::command_palette::{Command, CommandPalette, CommandPaletteState};
|
||||
use gpui_native_kit::common::{Sizable as _, h_flex};
|
||||
use gpui_native_kit::data::tabs::{Tab, Tabs, TabsVariant};
|
||||
use gpui_native_kit::icons::{Icon, IconRole};
|
||||
@@ -28,19 +29,24 @@ mod helpers;
|
||||
pub struct TitlebarView {
|
||||
weak: WeakEntity<Self>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
scanning: bool,
|
||||
/// User's announced repositories.
|
||||
announcements: Arc<Vec<Announcement>>,
|
||||
/// Local repositories found by the scan that are not announced yet.
|
||||
local_repos: Arc<Vec<ResolvedLocalRepo>>,
|
||||
/// Profiles rendered by the titlebar tabs.
|
||||
directory: gpui::Entity<ProfileDirectory>,
|
||||
/// The command palette opened from the titlebar.
|
||||
palette: gpui::Entity<CommandPaletteState>,
|
||||
user_menu_open: bool,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
impl TitlebarView {
|
||||
pub fn new(workspace: WeakEntity<Workspace>, cx: &mut Context<Self>) -> Self {
|
||||
pub fn new(
|
||||
workspace: WeakEntity<Workspace>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let backend = Backend::global(cx);
|
||||
let repos = RepoListStore::global(cx);
|
||||
let local = LocalReposStore::global(cx);
|
||||
@@ -68,25 +74,84 @@ impl TitlebarView {
|
||||
}
|
||||
}));
|
||||
|
||||
let mut this = Self {
|
||||
weak: cx.entity().downgrade(),
|
||||
let palette = Self::new_palette(workspace.clone(), window, cx);
|
||||
|
||||
let entity = cx.entity();
|
||||
|
||||
let this = Self {
|
||||
weak: entity.downgrade(),
|
||||
workspace,
|
||||
scanning: false,
|
||||
announcements: Arc::new(Vec::new()),
|
||||
local_repos: Arc::new(Vec::new()),
|
||||
directory: ProfileDirectory::new(cx),
|
||||
palette,
|
||||
user_menu_open: false,
|
||||
_subscriptions: subscriptions,
|
||||
};
|
||||
this.refresh(cx);
|
||||
|
||||
cx.defer(move |cx| {
|
||||
entity.update(cx, |this, cx| {
|
||||
if this.refresh(cx) {
|
||||
cx.notify();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
this
|
||||
}
|
||||
|
||||
fn new_palette(
|
||||
workspace: WeakEntity<Workspace>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> gpui::Entity<CommandPaletteState> {
|
||||
cx.new(|cx| {
|
||||
let matcher = |query: &str, commands: &[Command]| {
|
||||
let needle = query.to_lowercase();
|
||||
commands
|
||||
.iter()
|
||||
.filter(|command| command.label.to_lowercase().contains(&needle))
|
||||
.cloned()
|
||||
.collect()
|
||||
};
|
||||
|
||||
CommandPaletteState::new(
|
||||
CommandPalette::new("signed-command-palette", Self::palette_commands(), matcher)
|
||||
.on_execute(move |command, window, cx| match command.id.as_ref() {
|
||||
"create-repo" => dialogs::create::open(workspace.clone(), window, cx),
|
||||
"rescan-repos" => {
|
||||
let local_repos = LocalReposStore::global(cx);
|
||||
local_repos.update(cx, |store, cx| store.rescan(cx));
|
||||
}
|
||||
"open-settings" => settings::open(cx),
|
||||
"exit" => identity::helpers::open_exit(cx),
|
||||
_ => {}
|
||||
}),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn palette_commands() -> Vec<Command> {
|
||||
vec![
|
||||
Command::new("create-repo", "Create repository").icon(Icon::named(IconRole::Plus)),
|
||||
Command::new("rescan-repos", "Rescan for local repositories")
|
||||
.icon(Icon::named(IconRole::Refresh)),
|
||||
Command::new("open-settings", "Settings").icon(Icon::named(IconRole::Settings)),
|
||||
Command::new("exit", "Exit"),
|
||||
]
|
||||
}
|
||||
|
||||
pub fn palette(&self) -> gpui::Entity<CommandPaletteState> {
|
||||
self.palette.clone()
|
||||
}
|
||||
|
||||
fn refresh(&mut self, cx: &mut Context<Self>) -> bool {
|
||||
let backend = Backend::global(cx);
|
||||
let user = backend.read(cx).current_user();
|
||||
|
||||
let (announcements, local_repos, scanning) = {
|
||||
let (announcements, local_repos) = {
|
||||
let repo_list = RepoListStore::global(cx).read(cx);
|
||||
|
||||
let announcements = user
|
||||
@@ -98,16 +163,14 @@ impl TitlebarView {
|
||||
let local_repos =
|
||||
LocalReposStore::resolve(&local.repos, &repo_list.announcements, &announcements);
|
||||
|
||||
(announcements, local_repos, local.scanning)
|
||||
(announcements, local_repos)
|
||||
};
|
||||
|
||||
let announcements_changed = *self.announcements != announcements;
|
||||
let local_changed = *self.local_repos != local_repos;
|
||||
let scanning_changed = self.scanning != scanning;
|
||||
|
||||
self.announcements = Arc::new(announcements);
|
||||
self.local_repos = Arc::new(local_repos);
|
||||
self.scanning = scanning;
|
||||
|
||||
let mut profiles: Vec<PublicKey> = user.into_iter().collect();
|
||||
let owners: Vec<PublicKey> = self
|
||||
@@ -128,7 +191,7 @@ impl TitlebarView {
|
||||
directory.track(profiles, cx);
|
||||
});
|
||||
|
||||
announcements_changed || local_changed || scanning_changed
|
||||
announcements_changed || local_changed
|
||||
}
|
||||
|
||||
pub fn render_tabs(&self, cx: &App) -> Option<Tabs> {
|
||||
@@ -348,15 +411,15 @@ impl TitlebarView {
|
||||
h_flex()
|
||||
.gap_1()
|
||||
.child(
|
||||
Button::new("rescan-repos")
|
||||
.icon(Icon::named(IconRole::Loader))
|
||||
Button::new("open-command-palette")
|
||||
.icon(Icon::named(IconRole::Search))
|
||||
.variant(ButtonVariant::Ghost)
|
||||
.loading(self.scanning)
|
||||
.disabled(self.scanning)
|
||||
.tooltip(Tooltip::text("Rescan for local repositories"))
|
||||
.on_click(|_, _, cx| {
|
||||
let local_repos = LocalReposStore::global(cx);
|
||||
local_repos.update(cx, |store, cx| store.rescan(cx));
|
||||
.tooltip(Tooltip::text("Command palette"))
|
||||
.on_click({
|
||||
let palette = self.palette.clone();
|
||||
move |_, window, cx| {
|
||||
palette.update(cx, |palette, cx| palette.toggle(window, cx));
|
||||
}
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
|
||||
Reference in New Issue
Block a user