yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
command_palette_providers.cc
Go to the documentation of this file.
2
3#include <utility>
4
5#include "absl/strings/str_format.h"
8
9namespace yaze {
10namespace editor {
11
13 WorkspaceWindowManager* window_manager, size_t session_id)
14 : window_manager_(window_manager), session_id_(session_id) {}
15
19
21 std::function<void(const std::string&)> switch_callback)
22 : switch_callback_(std::move(switch_callback)) {}
23
27
29 std::function<void(const std::string&)> open_callback)
30 : open_callback_(std::move(open_callback)) {}
31
35
37 : session_id_(session_id) {}
38
42
44 std::function<void(int drawer_type)> toggle_callback,
45 std::function<void()> cycle_next, std::function<void()> cycle_prev)
46 : toggle_callback_(std::move(toggle_callback)),
47 cycle_next_(std::move(cycle_next)),
48 cycle_prev_(std::move(cycle_prev)) {}
49
53
55 std::function<void(const std::string&)> apply_callback)
56 : apply_callback_(std::move(apply_callback)) {}
57
61
63 WorkspaceWindowManager* window_manager, size_t session_id)
64 : window_manager_(window_manager), session_id_(session_id) {}
65
69
71 WorkspaceWindowManager* window_manager, UserSettings* user_settings,
72 size_t session_id)
73 : window_manager_(window_manager),
74 user_settings_(user_settings),
75 session_id_(session_id) {}
76
78 if (!palette || !user_settings_ || !window_manager_)
79 return;
80
82
83 // Global helpers first — they're callable any time.
84 palette->AddCommand("Sidebar: Reset Order", CommandCategory::kView,
85 "Clear the custom sidebar order and revert to defaults",
86 /*shortcut=*/"", [this]() {
87 if (!user_settings_)
88 return;
89 user_settings_->prefs().sidebar_order.clear();
90 (void)user_settings_->Save();
91 });
92
93 palette->AddCommand("Sidebar: Show All Categories", CommandCategory::kView,
94 "Un-hide every sidebar category",
95 /*shortcut=*/"", [this]() {
96 if (!user_settings_)
97 return;
99 (void)user_settings_->Save();
100 });
101
102 // Per-category toggles. Using static "Toggle" labels avoids the need to
103 // refresh the provider every time state flips.
104 for (const auto& cat : categories) {
106 continue;
107
108 std::string pin_name = absl::StrFormat("Sidebar: Toggle Pin: %s", cat);
109 std::string pin_desc =
110 absl::StrFormat("Pin or unpin %s at the top of the sidebar", cat);
111 std::string captured_cat_pin = cat;
112 palette->AddCommand(pin_name, CommandCategory::kView, pin_desc,
113 /*shortcut=*/"", [this, captured_cat_pin]() {
114 if (!user_settings_)
115 return;
116 auto& pinned = user_settings_->prefs().sidebar_pinned;
117 if (pinned.count(captured_cat_pin)) {
118 pinned.erase(captured_cat_pin);
119 } else {
120 pinned.insert(captured_cat_pin);
121 }
122 (void)user_settings_->Save();
123 });
124
125 std::string hide_name =
126 absl::StrFormat("Sidebar: Toggle Visibility: %s", cat);
127 std::string hide_desc =
128 absl::StrFormat("Show or hide %s in the sidebar", cat);
129 std::string captured_cat_hide = cat;
130 palette->AddCommand(hide_name, CommandCategory::kView, hide_desc,
131 /*shortcut=*/"", [this, captured_cat_hide]() {
132 if (!user_settings_)
133 return;
134 auto& hidden = user_settings_->prefs().sidebar_hidden;
135 if (hidden.count(captured_cat_hide)) {
136 hidden.erase(captured_cat_hide);
137 } else {
138 hidden.insert(captured_cat_hide);
139 }
140 (void)user_settings_->Save();
141 });
142 }
143}
144
146 : callbacks_(std::move(callbacks)) {}
147
155
156} // namespace editor
157} // namespace yaze
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 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)
void RegisterPanelCommands(WorkspaceWindowManager *window_manager, size_t session_id)
Register all window toggle commands from WorkspaceWindowManager.
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.
void RegisterRecentFilesCommands(std::function< void(const std::string &)> open_callback)
Register commands to open recent files.
void Provide(CommandPalette *palette) override
Populate palette with this source's commands.
DrawerCommandsProvider(std::function< void(int drawer_type)> toggle_callback, std::function< void()> cycle_next={}, std::function< void()> cycle_prev={})
void Provide(CommandPalette *palette) override
Populate palette with this source's commands.
void Provide(CommandPalette *palette) override
Populate palette with this source's commands.
EditorCommandsProvider(std::function< void(const std::string &)> switch_callback)
std::function< void(const std::string &) switch_callback_)
LayoutCommandsProvider(std::function< void(const std::string &)> apply_callback)
std::function< void(const std::string &) apply_callback_)
void Provide(CommandPalette *palette) override
Populate palette with this source's commands.
void Provide(CommandPalette *palette) override
Populate palette with this source's commands.
PanelCommandsProvider(WorkspaceWindowManager *window_manager, size_t session_id)
void Provide(CommandPalette *palette) override
Populate palette with this source's commands.
std::function< void(const std::string &) open_callback_)
RecentFilesCommandsProvider(std::function< void(const std::string &)> open_callback)
void Provide(CommandPalette *palette) override
Populate palette with this source's commands.
SidebarCommandsProvider(WorkspaceWindowManager *window_manager, UserSettings *user_settings, size_t session_id)
Manages user preferences and settings persistence.
void Provide(CommandPalette *palette) override
Populate palette with this source's commands.
void Provide(CommandPalette *palette) override
Populate palette with this source's commands.
WorkflowCommandsProvider(WorkspaceWindowManager *window_manager, size_t session_id)
Central registry for all editor cards with session awareness and dependency injection.
static constexpr const char * kDashboardCategory
std::vector< std::string > GetAllCategories(size_t session_id) const
static constexpr const char * kView
std::unordered_set< std::string > sidebar_hidden
std::function< void(const std::string &) toggle_pin)
std::function< void(const std::string &) remove)
std::function< void(const std::string &) create_from_template)