1#ifndef YAZE_APP_EDITOR_SYSTEM_COMMAND_PALETTE_H_
2#define YAZE_APP_EDITOR_SYSTEM_COMMAND_PALETTE_H_
9#include <unordered_map>
16class WorkspaceWindowManager;
18class RecentProjectsModel;
40 static constexpr const char*
kPanel =
"Panels";
41 static constexpr const char*
kEditor =
"Editor";
42 static constexpr const char*
kLayout =
"Layout";
43 static constexpr const char*
kFile =
"File";
44 static constexpr const char*
kEdit =
"Edit";
45 static constexpr const char*
kView =
"View";
47 static constexpr const char*
kTools =
"Tools";
48 static constexpr const char*
kWorkflow =
"Workflow";
49 static constexpr const char*
kHelp =
"Help";
50 static constexpr const char*
kDrawer =
"Drawers";
78 void AddCommand(
const std::string& name,
const std::string& category,
79 const std::string& description,
const std::string& shortcut,
80 std::function<
void()> callback);
90 std::vector<CommandEntry>
SearchCommands(
const std::string& query);
91 std::vector<CommandMatch>
Search(
const std::string& query,
92 int64_t now_ms)
const;
93 std::vector<CommandMatch>
Search(
const std::string& query)
const;
164 std::function<
void(
const std::string&)> switch_callback);
171 std::function<
void(
const std::string&)> apply_callback);
181 std::function<
void(
const std::string&)> open_callback);
206 std::function<
void(
int drawer_type)> toggle_callback,
207 std::function<
void()> cycle_next = {},
208 std::function<void()> cycle_prev = {});
240 const RecentProjectsModel* model,
241 const std::vector<std::string>& template_names,
242 std::function<
void(
const std::string&)> remove_callback,
243 std::function<
void(
const std::string&)> toggle_pin_callback,
244 std::function<
void()> undo_remove_callback,
245 std::function<
void()> clear_recents_callback,
246 std::function<
void(
const std::string&)> create_from_template_callback,
247 std::function<
void()> dismiss_welcome_callback,
248 std::function<
void()> show_welcome_callback);
263 static int FuzzyScore(
const std::string& text,
const std::string& query);
270 static int ScoreText(std::string_view text, std::string_view query);
275 static int ScoreEntry(
const CommandEntry& entry, std::string_view query,
292 static int64_t
NowMs();
305 std::unordered_map<std::string, CommandEntry>
commands_;
307 std::unordered_map<std::string, UsageStats>
usage_;
std::vector< CommandEntry > SearchCommands(const std::string &query)
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 RegisterDungeonRoomCommands(size_t session_id)
Register dungeon room navigation commands.
void RegisterOverworldMapCommands(size_t session_id)
Register overworld map navigation commands (0x00-0x9F).
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.
std::string CanonicalCommandName(const std::string &name) const
void Clear()
Clear all commands (and forget every registered provider). Usage history is kept so refreshing provid...
void RegisterLayoutCommands(std::function< void(const std::string &)> apply_callback)
Register layout preset commands.
void AddCommand(const std::string &name, const std::string &category, const std::string &description, const std::string &shortcut, std::function< void()> callback)
size_t GetCommandCount() const
Get command count.
void LoadHistory(const std::string &filepath)
Load command usage history from disk.
void UnregisterProvider(const std::string &provider_id)
void RegisterPanelCommands(WorkspaceWindowManager *window_manager, size_t session_id)
Register all window toggle commands from WorkspaceWindowManager.
void RemoveProviderCommands(const std::string &provider_id)
std::vector< CommandEntry > GetAllCommands() const
Get all registered commands (raw, not deduplicated)
static std::string NormalizeCommandName(std::string_view name)
std::unordered_map< std::string, CommandEntry > commands_
void RegisterProvider(std::unique_ptr< CommandProvider > provider)
void RegisterWorkflowCommands(WorkspaceWindowManager *window_manager, size_t session_id)
Register hack workflow commands from workflow-aware panels/actions.
void RegisterEditorCommands(std::function< void(const std::string &)> switch_callback)
Register all editor switch commands.
static int ScoreEntry(const CommandEntry &entry, std::string_view query, int64_t now_ms)
static int ScoreText(std::string_view text, std::string_view query)
std::vector< CommandEntry > GetRecentCommands(int limit=10)
std::vector< CommandEntry > GetVisibleCommands() const
bool RecordUsage(const std::string &name)
void RefreshProviders()
Remove-and-re-run every registered provider.
static bool IsInternalCommandId(std::string_view name)
std::string current_provider_id_
std::vector< std::unique_ptr< CommandProvider > > providers_
void RegisterRecentFilesCommands(std::function< void(const std::string &)> open_callback)
Register commands to open recent files.
std::vector< CommandMatch > Search(const std::string &query, int64_t now_ms) const
std::unordered_map< std::string, UsageStats > usage_
Usage keyed by command name; survives Clear() and provider refreshes.
std::vector< CommandEntry > GetFrequentCommands(int limit=10)
static int FuzzyScore(const std::string &text, const std::string &query)
Legacy name for ScoreText (kept for the Window Finder).
void RefreshProvider(const std::string &provider_id)
uint64_t generation() const
Plug-in command source for the palette.
virtual std::string ProviderId() const =0
Stable identifier. Used for selective refresh; must be unique.
virtual ~CommandProvider()=default
virtual void Provide(CommandPalette *palette)=0
Populate palette with this source's commands.
Central registry for all editor cards with session awareness and dependency injection.
Categories for command palette entries.
static constexpr const char * kDrawer
static constexpr const char * kTools
static constexpr const char * kLayout
static constexpr const char * kWorkflow
static constexpr const char * kFile
static constexpr const char * kView
static constexpr const char * kEditor
static constexpr const char * kHelp
static constexpr const char * kEdit
static constexpr const char * kPanel
static constexpr const char * kNavigation
std::function< void()> callback
A search hit: the (deduplicated) entry plus the score it matched with.