yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
shortcut_configurator.cc
Go to the documentation of this file.
2
3#include "absl/functional/bind_front.h"
4#include "absl/strings/str_format.h"
15#include "core/project.h"
16
17namespace yaze::editor {
18
19namespace {
20
21void RegisterIfValid(ShortcutManager* shortcut_manager,
22 const std::string& name,
23 const std::vector<ImGuiKey>& keys,
24 std::function<void()> callback) {
25 if (!shortcut_manager || !callback) {
26 return;
27 }
28 shortcut_manager->RegisterShortcut(name, keys, std::move(callback));
29}
30
31void RegisterIfValid(ShortcutManager* shortcut_manager,
32 const std::string& name,
33 ImGuiKey key,
34 std::function<void()> callback) {
35 if (!shortcut_manager || !callback) {
36 return;
37 }
38 shortcut_manager->RegisterShortcut(name, key, std::move(callback));
39}
40
41} // namespace
42
44 ShortcutManager* shortcut_manager) {
45 if (!shortcut_manager) {
46 return;
47 }
48
49 auto* editor_manager = deps.editor_manager;
50 auto* ui_coordinator = deps.ui_coordinator;
51 auto* popup_manager = deps.popup_manager;
52 auto* card_registry = deps.card_registry;
53
54 RegisterIfValid(
55 shortcut_manager, "global.toggle_sidebar",
56 {ImGuiKey_LeftCtrl, ImGuiKey_B},
57 [ui_coordinator]() {
58 if (ui_coordinator) {
59 ui_coordinator->ToggleCardSidebar();
60 }
61 });
62
63 RegisterIfValid(shortcut_manager, "Open", {ImGuiMod_Ctrl, ImGuiKey_O},
64 [editor_manager]() {
65 if (editor_manager) {
66 editor_manager->LoadRom();
67 }
68 });
69
70 RegisterIfValid(shortcut_manager, "Save", {ImGuiMod_Ctrl, ImGuiKey_S},
71 [editor_manager]() {
72 if (editor_manager) {
73 editor_manager->SaveRom();
74 }
75 });
76
77 RegisterIfValid(shortcut_manager, "Save As",
78 {ImGuiMod_Ctrl, ImGuiMod_Shift, ImGuiKey_S},
79 [editor_manager]() {
80 if (editor_manager) {
81 // Use project-aware default filename when possible
82 std::string filename = editor_manager->GetCurrentRom()
83 ? editor_manager->GetCurrentRom()->filename()
84 : "";
85 editor_manager->SaveRomAs(filename);
86 }
87 });
88
89 RegisterIfValid(shortcut_manager, "Close ROM", {ImGuiMod_Ctrl, ImGuiKey_W},
90 [editor_manager]() {
91 if (editor_manager && editor_manager->GetCurrentRom()) {
92 editor_manager->GetCurrentRom()->Close();
93 }
94 });
95
96 RegisterIfValid(shortcut_manager, "Quit", {ImGuiMod_Ctrl, ImGuiKey_Q},
97 [editor_manager]() {
98 if (editor_manager) {
99 editor_manager->Quit();
100 }
101 });
102
103 RegisterIfValid(shortcut_manager, "Undo", {ImGuiMod_Ctrl, ImGuiKey_Z},
104 [editor_manager]() {
105 if (editor_manager && editor_manager->GetCurrentEditor()) {
106 editor_manager->GetCurrentEditor()->Undo();
107 }
108 });
109
110 RegisterIfValid(shortcut_manager, "Redo",
111 {ImGuiMod_Ctrl, ImGuiMod_Shift, ImGuiKey_Z},
112 [editor_manager]() {
113 if (editor_manager && editor_manager->GetCurrentEditor()) {
114 editor_manager->GetCurrentEditor()->Redo();
115 }
116 });
117
118 RegisterIfValid(shortcut_manager, "Cut", {ImGuiMod_Ctrl, ImGuiKey_X},
119 [editor_manager]() {
120 if (editor_manager && editor_manager->GetCurrentEditor()) {
121 editor_manager->GetCurrentEditor()->Cut();
122 }
123 });
124
125 RegisterIfValid(shortcut_manager, "Copy", {ImGuiMod_Ctrl, ImGuiKey_C},
126 [editor_manager]() {
127 if (editor_manager && editor_manager->GetCurrentEditor()) {
128 editor_manager->GetCurrentEditor()->Copy();
129 }
130 });
131
132 RegisterIfValid(shortcut_manager, "Paste", {ImGuiMod_Ctrl, ImGuiKey_V},
133 [editor_manager]() {
134 if (editor_manager && editor_manager->GetCurrentEditor()) {
135 editor_manager->GetCurrentEditor()->Paste();
136 }
137 });
138
139 RegisterIfValid(shortcut_manager, "Find", {ImGuiMod_Ctrl, ImGuiKey_F},
140 [editor_manager]() {
141 if (editor_manager && editor_manager->GetCurrentEditor()) {
142 editor_manager->GetCurrentEditor()->Find();
143 }
144 });
145
146 RegisterIfValid(
147 shortcut_manager, "Command Palette",
148 {ImGuiMod_Ctrl, ImGuiMod_Shift, ImGuiKey_P},
149 [ui_coordinator]() {
150 if (ui_coordinator) {
151 ui_coordinator->ShowCommandPalette();
152 }
153 });
154
155 RegisterIfValid(
156 shortcut_manager, "Global Search",
157 {ImGuiMod_Ctrl, ImGuiMod_Shift, ImGuiKey_K},
158 [ui_coordinator]() {
159 if (ui_coordinator) {
160 ui_coordinator->ShowGlobalSearch();
161 }
162 });
163
164 RegisterIfValid(shortcut_manager, "Load Last ROM",
165 {ImGuiMod_Ctrl, ImGuiKey_R},
166 [editor_manager]() {
168 if (!recent.GetRecentFiles().empty() && editor_manager) {
169 editor_manager->OpenRomOrProject(
170 recent.GetRecentFiles().front());
171 }
172 });
173
174 RegisterIfValid(shortcut_manager, "Show About", ImGuiKey_F1,
175 [popup_manager]() {
176 if (popup_manager) {
177 popup_manager->Show("About");
178 }
179 });
180
181 auto register_editor_shortcut = [&](EditorType type, ImGuiKey key) {
182 RegisterIfValid(shortcut_manager,
183 absl::StrFormat("switch.%d", static_cast<int>(type)),
184 {ImGuiMod_Ctrl, key},
185 [editor_manager, type]() {
186 if (editor_manager) {
187 editor_manager->SwitchToEditor(type);
188 }
189 });
190 };
191
192 register_editor_shortcut(EditorType::kOverworld, ImGuiKey_1);
193 register_editor_shortcut(EditorType::kDungeon, ImGuiKey_2);
194 register_editor_shortcut(EditorType::kGraphics, ImGuiKey_3);
195 register_editor_shortcut(EditorType::kSprite, ImGuiKey_4);
196 register_editor_shortcut(EditorType::kMessage, ImGuiKey_5);
197 register_editor_shortcut(EditorType::kMusic, ImGuiKey_6);
198 register_editor_shortcut(EditorType::kPalette, ImGuiKey_7);
199 register_editor_shortcut(EditorType::kScreen, ImGuiKey_8);
200 register_editor_shortcut(EditorType::kAssembly, ImGuiKey_9);
201 register_editor_shortcut(EditorType::kSettings, ImGuiKey_0);
202
203 RegisterIfValid(shortcut_manager, "Editor Selection",
204 {ImGuiMod_Ctrl, ImGuiKey_E},
205 [ui_coordinator]() {
206 if (ui_coordinator) {
207 ui_coordinator->ShowEditorSelection();
208 }
209 });
210
211 RegisterIfValid(
212 shortcut_manager, "Card Browser",
213 {ImGuiMod_Ctrl, ImGuiMod_Shift, ImGuiKey_B},
214 [ui_coordinator]() {
215 if (ui_coordinator) {
216 ui_coordinator->ShowCardBrowser();
217 }
218 });
219
220 if (card_registry) {
221 // Note: Using Ctrl+Alt for card shortcuts to avoid conflicts with Save As (Ctrl+Shift+S)
222 RegisterIfValid(shortcut_manager, "Show Dungeon Cards",
223 {ImGuiMod_Ctrl, ImGuiMod_Alt, ImGuiKey_D},
224 [card_registry]() {
225 card_registry->ShowAllCardsInCategory("Dungeon");
226 });
227 RegisterIfValid(shortcut_manager, "Show Graphics Cards",
228 {ImGuiMod_Ctrl, ImGuiMod_Alt, ImGuiKey_G},
229 [card_registry]() {
230 card_registry->ShowAllCardsInCategory("Graphics");
231 });
232 RegisterIfValid(shortcut_manager, "Show Screen Cards",
233 {ImGuiMod_Ctrl, ImGuiMod_Alt, ImGuiKey_S},
234 [card_registry]() {
235 card_registry->ShowAllCardsInCategory("Screen");
236 });
237 }
238
239#ifdef YAZE_WITH_GRPC
240 RegisterIfValid(shortcut_manager, "Agent Editor",
241 {ImGuiMod_Ctrl, ImGuiMod_Shift, ImGuiKey_A},
242 [editor_manager]() {
243 if (editor_manager) {
244 editor_manager->ShowAIAgent();
245 }
246 });
247
248 RegisterIfValid(shortcut_manager, "Agent Chat History",
249 {ImGuiMod_Ctrl, ImGuiKey_H},
250 [editor_manager]() {
251 if (editor_manager) {
252 editor_manager->ShowChatHistory();
253 }
254 });
255
256 RegisterIfValid(shortcut_manager, "Proposal Drawer",
257 {ImGuiMod_Ctrl | ImGuiMod_Shift, ImGuiKey_R}, // Changed from Ctrl+P to Ctrl+Shift+R
258 [editor_manager]() {
259 if (editor_manager) {
260 editor_manager->ShowProposalDrawer();
261 }
262 });
263#endif
264}
265
267 ShortcutManager* shortcut_manager) {
268 if (!shortcut_manager) {
269 return;
270 }
271
272 auto* menu_orchestrator = deps.menu_orchestrator;
273 auto* session_coordinator = deps.session_coordinator;
274 auto* workspace_manager = deps.workspace_manager;
275
276 RegisterIfValid(shortcut_manager, "New Session",
277 {ImGuiMod_Ctrl, ImGuiMod_Shift, ImGuiKey_N},
278 [session_coordinator]() {
279 if (session_coordinator) {
280 session_coordinator->CreateNewSession();
281 }
282 });
283
284 RegisterIfValid(shortcut_manager, "Duplicate Session",
285 {ImGuiMod_Ctrl, ImGuiMod_Shift, ImGuiKey_D},
286 [session_coordinator]() {
287 if (session_coordinator) {
288 session_coordinator->DuplicateCurrentSession();
289 }
290 });
291
292 RegisterIfValid(shortcut_manager, "Close Session",
293 {ImGuiMod_Ctrl, ImGuiMod_Shift, ImGuiKey_W},
294 [session_coordinator]() {
295 if (session_coordinator) {
296 session_coordinator->CloseCurrentSession();
297 }
298 });
299
300 RegisterIfValid(shortcut_manager, "Session Switcher",
301 {ImGuiMod_Ctrl, ImGuiKey_Tab},
302 [session_coordinator]() {
303 if (session_coordinator) {
304 session_coordinator->ShowSessionSwitcher();
305 }
306 });
307
308 RegisterIfValid(shortcut_manager, "Save Layout",
309 {ImGuiMod_Ctrl, ImGuiMod_Shift, ImGuiKey_L},
310 [workspace_manager]() {
311 if (workspace_manager) {
312 workspace_manager->SaveWorkspaceLayout();
313 }
314 });
315
316 RegisterIfValid(shortcut_manager, "Load Layout",
317 {ImGuiMod_Ctrl, ImGuiMod_Shift, ImGuiKey_O},
318 [workspace_manager]() {
319 if (workspace_manager) {
320 workspace_manager->LoadWorkspaceLayout();
321 }
322 });
323
324 // Note: Changed from Ctrl+Shift+R to Ctrl+Alt+R to avoid conflict with Proposal Drawer
325 RegisterIfValid(shortcut_manager, "Reset Layout",
326 {ImGuiMod_Ctrl, ImGuiMod_Alt, ImGuiKey_R},
327 [workspace_manager]() {
328 if (workspace_manager) {
329 workspace_manager->ResetWorkspaceLayout();
330 }
331 });
332
333 RegisterIfValid(shortcut_manager, "Maximize Window", ImGuiKey_F11,
334 [workspace_manager]() {
335 if (workspace_manager) {
336 workspace_manager->MaximizeCurrentWindow();
337 }
338 });
339
340#ifdef YAZE_ENABLE_TESTING
341 RegisterIfValid(shortcut_manager, "Test Dashboard",
342 {ImGuiMod_Ctrl, ImGuiKey_T},
343 [menu_orchestrator]() {
344 if (menu_orchestrator) {
345 menu_orchestrator->OnShowTestDashboard();
346 }
347 });
348#endif
349}
350
351} // namespace yaze::editor
352
void RegisterShortcut(const std::string &name, const std::vector< ImGuiKey > &keys)
static RecentFilesManager & GetInstance()
Definition project.h:244
void RegisterIfValid(ShortcutManager *shortcut_manager, const std::string &name, const std::vector< ImGuiKey > &keys, std::function< void()> callback)
Editors are the view controllers for the application.
void ConfigureMenuShortcuts(const ShortcutDependencies &deps, ShortcutManager *shortcut_manager)
void ConfigureEditorShortcuts(const ShortcutDependencies &deps, ShortcutManager *shortcut_manager)