yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
command_palette.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_SYSTEM_COMMAND_PALETTE_H_
2#define YAZE_APP_EDITOR_SYSTEM_COMMAND_PALETTE_H_
3
4#include <functional>
5#include <memory>
6#include <string>
7#include <unordered_map>
8#include <vector>
9
10namespace yaze {
11namespace editor {
12
13class CommandPalette;
14class WorkspaceWindowManager;
15class EditorRegistry;
16class RecentProjectsModel;
17
26 public:
27 virtual ~CommandProvider() = default;
29 virtual std::string ProviderId() const = 0;
31 virtual void Provide(CommandPalette* palette) = 0;
32};
33
38 static constexpr const char* kPanel = "Panels";
39 static constexpr const char* kEditor = "Editor";
40 static constexpr const char* kLayout = "Layout";
41 static constexpr const char* kFile = "File";
42 static constexpr const char* kEdit = "Edit";
43 static constexpr const char* kView = "View";
44 static constexpr const char* kNavigation = "Navigation";
45 static constexpr const char* kTools = "Tools";
46 static constexpr const char* kWorkflow = "Workflow";
47 static constexpr const char* kHelp = "Help";
48};
49
51 std::string name;
52 std::string category;
53 std::string description;
54 std::string shortcut;
55 std::function<void()> callback;
56 int usage_count = 0;
57 int64_t last_used_ms = 0;
60 std::string provider_id;
61};
62
64 public:
65 void AddCommand(const std::string& name, const std::string& category,
66 const std::string& description, const std::string& shortcut,
67 std::function<void()> callback);
68
69 void RecordUsage(const std::string& name);
70
71 std::vector<CommandEntry> SearchCommands(const std::string& query);
72
73 std::vector<CommandEntry> GetRecentCommands(int limit = 10);
74
75 std::vector<CommandEntry> GetFrequentCommands(int limit = 10);
76
81 std::vector<CommandEntry> GetAllCommands() const;
82
86 size_t GetCommandCount() const { return commands_.size(); }
87
91 void Clear();
92
93 // ============================================================================
94 // Providers
95 // ============================================================================
96
101 void RegisterProvider(std::unique_ptr<CommandProvider> provider);
102
105 void UnregisterProvider(const std::string& provider_id);
106
109 void RefreshProvider(const std::string& provider_id);
110
112 void RefreshProviders();
113
116 void RemoveProviderCommands(const std::string& provider_id);
117
118 // ============================================================================
119 // Bulk Registration Methods (used by built-in providers; kept public so
120 // tests and legacy callers can still drive registration directly).
121 // ============================================================================
122
129 size_t session_id);
130
136 std::function<void(const std::string&)> switch_callback);
137
143 std::function<void(const std::string&)> apply_callback);
144
153 std::function<void(const std::string&)> open_callback);
154
161 void RegisterDungeonRoomCommands(size_t session_id);
162
167 size_t session_id);
168
193 const RecentProjectsModel* model,
194 const std::vector<std::string>& template_names,
195 std::function<void(const std::string&)> remove_callback,
196 std::function<void(const std::string&)> toggle_pin_callback,
197 std::function<void()> undo_remove_callback,
198 std::function<void()> clear_recents_callback,
199 std::function<void(const std::string&)> create_from_template_callback,
200 std::function<void()> dismiss_welcome_callback,
201 std::function<void()> show_welcome_callback);
202
207 void SaveHistory(const std::string& filepath);
208
213 void LoadHistory(const std::string& filepath);
214
215 static int FuzzyScore(const std::string& text, const std::string& query);
216
217 private:
218 std::unordered_map<std::string, CommandEntry> commands_;
219 std::vector<std::unique_ptr<CommandProvider>> providers_;
223};
224
225} // namespace editor
226} // namespace yaze
227
228#endif // YAZE_APP_EDITOR_SYSTEM_COMMAND_PALETTE_H_
std::vector< CommandEntry > SearchCommands(const std::string &query)
void RegisterDungeonRoomCommands(size_t session_id)
Register dungeon room navigation commands.
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 Clear()
Clear all commands (and forget every registered provider).
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.
void RecordUsage(const std::string &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.
std::vector< CommandEntry > GetRecentCommands(int limit=10)
void RefreshProviders()
Remove-and-re-run every registered provider.
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< CommandEntry > GetFrequentCommands(int limit=10)
static int FuzzyScore(const std::string &text, const std::string &query)
void RefreshProvider(const std::string &provider_id)
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 * 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