yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::editor::CommandPalette Class Reference

#include <command_palette.h>

Classes

struct  UsageStats
 

Public Member Functions

void AddCommand (const std::string &name, const std::string &category, const std::string &description, const std::string &shortcut, std::function< void()> callback)
 
bool RecordUsage (const std::string &name)
 
std::vector< CommandEntry > SearchCommands (const std::string &query)
 
std::vector< CommandMatch > Search (const std::string &query, int64_t now_ms) const
 
std::vector< CommandMatch > Search (const std::string &query) const
 
std::vector< CommandEntry > GetRecentCommands (int limit=10)
 
std::vector< CommandEntry > GetFrequentCommands (int limit=10)
 
std::vector< CommandEntry > GetAllCommands () const
 Get all registered commands (raw, not deduplicated)
 
std::vector< CommandEntry > GetVisibleCommands () const
 
size_t GetCommandCount () const
 Get command count.
 
void Clear ()
 Clear all commands (and forget every registered provider). Usage history is kept so refreshing providers does not reset frecency.
 
void RegisterProvider (std::unique_ptr< CommandProvider > provider)
 
void UnregisterProvider (const std::string &provider_id)
 
void RefreshProvider (const std::string &provider_id)
 
void RefreshProviders ()
 Remove-and-re-run every registered provider.
 
void RemoveProviderCommands (const std::string &provider_id)
 
void RegisterPanelCommands (WorkspaceWindowManager *window_manager, size_t session_id)
 Register all window toggle commands from WorkspaceWindowManager.
 
void RegisterEditorCommands (std::function< void(const std::string &)> switch_callback)
 Register all editor switch commands.
 
void RegisterLayoutCommands (std::function< void(const std::string &)> apply_callback)
 Register layout preset commands.
 
void RegisterRecentFilesCommands (std::function< void(const std::string &)> open_callback)
 Register commands to open recent files.
 
void RegisterOverworldMapCommands (size_t session_id)
 Register overworld map navigation commands (0x00-0x9F).
 
void RegisterDungeonRoomCommands (size_t session_id)
 Register dungeon room navigation commands.
 
void RegisterDrawerCommands (std::function< void(int drawer_type)> toggle_callback, std::function< void()> cycle_next={}, std::function< void()> cycle_prev={})
 Register right-drawer toggle commands from GetDrawerCatalog().
 
void RegisterWorkflowCommands (WorkspaceWindowManager *window_manager, size_t session_id)
 Register hack workflow commands from workflow-aware panels/actions.
 
void RegisterWelcomeCommands (const RecentProjectsModel *model, const std::vector< std::string > &template_names, std::function< void(const std::string &)> remove_callback, std::function< void(const std::string &)> toggle_pin_callback, std::function< void()> undo_remove_callback, std::function< void()> clear_recents_callback, std::function< void(const std::string &)> create_from_template_callback, std::function< void()> dismiss_welcome_callback, std::function< void()> show_welcome_callback)
 Expose welcome-screen actions through the command palette.
 
void SaveHistory (const std::string &filepath)
 Save command usage history to disk.
 
void LoadHistory (const std::string &filepath)
 Load command usage history from disk.
 
std::string CanonicalCommandName (const std::string &name) const
 
uint64_t generation () const
 

Static Public Member Functions

static int FuzzyScore (const std::string &text, const std::string &query)
 Legacy name for ScoreText (kept for the Window Finder).
 
static int ScoreText (std::string_view text, std::string_view query)
 
static int ScoreEntry (const CommandEntry &entry, std::string_view query, int64_t now_ms)
 
static std::string NormalizeCommandName (std::string_view name)
 
static bool IsInternalCommandId (std::string_view name)
 
static int64_t NowMs ()
 

Private Attributes

uint64_t generation_ = 0
 
std::unordered_map< std::string, CommandEntry > commands_
 
std::unordered_map< std::string, UsageStats > usage_
 Usage keyed by command name; survives Clear() and provider refreshes.
 
std::vector< std::unique_ptr< CommandProvider > > providers_
 
std::string current_provider_id_
 

Detailed Description

Definition at line 76 of file command_palette.h.

Member Function Documentation

◆ AddCommand()

◆ RecordUsage()

