Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
shortcutdefs.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 Twilight
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15*/
16#pragma once
17
31
32#include <QHash>
33#include <QString>
34#include <QKeySequence>
35#include <Qt>
36#include <functional>
37
40
41namespace pse {
42
45inline QHash<QString, QKeySequence> shortcutKeyMap()
46{
47 return {
48 { QStringLiteral("new"), QKeySequence(Qt::CTRL | Qt::Key_N) },
49 { QStringLiteral("open"), QKeySequence(Qt::CTRL | Qt::Key_O) },
50 { QStringLiteral("reopen"), QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_O) },
51 { QStringLiteral("save"), QKeySequence(Qt::CTRL | Qt::Key_S) },
52 { QStringLiteral("saveas"), QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_S) },
53 { QStringLiteral("savecopyas"), QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_S) },
54 { QStringLiteral("scrub"), QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_W) },
55 { QStringLiteral("clear-recentfiles"), QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Minus) },
56 { QStringLiteral("exit"), QKeySequence(Qt::CTRL | Qt::Key_Q) },
57 { QStringLiteral("exit2"), QKeySequence(Qt::ALT | Qt::Key_F4) },
58 { QStringLiteral("random"), QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_R) },
59 };
60}
61
64inline QKeySequence recentFileShortcutKey(int i)
65{
66 return QKeySequence(Qt::CTRL | Qt::SHIFT | static_cast<Qt::Key>(0x30 + i));
67}
68
75inline QHash<QString, std::function<void()>> shortcutActions(FileManagement* file,
76 std::function<void()> onExit)
77{
78 return {
79 { QStringLiteral("new"), [file]{ file->newFile(); } },
80 { QStringLiteral("open"), [file]{ file->openFile(); } },
81 { QStringLiteral("reopen"), [file]{ file->reopenFile(); } },
82 { QStringLiteral("save"), [file]{ file->saveFile(); } },
83 { QStringLiteral("saveas"), [file]{ file->saveFileAs(); } },
84 { QStringLiteral("savecopyas"), [file]{ file->saveFileCopy(); } },
85 { QStringLiteral("scrub"), [file]{ file->wipeUnusedSpace(); } },
86 { QStringLiteral("clear-recentfiles"), [file]{ file->clearRecentFiles(); } },
87 { QStringLiteral("exit"), [onExit]{ if (onExit) onExit(); } },
88 { QStringLiteral("exit2"), [onExit]{ if (onExit) onExit(); } },
89 { QStringLiteral("random"), [file]{ file->data->randomizeExpansion(); } },
90 };
91}
92
93} // namespace pse
Owns the on-disk side of a save: the current path, the recent-files list, and the live SaveFile.
void newFile()
Start a fresh blank save.
void clearRecentFiles()
Forget the entire recent-files list.
SaveFile * data
The live save file these operations load into / save from.
bool saveFileAs()
Prompt for a new path and save there.
void wipeUnusedSpace()
Zero out save regions that aren't meaningfully used.
void reopenFile()
Reload the current path from disk, discarding edits.
bool saveFile()
Save to the current path.
bool saveFileCopy()
Save a copy elsewhere without changing the active path.
bool openFile()
Prompt for and open a save.
void randomizeExpansion()
Fully randomizes the expansion data, doesn't change save file data.
Definition savefile.cpp:104
QHash< QString, QKeySequence > shortcutKeyMap()
Named global shortcuts: action id -> key sequence.
QHash< QString, std::function< void()> > shortcutActions(FileManagement *file, std::function< void()> onExit)
What each named shortcut DOES, action id -> callable, over a live FileManagement.
QKeySequence recentFileShortcutKey(int i)
Recent-file shortcut i (0..MAX_RECENT_FILES-1) == Ctrl+Shift+(0+i), i.e.