Re-vendor the native UI kit at 278430d
- Upstream merged core, data, editor, and utils into a single `components` crate: `ui::button`, `ui::tabs`, `ui::code`, `ui::tree`, `ui::sidebar` are flat, and `h_flex`/`v_flex`/`StyledExt` live in `ui::common` and `ui::layout`. - Adopts the new wrapper-less component module tree, the merged theme/icon updates, and the relocated editor grammars. - Titlebar repo tabs use the new `TabsVariant::Titlebar` capsule sizing. - Doc examples now import from `ui::`, so all 44 doctests compile; the clipboard sample no longer names the kit crate. - docs/ui-gaps.md records that `ui` has no dock/view-registry API instead of the deleted `DockState`.
This commit is contained in:
@@ -1,7 +1,33 @@
|
||||
//! The command palette: a modal query field over the application's actions.
|
||||
//! Renders a modal query field over the application's actions.
|
||||
//!
|
||||
//! The state is the view: [`CommandPaletteState`] owns the query field and
|
||||
//! the matches, and the owner renders the entity itself. Opening resets the
|
||||
//! query, typing asks the caller's matcher for fresh matches, the arrow keys
|
||||
//! move a highlight, and Enter runs the highlighted command through
|
||||
//! [`CommandPalette::on_execute`].
|
||||
//!
|
||||
//! # Examples
|
||||
//!
|
||||
//! ```no_run
|
||||
//! use gpui::prelude::*;
|
||||
//! use gpui::{App, Entity, Window};
|
||||
//! use ui::command_palette::{Command, CommandPalette, CommandPaletteState};
|
||||
//!
|
||||
//! # fn build(window: &mut Window, cx: &mut App) -> Entity<CommandPaletteState> {
|
||||
//! # let commands = vec![Command::new("save", "Save file").hint("Cmd+S")];
|
||||
//! let palette = CommandPalette::new("palette", commands, |query, all| {
|
||||
//! all.iter().filter(|command| command.label.contains(query)).cloned().collect()
|
||||
//! })
|
||||
//! .on_execute(|command, _window, _cx| println!("run {}", command.id));
|
||||
//! let state = cx.new(|cx| CommandPaletteState::new(palette, window, cx));
|
||||
//! # state
|
||||
//! # }
|
||||
//! ```
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::icons::Icon;
|
||||
use crate::theme::{ActiveTheme as _, POPUP_MAX_HEIGHT, Size};
|
||||
use gpui::prelude::FluentBuilder;
|
||||
use gpui::{
|
||||
AnyElement, App, Context, ElementId, Entity, InteractiveElement as _, IntoElement, KeyBinding,
|
||||
@@ -13,8 +39,6 @@ use gpui::{
|
||||
use crate::components::common::{DIALOG_LAYER, StyledExt as _, h_flex, v_flex};
|
||||
use crate::components::input::{Input, InputState, InputStateEvent};
|
||||
use crate::components::scroll_area::{ScrollArea, ScrollAxes};
|
||||
use crate::icons::Icon;
|
||||
use crate::theme::{ActiveTheme as _, POPUP_MAX_HEIGHT, Size};
|
||||
|
||||
actions!(
|
||||
command_palette,
|
||||
@@ -95,7 +119,7 @@ pub type CommandMatcher = Rc<dyn Fn(&str, &[Command]) -> Vec<Command>>;
|
||||
/// Runs the chosen command.
|
||||
pub type CommandHandler = Rc<dyn Fn(&Command, &mut Window, &mut App)>;
|
||||
|
||||
/// Builder for a command palette. Pass it to [`CommandPaletteState::new`].
|
||||
/// Builder for a command palette, consumed by [`CommandPaletteState::new`].
|
||||
#[must_use]
|
||||
pub struct CommandPalette {
|
||||
id: ElementId,
|
||||
@@ -108,7 +132,7 @@ pub struct CommandPalette {
|
||||
}
|
||||
|
||||
impl CommandPalette {
|
||||
/// Creates the builder, the caller-owned matcher decides what matches.
|
||||
/// Creates the builder with a caller-owned matcher that decides what matches.
|
||||
pub fn new<I, M>(id: I, commands: Vec<Command>, matcher: M) -> Self
|
||||
where
|
||||
I: Into<ElementId>,
|
||||
@@ -157,6 +181,22 @@ impl CommandPalette {
|
||||
impl FluentBuilder for CommandPalette {}
|
||||
|
||||
/// The stateful palette.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use gpui::prelude::*;
|
||||
/// # use gpui::{App, Entity, Window};
|
||||
/// # use ui::command_palette::{Command, CommandPalette, CommandPaletteState};
|
||||
/// #
|
||||
/// # fn build(window: &mut Window, cx: &mut App) -> Entity<CommandPaletteState> {
|
||||
/// # let palette = CommandPalette::new("palette", Vec::new(), |_, all| all.to_vec());
|
||||
/// # let state = cx.new(|cx| CommandPaletteState::new(palette, window, cx));
|
||||
/// state.update(cx, |state, cx| state.toggle(window, cx));
|
||||
/// assert!(state.read(cx).is_open());
|
||||
/// # state
|
||||
/// # }
|
||||
/// ```
|
||||
pub struct CommandPaletteState {
|
||||
id: ElementId,
|
||||
name: SharedString,
|
||||
|
||||
Reference in New Issue
Block a user