bool yaze::editor::CommandPalette::RecordUsage ( const std::string & name)

Record one execution of name. Only names the palette knows (after dedupe, see CanonicalCommandName) are counted; returns false otherwise. Usage survives Clear()/provider refreshes.

Definition at line 285 of file command_palette.cc.

References CanonicalCommandName(), commands_, generation_, NormalizeCommandName(), NowMs(), and usage_.

Referenced by yaze::editor::UICoordinator::ExecutePaletteCommand().

Here is the call graph for this function:

◆ SearchCommands()

std::vector< CommandEntry > yaze::editor::CommandPalette::SearchCommands ( const std::string & query)

Ranked, deduplicated search. An empty query lists every visible command (recently used first, then by name). Recency/frequency only boosts entries that already match the query.

Definition at line 519 of file command_palette.cc.

References Search().

Here is the call graph for this function:

◆ Search() [1/2]

std::vector< CommandMatch > yaze::editor::CommandPalette::Search ( const std::string & query,
int64_t now_ms ) const

Definition at line 491 of file command_palette.cc.

References GetVisibleCommands(), and ScoreEntry().

Referenced by yaze::editor::UICoordinator::DrawCommandPalette(), Search(), and SearchCommands().

Here is the call graph for this function:

◆ Search() [2/2]

std::vector< CommandMatch > yaze::editor::CommandPalette::Search ( const std::string & query) const

Definition at line 514 of file command_palette.cc.

References NowMs(), and Search().

Here is the call graph for this function:

◆ GetRecentCommands()

std::vector< CommandEntry > yaze::editor::CommandPalette::GetRecentCommands ( int limit = 10)

Definition at line 528 of file command_palette.cc.

References GetVisibleCommands().

Referenced by yaze::editor::UICoordinator::DrawCommandPalette().

Here is the call graph for this function:

◆ GetFrequentCommands()

std::vector< CommandEntry > yaze::editor::CommandPalette::GetFrequentCommands ( int limit = 10)

Definition at line 543 of file command_palette.cc.

References GetVisibleCommands().

Referenced by yaze::editor::UICoordinator::DrawCommandPalette().

Here is the call graph for this function:

◆ GetAllCommands()

std::vector< CommandEntry > yaze::editor::CommandPalette::GetAllCommands ( ) const

Get all registered commands (raw, not deduplicated)

Returns
Vector of all command entries

Definition at line 626 of file command_palette.cc.

References commands_.

◆ GetVisibleCommands()

std::vector< CommandEntry > yaze::editor::CommandPalette::GetVisibleCommands ( ) const

Commands after hiding duplicates (see NormalizeCommandName). Each group is represented by one entry that inherits the first non-empty shortcut and the group's best usage stats. Sorted by name.

Definition at line 395 of file command_palette.cc.

References yaze::editor::CommandEntry::callback, commands_, IsInternalCommandId(), yaze::editor::CommandEntry::last_used_ms, NormalizeCommandName(), yaze::editor::CommandEntry::shortcut, and yaze::editor::CommandEntry::usage_count.

Referenced by CanonicalCommandName(), GetFrequentCommands(), GetRecentCommands(), and Search().

Here is the call graph for this function:

◆ GetCommandCount()

size_t yaze::editor::CommandPalette::GetCommandCount ( ) const
inline

Get command count.

Definition at line 113 of file command_palette.h.

References commands_.

◆ Clear()

void yaze::editor::CommandPalette::Clear ( )

Clear all commands (and forget every registered provider). Usage history is kept so refreshing providers does not reset frecency.

Definition at line 202 of file command_palette.cc.

References commands_, current_provider_id_, generation_, and providers_.

Referenced by yaze::editor::UICoordinator::InitializeCommandPalette().

◆ RegisterProvider()

void yaze::editor::CommandPalette::RegisterProvider ( std::unique_ptr< CommandProvider > provider)

Register provider and run it once. Entries added during Provide() are attributed to the provider's id. The provider stays registered so it can be re-run via RefreshProvider / RefreshProviders. A duplicate id replaces the prior registration (the old provider's commands are dropped first).

Definition at line 209 of file command_palette.cc.

References current_provider_id_, LOG_WARN, yaze::editor::CommandProvider::Provide(), providers_, and RemoveProviderCommands().

