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

#include <command_palette.h>

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)
 
void RecordUsage (const std::string &name)
 
std::vector< CommandEntrySearchCommands (const std::string &query)
 
std::vector< CommandEntryGetRecentCommands (int limit=10)
 
std::vector< CommandEntryGetFrequentCommands (int limit=10)
 
std::vector< CommandEntryGetAllCommands () const
 Get all registered commands.
 
size_t GetCommandCount () const
 Get command count.
 
void Clear ()
 Clear all commands (and forget every registered provider).
 
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 RegisterDungeonRoomCommands (size_t session_id)
 Register dungeon room navigation commands.
 
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.
 

Static Public Member Functions

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

Private Attributes

std::unordered_map< std::string, CommandEntrycommands_
 
std::vector< std::unique_ptr< CommandProvider > > providers_
 
std::string current_provider_id_
 

Detailed Description

Definition at line 63 of file command_palette.h.

Member Function Documentation

◆ AddCommand()

◆ RecordUsage()

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

◆ SearchCommands()

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

Definition at line 174 of file command_palette.cc.

References commands_, and FuzzyScore().

Referenced by yaze::editor::CommandPaletteWidget::Draw().

Here is the call graph for this function:

◆ GetRecentCommands()

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

◆ GetFrequentCommands()

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

◆ GetAllCommands()

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

Get all registered commands.

Returns
Vector of all command entries

Definition at line 319 of file command_palette.cc.

References commands_.

Referenced by yaze::editor::CommandPaletteWidget::Draw(), and yaze::editor::UICoordinator::DrawCommandPalette().

◆ GetCommandCount()

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

Get command count.

Definition at line 86 of file command_palette.h.

References commands_.

◆ Clear()

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

Clear all commands (and forget every registered provider).

Definition at line 38 of file command_palette.cc.

References commands_, current_provider_id_, 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 44 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 72 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 82 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 94 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 107 of file command_palette.cc.

References commands_.

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 392 of file command_palette.cc.

References AddCommand(), yaze::editor::EditorRegistry::GetAllEditorCategories(), and yaze::editor::CommandCategory::kEditor.

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

Here is the call graph for this function:

◆ 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 407 of file command_palette.cc.

References AddCommand(), and yaze::editor::CommandCategory::kLayout.

Here is the call graph for this function:

◆ 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 475 of file command_palette.cc.

References AddCommand(), yaze::project::RecentFilesManager::GetInstance(), yaze::project::RecentFilesManager::GetRecentFiles(), and yaze::editor::CommandCategory::kFile.

Referenced by yaze::editor::RecentFilesCommandsProvider::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 498 of file command_palette.cc.

References AddCommand(), yaze::editor::JumpToRoomRequestEvent::Create(), yaze::editor::ContentRegistry::Context::event_bus(), yaze::zelda3::GetRoomLabel(), and yaze::editor::CommandCategory::kNavigation.

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

Here is the call graph for this function:

◆ RegisterWorkflowCommands()

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

◆ 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 564 of file command_palette.cc.

References AddCommand(), yaze::editor::RecentProjectsModel::entries(), yaze::editor::CommandCategory::kFile, and yaze::editor::CommandCategory::kView.

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 257 of file command_palette.cc.

References commands_, yaze::Json::dump(), LOG_ERROR, LOG_INFO, and yaze::Json::object().

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

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 283 of file command_palette.cc.

References commands_, yaze::Json::contains(), yaze::Json::is_object(), yaze::Json::items(), LOG_ERROR, LOG_INFO, and yaze::Json::parse().

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

Member Data Documentation

◆ commands_

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

◆ 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 222 of file command_palette.h.

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


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