impr: Disable main menu items for views that aren't selected right now
This commit is contained in:
parent
7752354598
commit
9fb38922ea
@ -98,6 +98,14 @@ namespace hex {
|
|||||||
|
|
||||||
[[nodiscard]] static std::string toWindowName(const UnlocalizedString &unlocalizedName);
|
[[nodiscard]] static std::string toWindowName(const UnlocalizedString &unlocalizedName);
|
||||||
|
|
||||||
|
[[nodiscard]] bool isFocused() const { return m_focused; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Used for focus handling. Don't use this directly
|
||||||
|
* @param focused Whether this view is focused
|
||||||
|
*/
|
||||||
|
void setFocused(bool focused) { m_focused = focused; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
class Window;
|
class Window;
|
||||||
class Special;
|
class Special;
|
||||||
@ -110,6 +118,7 @@ namespace hex {
|
|||||||
std::map<Shortcut, ShortcutManager::ShortcutEntry> m_shortcuts;
|
std::map<Shortcut, ShortcutManager::ShortcutEntry> m_shortcuts;
|
||||||
bool m_windowJustOpened = false;
|
bool m_windowJustOpened = false;
|
||||||
const char *m_icon;
|
const char *m_icon;
|
||||||
|
bool m_focused = false;
|
||||||
|
|
||||||
friend class ShortcutManager;
|
friend class ShortcutManager;
|
||||||
};
|
};
|
||||||
|
@ -728,6 +728,7 @@ namespace hex {
|
|||||||
|
|
||||||
// Detect if the window is focused
|
// Detect if the window is focused
|
||||||
const bool focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows | ImGuiFocusedFlags_NoPopupHierarchy);
|
const bool focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows | ImGuiFocusedFlags_NoPopupHierarchy);
|
||||||
|
view->setFocused(focused);
|
||||||
|
|
||||||
// Dock the window if it's not already docked
|
// Dock the window if it's not already docked
|
||||||
if (view->didWindowJustOpen() && !ImGui::IsWindowDocked()) {
|
if (view->didWindowJustOpen() && !ImGui::IsWindowDocked()) {
|
||||||
|
@ -33,7 +33,7 @@ namespace hex::plugin::builtin {
|
|||||||
bool s_displayShortcutHighlights = true;
|
bool s_displayShortcutHighlights = true;
|
||||||
bool s_useNativeMenuBar = false;
|
bool s_useNativeMenuBar = false;
|
||||||
|
|
||||||
void createNestedMenu(std::span<const UnlocalizedString> menuItems, const char *icon, const Shortcut &shortcut, const ContentRegistry::Interface::impl::MenuCallback &callback, const ContentRegistry::Interface::impl::EnabledCallback &enabledCallback, const ContentRegistry::Interface::impl::SelectedCallback &selectedCallback) {
|
void createNestedMenu(std::span<const UnlocalizedString> menuItems, const char *icon, const Shortcut &shortcut, View *view, const ContentRegistry::Interface::impl::MenuCallback &callback, const ContentRegistry::Interface::impl::EnabledCallback &enabledCallback, const ContentRegistry::Interface::impl::SelectedCallback &selectedCallback) {
|
||||||
const auto &name = menuItems.front();
|
const auto &name = menuItems.front();
|
||||||
|
|
||||||
if (name.get() == ContentRegistry::Interface::impl::SeparatorValue) {
|
if (name.get() == ContentRegistry::Interface::impl::SeparatorValue) {
|
||||||
@ -46,13 +46,13 @@ namespace hex::plugin::builtin {
|
|||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
} else if (menuItems.size() == 1) {
|
} else if (menuItems.size() == 1) {
|
||||||
if (menu::menuItemEx(Lang(name), icon, shortcut, selectedCallback(), enabledCallback()))
|
if (menu::menuItemEx(Lang(name), icon, shortcut, selectedCallback(), enabledCallback() && (view == nullptr || view->isFocused())))
|
||||||
callback();
|
callback();
|
||||||
} else {
|
} else {
|
||||||
bool isSubmenu = (menuItems.begin() + 1)->get() == ContentRegistry::Interface::impl::SubMenuValue;
|
bool isSubmenu = (menuItems.begin() + 1)->get() == ContentRegistry::Interface::impl::SubMenuValue;
|
||||||
|
|
||||||
if (menu::beginMenuEx(Lang(name), std::next(menuItems.begin())->get() == ContentRegistry::Interface::impl::SubMenuValue ? icon : nullptr, isSubmenu ? enabledCallback() : true)) {
|
if (menu::beginMenuEx(Lang(name), std::next(menuItems.begin())->get() == ContentRegistry::Interface::impl::SubMenuValue ? icon : nullptr, isSubmenu ? enabledCallback() : true)) {
|
||||||
createNestedMenu({ std::next(menuItems.begin()), menuItems.end() }, icon, shortcut, callback, enabledCallback, selectedCallback);
|
createNestedMenu({ std::next(menuItems.begin()), menuItems.end() }, icon, shortcut, view, callback, enabledCallback, selectedCallback);
|
||||||
menu::endMenu();
|
menu::endMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,7 +287,7 @@ namespace hex::plugin::builtin {
|
|||||||
toolbarIndex
|
toolbarIndex
|
||||||
] = menuItem;
|
] = menuItem;
|
||||||
|
|
||||||
createNestedMenu(unlocalizedNames | std::views::drop(1), icon.glyph.c_str(), shortcut, callback, enabledCallback, selectedCallack);
|
createNestedMenu(unlocalizedNames | std::views::drop(1), icon.glyph.c_str(), shortcut, view, callback, enabledCallback, selectedCallack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,7 +572,7 @@ namespace hex::plugin::builtin {
|
|||||||
const auto &[unlocalizedNames, icon, shortcut, view, callback, enabledCallback, selectedCallback, toolbarIndex] = menuItem;
|
const auto &[unlocalizedNames, icon, shortcut, view, callback, enabledCallback, selectedCallback, toolbarIndex] = menuItem;
|
||||||
|
|
||||||
if (ImGui::BeginPopup(unlocalizedNames.front().get().c_str())) {
|
if (ImGui::BeginPopup(unlocalizedNames.front().get().c_str())) {
|
||||||
createNestedMenu({ unlocalizedNames.begin() + 1, unlocalizedNames.end() }, icon.glyph.c_str(), shortcut, callback, enabledCallback, selectedCallback);
|
createNestedMenu({ unlocalizedNames.begin() + 1, unlocalizedNames.end() }, icon.glyph.c_str(), shortcut, view, callback, enabledCallback, selectedCallback);
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user