impr: Display sub menus for shortcut settings
This commit is contained in:
parent
caf8fa8e25
commit
ee4bb33b0a
@ -393,7 +393,7 @@ namespace hex {
|
|||||||
using Callback = std::function<void()>;
|
using Callback = std::function<void()>;
|
||||||
struct ShortcutEntry {
|
struct ShortcutEntry {
|
||||||
Shortcut shortcut;
|
Shortcut shortcut;
|
||||||
UnlocalizedString unlocalizedName;
|
std::vector<UnlocalizedString> unlocalizedName;
|
||||||
Callback callback;
|
Callback callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -403,6 +403,7 @@ namespace hex {
|
|||||||
* @param unlocalizedName The unlocalized name of the shortcut
|
* @param unlocalizedName The unlocalized name of the shortcut
|
||||||
* @param callback The callback to call when the shortcut is triggered.
|
* @param callback The callback to call when the shortcut is triggered.
|
||||||
*/
|
*/
|
||||||
|
static void addGlobalShortcut(const Shortcut &shortcut, const std::vector<UnlocalizedString> &unlocalizedName, const Callback &callback);
|
||||||
static void addGlobalShortcut(const Shortcut &shortcut, const UnlocalizedString &unlocalizedName, const Callback &callback);
|
static void addGlobalShortcut(const Shortcut &shortcut, const UnlocalizedString &unlocalizedName, const Callback &callback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -412,6 +413,7 @@ namespace hex {
|
|||||||
* @param unlocalizedName The unlocalized name of the shortcut
|
* @param unlocalizedName The unlocalized name of the shortcut
|
||||||
* @param callback The callback to call when the shortcut is triggered.
|
* @param callback The callback to call when the shortcut is triggered.
|
||||||
*/
|
*/
|
||||||
|
static void addShortcut(View *view, const Shortcut &shortcut, const std::vector<UnlocalizedString> &unlocalizedName, const Callback &callback);
|
||||||
static void addShortcut(View *view, const Shortcut &shortcut, const UnlocalizedString &unlocalizedName, const Callback &callback);
|
static void addShortcut(View *view, const Shortcut &shortcut, const UnlocalizedString &unlocalizedName, const Callback &callback);
|
||||||
|
|
||||||
|
|
||||||
|
@ -909,10 +909,16 @@ namespace hex {
|
|||||||
|
|
||||||
if (shortcut != Shortcut::None) {
|
if (shortcut != Shortcut::None) {
|
||||||
auto callbackIfEnabled = [enabledCallback, function]{ if (enabledCallback()) { function(); } };
|
auto callbackIfEnabled = [enabledCallback, function]{ if (enabledCallback()) { function(); } };
|
||||||
|
|
||||||
|
const auto unlocalizedShortcutName =
|
||||||
|
unlocalizedMainMenuNames.size() == 1 ?
|
||||||
|
std::vector { unlocalizedMainMenuNames.back() } :
|
||||||
|
std::vector(unlocalizedMainMenuNames.begin() + 1, unlocalizedMainMenuNames.end());
|
||||||
|
|
||||||
if (shortcut.isLocal() && view != nullptr)
|
if (shortcut.isLocal() && view != nullptr)
|
||||||
ShortcutManager::addShortcut(view, shortcut, unlocalizedMainMenuNames.back(), callbackIfEnabled);
|
ShortcutManager::addShortcut(view, shortcut, unlocalizedShortcutName, callbackIfEnabled);
|
||||||
else
|
else
|
||||||
ShortcutManager::addGlobalShortcut(shortcut, unlocalizedMainMenuNames.back(), callbackIfEnabled);
|
ShortcutManager::addGlobalShortcut(shortcut, unlocalizedShortcutName, callbackIfEnabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,14 +16,22 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ShortcutManager::addGlobalShortcut(const Shortcut &shortcut, const UnlocalizedString &unlocalizedName, const std::function<void()> &callback) {
|
void ShortcutManager::addGlobalShortcut(const Shortcut &shortcut, const std::vector<UnlocalizedString> &unlocalizedName, const std::function<void()> &callback) {
|
||||||
s_globalShortcuts->insert({ shortcut, { shortcut, unlocalizedName, callback } });
|
s_globalShortcuts->insert({ shortcut, { shortcut, unlocalizedName, callback } });
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutManager::addShortcut(View *view, const Shortcut &shortcut, const UnlocalizedString &unlocalizedName, const std::function<void()> &callback) {
|
void ShortcutManager::addGlobalShortcut(const Shortcut &shortcut, const UnlocalizedString &unlocalizedName, const std::function<void()> &callback) {
|
||||||
|
s_globalShortcuts->insert({ shortcut, { shortcut, { unlocalizedName }, callback } });
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShortcutManager::addShortcut(View *view, const Shortcut &shortcut, const std::vector<UnlocalizedString> &unlocalizedName, const std::function<void()> &callback) {
|
||||||
view->m_shortcuts.insert({ shortcut + CurrentView, { shortcut, unlocalizedName, callback } });
|
view->m_shortcuts.insert({ shortcut + CurrentView, { shortcut, unlocalizedName, callback } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShortcutManager::addShortcut(View *view, const Shortcut &shortcut, const UnlocalizedString &unlocalizedName, const std::function<void()> &callback) {
|
||||||
|
view->m_shortcuts.insert({ shortcut + CurrentView, { shortcut, { unlocalizedName }, callback } });
|
||||||
|
}
|
||||||
|
|
||||||
static Shortcut getShortcut(bool ctrl, bool alt, bool shift, bool super, bool focused, u32 keyCode) {
|
static Shortcut getShortcut(bool ctrl, bool alt, bool shift, bool super, bool focused, u32 keyCode) {
|
||||||
Shortcut pressedShortcut;
|
Shortcut pressedShortcut;
|
||||||
|
|
||||||
|
@ -246,9 +246,12 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
class KeybindingWidget : public ContentRegistry::Settings::Widgets::Widget {
|
class KeybindingWidget : public ContentRegistry::Settings::Widgets::Widget {
|
||||||
public:
|
public:
|
||||||
KeybindingWidget(View *view, const Shortcut &shortcut) : m_view(view), m_shortcut(shortcut), m_drawShortcut(shortcut), m_defaultShortcut(shortcut) {}
|
KeybindingWidget(View *view, const Shortcut &shortcut, const std::vector<UnlocalizedString> &fullName)
|
||||||
|
: m_view(view), m_shortcut(shortcut), m_drawShortcut(shortcut), m_defaultShortcut(shortcut), m_fullName(fullName) {}
|
||||||
|
|
||||||
bool draw(const std::string &name) override {
|
bool draw(const std::string &name) override {
|
||||||
|
std::ignore = name;
|
||||||
|
|
||||||
std::string label;
|
std::string label;
|
||||||
|
|
||||||
if (!m_editing)
|
if (!m_editing)
|
||||||
@ -300,7 +303,15 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
ImGuiExt::TextFormatted("{}", name);
|
std::string fullName;
|
||||||
|
for (const auto &part : m_fullName) {
|
||||||
|
fullName += Lang(part).get();
|
||||||
|
fullName += " -> ";
|
||||||
|
}
|
||||||
|
if (fullName.size() >= 4)
|
||||||
|
fullName = fullName.substr(0, fullName.size() - 4);
|
||||||
|
|
||||||
|
ImGuiExt::TextFormatted("{}", fullName);
|
||||||
|
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
|
|
||||||
@ -376,6 +387,7 @@ namespace hex::plugin::builtin {
|
|||||||
private:
|
private:
|
||||||
View *m_view = nullptr;
|
View *m_view = nullptr;
|
||||||
Shortcut m_shortcut, m_drawShortcut, m_defaultShortcut;
|
Shortcut m_shortcut, m_drawShortcut, m_defaultShortcut;
|
||||||
|
std::vector<UnlocalizedString> m_fullName;
|
||||||
bool m_editing = false;
|
bool m_editing = false;
|
||||||
bool m_hasDuplicate = false;
|
bool m_hasDuplicate = false;
|
||||||
};
|
};
|
||||||
@ -934,12 +946,12 @@ namespace hex::plugin::builtin {
|
|||||||
{
|
{
|
||||||
EventImHexStartupFinished::subscribe([]{
|
EventImHexStartupFinished::subscribe([]{
|
||||||
for (const auto &shortcutEntry : ShortcutManager::getGlobalShortcuts()) {
|
for (const auto &shortcutEntry : ShortcutManager::getGlobalShortcuts()) {
|
||||||
ContentRegistry::Settings::add<KeybindingWidget>("hex.builtin.setting.shortcuts", "hex.builtin.setting.shortcuts.global", shortcutEntry.unlocalizedName, nullptr, shortcutEntry.shortcut);
|
ContentRegistry::Settings::add<KeybindingWidget>("hex.builtin.setting.shortcuts", "hex.builtin.setting.shortcuts.global", shortcutEntry.unlocalizedName.back(), nullptr, shortcutEntry.shortcut, shortcutEntry.unlocalizedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &[viewName, view] : ContentRegistry::Views::impl::getEntries()) {
|
for (auto &[viewName, view] : ContentRegistry::Views::impl::getEntries()) {
|
||||||
for (const auto &shortcutEntry : ShortcutManager::getViewShortcuts(view.get())) {
|
for (const auto &shortcutEntry : ShortcutManager::getViewShortcuts(view.get())) {
|
||||||
ContentRegistry::Settings::add<KeybindingWidget>("hex.builtin.setting.shortcuts", viewName, shortcutEntry.unlocalizedName, view.get(), shortcutEntry.shortcut);
|
ContentRegistry::Settings::add<KeybindingWidget>("hex.builtin.setting.shortcuts", viewName, shortcutEntry.unlocalizedName.back(), view.get(), shortcutEntry.shortcut, shortcutEntry.unlocalizedName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user