CommandPalette
Namespace: Wisej.Web
Assembly: Wisej.Framework (4.2.0.0)
Provides a searchable command popup without occupying space on a page.
- C#
- VB.NET
public class CommandPalette : Component
Public Class CommandPalette
Inherits Component
The component registers its shortcut while alive; dispose it with the owning page or container. QueryChanged supplies synchronous server results. Selection closes the popup before CommandExecuted. Registered commands and recent history are scoped to this component and this session.
Example:
var palette = new CommandPalette(components);
palette.Commands.Add(new PaletteCommand { Text = "Open orders", Category = "Navigation", Tag = "orders" });
palette.CommandExecuted += (s, e) => NavigateTo((string)e.Command.Tag);
palette.Show();
Constructors
CommandPalette()
Creates a palette with Ctrl+K and local filtering.
CommandPalette(container)
Creates a palette owned by a component container.
| Name | Type | Description |
|---|---|---|
| container | IContainer | The lifetime owner. |
Properties
CloseAccessibleText
String: Gets or sets the localized override for the "Close command palette" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
Commands
CommandCollection: Gets the observable commands available to local filtering and the default server filter.
CommandsText
String: Gets or sets the localized override for the "Commands" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
Enabled
Boolean: Gets or sets whether opening and execution are enabled. Disabling closes an open palette. (Default: True)
EscapeText
String: Gets or sets the localized override for the "ESC" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
FilterMode
CommandFilterMode: Gets or sets whether filtering uses the browser or QueryChanged results on the server. (Default: Client)
IsOpen
Boolean: Gets whether the palette is currently open.
KeyboardHelpText
String: Gets or sets the localized override for the "↑↓ navigate Enter run Tab category Esc close" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
MaxRecent
Int32: Gets or sets the maximum retained recent executions, from zero to one hundred. (Default: 5)
MinimumCharactersText
String: Gets or sets the localized override for the "Type at least {0} characters" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation. {0} is the minimum character count. Used for the CLDR other category of the current UI culture. Literal braces can be written as {{ and }}.
MinimumCharacterText
String: Gets or sets the localized override for the "Type at least {0} character" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation. {0} is the minimum character count. Used for the CLDR one category of the current UI culture. Literal braces can be written as {{ and }}.
MinQueryLength
Int32: Gets or sets the minimum trimmed query length, from zero to 1024. Shorter queries display a prompt. (Default: 0)
NoMatchingCommandsText
String: Gets or sets the localized override for the "No matching commands" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
PaletteAccessibleText
String: Gets or sets the localized override for the "Command palette" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
PlaceholderText
String: Gets or sets the prompt displayed in the empty search field. (Default: null)
Null uses the built-in text for the current UI culture. An empty string suppresses the text.
RecentText
String: Gets or sets the localized override for the "Recent" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
SearchAccessibleText
String: Gets or sets the localized override for the "Search commands" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
SearchingText
String: Gets or sets the localized override for the "Searching…" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
Shortcut
Keys: Gets or sets the global opening shortcut. None unregisters it; Show remains available. (Default: K, Control)
ShowRecent
Boolean: Gets or sets whether recent executions appear first for an empty query. (Default: True)
Width
Int32: Gets or sets the desired popup width in pixels, from 240 to 1600. The browser viewport caps the actual width. (Default: 560)
Methods
Dispose(disposing)
Releases commands, recent records, and the client popup and shortcut.
| Parameter | Type | Description |
|---|---|---|
| disposing | Boolean | Whether managed resources are being released. |
Hide()
Closes the popup and raises Closed once; hiding an already closed palette has no effect.
OnClosed(e)
Raises Closed.
| Parameter | Type | Description |
|---|---|---|
| e | EventArgs | Event data. |
OnCommandExecuted(e)
Raises CommandExecuted.
| Parameter | Type | Description |
|---|---|---|
| e | CommandEventArgs | Executed command. |
OnOpened(e)
Raises Opened, including derived overrides without subscribers.
| Parameter | Type | Description |
|---|---|---|
| e | EventArgs | Event data. |
OnQueryChanged(e)
Raises QueryChanged.
| Parameter | Type | Description |
|---|---|---|
| e | CommandQueryEventArgs | Query and optional results. |
OnWebEvent(e)
Dispatches browser requests to validated processing methods.
| Parameter | Type | Description |
|---|---|---|
| e | WisejEventArgs | Client event data. |
OnWebRender(config)
Serializes only public command data and wires events independently of subscribers.
| Parameter | Type | Description |
|---|---|---|
| config | Object | The client component configuration. |
Show()
Opens the palette with an empty query.
Show(query)
Opens or refreshes the palette with a query. Null becomes empty; queries are limited to 1024 characters.
| Parameter | Type | Description |
|---|---|---|
| query | String | Initial search text. |
Calling Show while open replaces the query without raising Opened again. A fresh search epoch invalidates responses and execution requests from earlier openings.
Events
Closed
EventHandler Occurs once when the palette closes, before any execution event.
CommandExecuted
EventHandler<CommandEventArgs> Occurs after an enabled result is activated and the popup is closed.
Opened
EventHandler Occurs once when a closed palette is shown.
QueryChanged
EventHandler<CommandQueryEventArgs> Occurs on Show and accepted query changes. Set Results for server filtering.
Populate Results synchronously. Queries below MinQueryLength do not raise this event. Null Results uses the registered commands; an empty sequence displays no matches.
Example:
palette.FilterMode = CommandFilterMode.Server;
palette.QueryChanged += (s, e) => e.Results = SearchRecords(e.Query);
Implements
| Name | Description |
|---|---|
| IUserData | Provides access to the UserData and Tag properties associated to the component implementing this interface. |
| IWisejComponent | All wisej components implement this interface. |
| IWisejSerializable | Allows an object to serialize itself. |