Referenced by yaze::editor::UICoordinator::InitializeCommandPalette().

Here is the call graph for this function:

◆ UnregisterProvider()

void yaze::editor::CommandPalette::UnregisterProvider ( const std::string & provider_id)

Remove every command attributed to provider_id and drop the provider. No-op if the id is unknown.

Definition at line 237 of file command_palette.cc.

References providers_, and RemoveProviderCommands().

Here is the call graph for this function:

◆ RefreshProvider()

void yaze::editor::CommandPalette::RefreshProvider ( const std::string & provider_id)

Remove-and-re-run a single provider. Useful after its underlying data changed (e.g., recent-files list). No-op if the id is unknown.

Definition at line 247 of file command_palette.cc.

References current_provider_id_, providers_, and RemoveProviderCommands().

Referenced by RefreshProviders().

Here is the call graph for this function:

◆ RefreshProviders()

void yaze::editor::CommandPalette::RefreshProviders ( )

Remove-and-re-run every registered provider.

Definition at line 259 of file command_palette.cc.

References providers_, and RefreshProvider().

Here is the call graph for this function:

◆ RemoveProviderCommands()

void yaze::editor::CommandPalette::RemoveProviderCommands ( const std::string & provider_id)

Remove every command with the given provider attribution. Leaves the provider itself registered so RefreshProvider can repopulate later.

Definition at line 272 of file command_palette.cc.

References commands_, and generation_.

Referenced by RefreshProvider(), RegisterProvider(), and UnregisterProvider().

◆ RegisterPanelCommands()

void yaze::editor::CommandPalette::RegisterPanelCommands ( WorkspaceWindowManager * window_manager,
size_t session_id )

◆ RegisterEditorCommands()

void yaze::editor::CommandPalette::RegisterEditorCommands ( std::function< void(const std::string &)> switch_callback)

Register all editor switch commands.

Parameters
switch_callbackCallback to switch to an editor category

Definition at line 747 of file command_palette.cc.

Referenced by yaze::editor::EditorCommandsProvider::Provide().

◆ RegisterLayoutCommands()

void yaze::editor::CommandPalette::RegisterLayoutCommands ( std::function< void(const std::string &)> apply_callback)

Register layout preset commands.

Parameters
apply_callbackCallback to apply a layout preset by name

Definition at line 762 of file command_palette.cc.

Referenced by yaze::editor::LayoutCommandsProvider::Provide().

◆ RegisterRecentFilesCommands()

void yaze::editor::CommandPalette::RegisterRecentFilesCommands ( std::function< void(const std::string &)> open_callback)

Register commands to open recent files.

Parameters
open_callbackCallback to open a file by path

Creates "Open Recent: <filename>" commands for each file in RecentFilesManager. Files are checked for existence before registration.

Definition at line 852 of file command_palette.cc.

References yaze::project::RecentFilesManager::GetInstance(), and yaze::project::RecentFilesManager::GetRecentFiles().

Referenced by yaze::editor::RecentFilesCommandsProvider::Provide().

Here is the call graph for this function:

◆ RegisterOverworldMapCommands()

void yaze::editor::CommandPalette::RegisterOverworldMapCommands ( size_t session_id)

Register overworld map navigation commands (0x00-0x9F).

Commands publish JumpToMapRequestEvent; names carry the resource label when one exists.

Definition at line 875 of file command_palette.cc.

References yaze::zelda3::GetOverworldMapLabel(), and yaze::zelda3::kNumOverworldMaps.

Referenced by yaze::editor::OverworldMapCommandsProvider::Provide().

Here is the call graph for this function:

◆ RegisterDungeonRoomCommands()

void yaze::editor::CommandPalette::RegisterDungeonRoomCommands ( size_t session_id)

Register dungeon room navigation commands.

Adds one command per room ID (0x000-0x127) using the ResourceLabelProvider label (when available). Commands publish JumpToRoomRequestEvent.

Definition at line 893 of file command_palette.cc.

References yaze::zelda3::GetRoomLabel().

Referenced by yaze::editor::DungeonRoomCommandsProvider::Provide().

Here is the call graph for this function:

◆ RegisterDrawerCommands()

