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 static constexpr const char* kDrawer = "Drawers";
49};
50
52 std::string name;
53 std::string category;
54 std::string description;
55 std::string shortcut;
56 std::function<void()> callback;
57 int usage_count = 0;
58 int64_t last_used_ms = 0;
61 std::string provider_id;
62};
63
65 public:
66 void AddCommand(const std::string& name, const std::string& category,
67 const std::string& description, const std::string& shortcut,
68 std::function<void()> callback);
69
70 void RecordUsage(const std::string& name);
71
72 std::vector<CommandEntry> SearchCommands(const std::string& query);
73
74 std::vector<CommandEntry> GetRecentCommands(int limit = 10);
75
76 std::vector<CommandEntry> GetFrequentCommands(int limit = 10);
77
82 std::vector<CommandEntry> GetAllCommands() const;
83
87 size_t GetCommandCount() const { return commands_.size(); }
88
92 void Clear();
93
94 // ============================================================================
95 // Providers
96 // ============================================================================
97
102 void RegisterProvider(std::unique_ptr<CommandProvider> provider);
103
106 void UnregisterProvider(const std::string& provider_id);
107
110 void RefreshProvider(const std::string& provider_id);
111
113 void RefreshProviders();
114
117 void RemoveProviderCommands(const std::string& provider_id);
118
119 // ============================================================================
120 // Bulk Registration Methods (used by built-in providers; kept public so
121 // tests and legacy callers can still drive registration directly).
122 // ============================================================================
123
130 size_t session_id);
131
137 std::function<void(const std::string&)> switch_callback);
138
144 std::function<void(const std::string&)> apply_callback);
145
154 std::function<void(const std::string&)> open_callback);
155
162 void RegisterDungeonRoomCommands(size_t session_id);
163
171 std::function<void(int drawer_type)> toggle_callback,
172 std::function<void()> cycle_next = {},
173 std::function<void()> cycle_prev = {});
174
178 void RegisterWorkflowCommands(WorkspaceWindowManager* window_manager,
179 size_t session_id);
180
205 const RecentProjectsModel* model,
206 const std::vector<std::string>& template_names,
207 std::function<void(const std::string&)> remove_callback,
208 std::function<void(const std::string&)> toggle_pin_callback,
209 std::function<void()> undo_remove_callback,
210 std::function<void()> clear_recents_callback,
211 std::function<void(const std::string&)> create_from_template_callback,
212 std::function<void()> dismiss_welcome_callback,
213 std::function<void()> show_welcome_callback);
214
219 void SaveHistory(const std::string& filepath);
220
225 void LoadHistory(const std::string& filepath);
226
227 static int FuzzyScore(const std::string& text, const std::string& query);
228
229 private:
230 std::unordered_map<std::string, CommandEntry> commands_;
231 std::vector<std::unique_ptr<CommandProvider>> providers_;
235};
236
237} // namespace editor
238} // namespace yaze
239
240#endif // YAZE_APP_EDITOR_SYSTEM_COMMAND_PALETTE_H_
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 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 * 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