pub struct CommandSpec {
pub id: SharedString,
pub title: SharedString,
pub icon: IconName,
pub hint: SharedString,
pub group: SharedString,
pub key: Option<SharedString>,
pub args: Option<Value>,
pub read_only: bool,
pub enabled: EnabledFn,
pub checked: Option<CheckedFn>,
pub run: RunFn,
}Expand description
One thing an app can do.
Fields§
§id: SharedStringUnique, dotted by area: file.open, hist.find_cells, pipeline.add_op.
title: SharedStringWhat menus and search show: “Open image…”.
icon: IconNameIts icon, in menus and search.
hint: SharedStringOne line saying what it does (search, tooltips, the agent’s tool description).
group: SharedStringThe group it is listed under in search (“File”, “Process”).
key: Option<SharedString>Its key in GPUI’s notation (secondary-o: Cmd on macOS, Ctrl elsewhere), if any.
args: Option<Value>The JSON Schema of its arguments, when an agent can pass some (CommandSpec::with_args).
read_only: boolWhether it only reads (an agent may run it without asking).
enabled: EnabledFnWhether it can run now, and why not.
checked: Option<CheckedFn>For a toggle: whether it is on.
run: RunFnWhat it does.
Implementations§
Source§impl CommandSpec
impl CommandSpec
Sourcepub fn new(
id: impl Into<SharedString>,
title: impl Into<SharedString>,
icon: IconName,
run: impl Fn(&mut Window, &mut App) + 'static,
) -> Self
pub fn new( id: impl Into<SharedString>, title: impl Into<SharedString>, icon: IconName, run: impl Fn(&mut Window, &mut App) + 'static, ) -> Self
A plain command: no arguments, no result.
Sourcepub fn with_args<A: DeserializeOwned + JsonSchema + 'static>(
id: impl Into<SharedString>,
title: impl Into<SharedString>,
icon: IconName,
run: impl Fn(A, &mut Window, &mut App) -> Result<Value, String> + 'static,
) -> Self
pub fn with_args<A: DeserializeOwned + JsonSchema + 'static>( id: impl Into<SharedString>, title: impl Into<SharedString>, icon: IconName, run: impl Fn(A, &mut Window, &mut App) -> Result<Value, String> + 'static, ) -> Self
A command taking arguments A (their JSON Schema comes from A, and a call whose
arguments do not read as A is refused with the reason) and returning JSON.
Sourcepub fn raw(
id: impl Into<SharedString>,
title: impl Into<SharedString>,
icon: IconName,
args: Option<Value>,
run: RunFn,
) -> Self
pub fn raw( id: impl Into<SharedString>, title: impl Into<SharedString>, icon: IconName, args: Option<Value>, run: RunFn, ) -> Self
A command from its parts: args is its JSON Schema (or None), run gets the raw JSON.
Sourcepub fn hint(self, hint: impl Into<SharedString>) -> Self
pub fn hint(self, hint: impl Into<SharedString>) -> Self
Sets the line saying what it does.
Sourcepub fn group(self, group: impl Into<SharedString>) -> Self
pub fn group(self, group: impl Into<SharedString>) -> Self
Sets the group it is listed under.
Sourcepub fn key(self, key: impl Into<SharedString>) -> Self
pub fn key(self, key: impl Into<SharedString>) -> Self
Sets its key (secondary-o, f3, secondary-shift-s).
Sourcepub fn enabled(
self,
enabled: impl Fn(&App) -> Result<(), String> + 'static,
) -> Self
pub fn enabled( self, enabled: impl Fn(&App) -> Result<(), String> + 'static, ) -> Self
Sets when it can run (Err(why) otherwise).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for CommandSpec
impl !Send for CommandSpec
impl !Sync for CommandSpec
impl !UnwindSafe for CommandSpec
impl Forget for CommandSpec
impl Freeze for CommandSpec
impl Move for CommandSpec
impl Unpin for CommandSpec
impl UnsafeUnpin for CommandSpec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more