void yaze::editor::CommandPalette::RegisterDrawerCommands ( std::function< void(int drawer_type)> toggle_callback,
std::function< void()> cycle_next = {},
std::function< void()> cycle_prev = {} )

Register right-drawer toggle commands from GetDrawerCatalog().

Names use a "drawer: " prefix so palette search (drawer:) groups them.

Parameters
toggle_callbackReceives RightDrawerManager::DrawerType as int.

Definition at line 717 of file command_palette.cc.

References yaze::editor::GetDrawerCatalog().

Referenced by yaze::editor::DrawerCommandsProvider::Provide().

Here is the call graph for this function:

◆ RegisterWorkflowCommands()

void yaze::editor::CommandPalette::RegisterWorkflowCommands ( WorkspaceWindowManager * window_manager,
size_t session_id )

Register hack workflow commands from workflow-aware panels/actions.

Definition at line 914 of file command_palette.cc.

References yaze::editor::WorkspaceWindowManager::GetAllCategories(), and yaze::editor::WorkspaceWindowManager::GetWindowsInCategory().

Referenced by yaze::editor::WorkflowCommandsProvider::Provide().

Here is the call graph for this function:

◆ RegisterWelcomeCommands()

void yaze::editor::CommandPalette::RegisterWelcomeCommands ( const RecentProjectsModel * model,
const std::vector< std::string > & template_names,
std::function< void(const std::string &)> remove_callback,
std::function< void(const std::string &)> toggle_pin_callback,
std::function< void()> undo_remove_callback,
std::function< void()> clear_recents_callback,
std::function< void(const std::string &)> create_from_template_callback,
std::function< void()> dismiss_welcome_callback,
std::function< void()> show_welcome_callback )

Expose welcome-screen actions through the command palette.

Registers commands that surface recent-project mutations (remove, pin, undo, clear), template-based project creation, and welcome-screen visibility toggles. This lets power users drive the welcome screen entirely from the palette without opening it.

The RecentProjectsModel pointer may be null; in that case the per-entry remove/pin commands are skipped but the global commands still register.

Parameters
modelSource of recent-project entries (not owned, may be null).
template_namesDisplay names of project templates to register "Create from Template: <name>" commands for. If empty, the template commands are skipped.
remove_callbackInvoked with the filepath to remove from recents.
toggle_pin_callbackInvoked with the filepath to flip pin state.
undo_remove_callbackInvoked to restore the last-removed entry.
clear_recents_callbackInvoked to clear all recents.
create_from_template_callbackInvoked with the template display name to kick off the "new project" flow for that template.
dismiss_welcome_callbackInvoked to hide the welcome screen.
show_welcome_callbackInvoked to bring the welcome screen back.

Definition at line 959 of file command_palette.cc.

References yaze::editor::RecentProjectsModel::entries().

Referenced by yaze::editor::WelcomeCommandsProvider::Provide().

Here is the call graph for this function:

◆ SaveHistory()

void yaze::editor::CommandPalette::SaveHistory ( const std::string & filepath)

Save command usage history to disk.

Parameters
filepathPath to save JSON history file

Definition at line 558 of file command_palette.cc.

References yaze::Json::dump(), LOG_DEBUG, LOG_ERROR, yaze::Json::object(), and usage_.

Referenced by yaze::editor::UICoordinator::SaveCommandPaletteHistory().

Here is the call graph for this function:

◆ LoadHistory()

void yaze::editor::CommandPalette::LoadHistory ( const std::string & filepath)

Load command usage history from disk.

Parameters
filepathPath to load JSON history file from

Definition at line 584 of file command_palette.cc.

References commands_, yaze::Json::contains(), yaze::editor::CommandPalette::UsageStats::count, generation_, yaze::Json::is_object(), yaze::Json::items(), yaze::editor::CommandPalette::UsageStats::last_used_ms, LOG_ERROR, LOG_INFO, yaze::Json::parse(), and usage_.

Referenced by yaze::editor::UICoordinator::InitializeCommandPalette().

Here is the call graph for this function:

◆ FuzzyScore()

int yaze::editor::CommandPalette::FuzzyScore ( const std::string & text,
const std::string & query )
static

Legacy name for ScoreText (kept for the Window Finder).

