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 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.
 

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

Member Function Documentation

◆ AddCommand()

void yaze::editor::CommandPalette::AddCommand ( const std::string & name,
const std::string & category,
const std::string & description,
const std::string & shortcut,
std::function< void()> callback )

◆ 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 176 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 321 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 87 of file command_palette.h.

References commands_.

◆ Clear()

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

Clear all commands (and forget every registered provider).

Definition at line 40 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 46 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 74 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 84 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 96 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 109 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 442 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 457 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 547 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:

◆ 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 570 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 412 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 591 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 636 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 259 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 285 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 234 of file command_palette.h.

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


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