Definition at line 309 of file command_palette.cc.

References ScoreText().

Referenced by yaze::editor::UICoordinator::DrawPanelFinder().

Here is the call graph for this function:

◆ ScoreText()

int yaze::editor::CommandPalette::ScoreText ( std::string_view text,
std::string_view query )
static

Unified scorer, case-insensitive. 0 = no match. Tiers (high to low): exact > prefix > substring at a word start > substring elsewhere > in-order subsequence. Subsequence matches earn a word-start bonus that outweighs the consecutive-character bonus, and always stay below every substring tier. Queries with spaces also match when every token matches.

Definition at line 314 of file command_palette.cc.

Referenced by FuzzyScore(), and ScoreEntry().

◆ ScoreEntry()

int yaze::editor::CommandPalette::ScoreEntry ( const CommandEntry & entry,
std::string_view query,
int64_t now_ms )
static

Score one entry: name first, then category/description at reduced weight, then a frecency boost that is only applied when the text matched. Returns 0 when nothing matched.

Definition at line 338 of file command_palette.cc.

References yaze::editor::CommandEntry::category, yaze::editor::CommandEntry::description, yaze::editor::CommandEntry::last_used_ms, yaze::editor::CommandEntry::name, ScoreText(), and yaze::editor::CommandEntry::usage_count.

Referenced by Search().

Here is the call graph for this function:

◆ NormalizeCommandName()

std::string yaze::editor::CommandPalette::NormalizeCommandName ( std::string_view name)
static

Lowercase, strip punctuation and "(Alt)" suffixes, collapse spaces, and treat the word "panel(s)" as "window(s)". "Switch to: Overworld Editor" and "Switch to Overworld Editor" share a key, as do "Panel Browser" and "Window Browser", so only one of each is listed (Window names win).

Definition at line 349 of file command_palette.cc.

Referenced by CanonicalCommandName(), GetVisibleCommands(), and RecordUsage().

◆ IsInternalCommandId()

bool yaze::editor::CommandPalette::IsInternalCommandId ( std::string_view name)
static

True for dotted/underscored ids such as "switch.3" or "graphics.tool.pencil" that are keybinding ids, not user-facing names.

Definition at line 383 of file command_palette.cc.

Referenced by GetVisibleCommands(), and yaze::editor::PaletteNameForShortcut().

◆ CanonicalCommandName()

std::string yaze::editor::CommandPalette::CanonicalCommandName ( const std::string & name) const

Name of the entry that represents name after dedupe, or empty when the palette has no such command.

Definition at line 479 of file command_palette.cc.

References GetVisibleCommands(), and NormalizeCommandName().

Referenced by RecordUsage().

Here is the call graph for this function:

◆ NowMs()

int64_t yaze::editor::CommandPalette::NowMs ( )
static

Definition at line 176 of file command_palette.cc.

Referenced by RecordUsage(), and Search().

◆ generation()

uint64_t yaze::editor::CommandPalette::generation ( ) const
inline

Bumped on every mutation (commands, providers, usage). Lets callers cache Search() results per query across frames.

Definition at line 296 of file command_palette.h.

References generation_.

Referenced by yaze::editor::UICoordinator::DrawCommandPalette().

Member Data Documentation

◆ generation_

uint64_t yaze::editor::CommandPalette::generation_ = 0
private

◆ commands_

std::unordered_map<std::string, CommandEntry> yaze::editor::CommandPalette::commands_
private

◆ usage_

std::unordered_map<std::string, UsageStats> yaze::editor::CommandPalette::usage_
private

Usage keyed by command name; survives Clear() and provider refreshes.

Definition at line 307 of file command_palette.h.

Referenced by AddCommand(), LoadHistory(), RecordUsage(), and SaveHistory().

◆ providers_

std::vector<std::unique_ptr<CommandProvider> > yaze::editor::CommandPalette::providers_
private

◆ current_provider_id_

std::string yaze::editor::CommandPalette::current_provider_id_
private

Set while a provider's Provide() call is on the stack; stamped into every CommandEntry added during that call. Empty outside Provide().

Definition at line 311 of file command_palette.h.

Referenced by AddCommand(), Clear(), RefreshProvider(), and RegisterProvider().


The documentation for this class was generated from the following files: