diff --git a/lib/libimhex/include/hex/api/imhex_api.hpp b/lib/libimhex/include/hex/api/imhex_api.hpp index ae8e25146..db2e69777 100644 --- a/lib/libimhex/include/hex/api/imhex_api.hpp +++ b/lib/libimhex/include/hex/api/imhex_api.hpp @@ -261,6 +261,12 @@ namespace hex { */ void setCurrentProvider(u32 index); + /** + * @brief Gets the index of the currently selected data provider + * @return Index of the selected provider + */ + i64 getCurrentProviderIndex(); + /** * @brief Checks whether the currently selected data provider is valid * @return Whether the currently selected data provider is valid diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index 9b52e914b..f8988b4b3 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -255,6 +255,10 @@ namespace hex { } } + i64 getCurrentProviderIndex() { + return s_currentProvider; + } + bool isValid() { return !s_providers.empty() && s_currentProvider >= 0 && s_currentProvider < i64(s_providers.size()); } diff --git a/plugins/builtin/source/content/ui_items.cpp b/plugins/builtin/source/content/ui_items.cpp index b7ea14118..7a24ab1e4 100644 --- a/plugins/builtin/source/content/ui_items.cpp +++ b/plugins/builtin/source/content/ui_items.cpp @@ -142,6 +142,21 @@ namespace hex::plugin::builtin { } void addToolbarItems() { + ShortcutManager::addGlobalShortcut(AllowWhileTyping + ALT + CTRLCMD + Keys::Left, []{ + auto currIndex = ImHexApi::Provider::getCurrentProviderIndex(); + + if (currIndex > 0) + ImHexApi::Provider::setCurrentProvider(currIndex - 1); + }); + + ShortcutManager::addGlobalShortcut(AllowWhileTyping + ALT + CTRLCMD + Keys::Right, []{ + auto currIndex = ImHexApi::Provider::getCurrentProviderIndex(); + + const auto &providers = ImHexApi::Provider::getProviders(); + if (currIndex < i64(providers.size() - 1)) + ImHexApi::Provider::setCurrentProvider(currIndex + 1); + }); + ContentRegistry::Interface::addToolbarItem([] { auto provider = ImHexApi::Provider::get(); bool providerValid = provider != nullptr; @@ -236,13 +251,22 @@ namespace hex::plugin::builtin { if (providerSelectorVisible) { for (size_t i = 0; i < providers.size(); i++) { auto &tabProvider = providers[i]; + const auto selectedProviderIndex = ImHexApi::Provider::getCurrentProviderIndex(); bool open = true; ImGui::PushID(tabProvider); - if (ImGui::BeginTabItem(tabProvider->getName().c_str(), &open, ImGuiTabItemFlags_NoTooltip | (tabProvider->isDirty() ? ImGuiTabItemFlags_UnsavedDocument : ImGuiTabItemFlags_None))) { - ImHexApi::Provider::setCurrentProvider(i); + + ImGuiTabItemFlags flags = ImGuiTabItemFlags_NoTooltip; + if (tabProvider->isDirty()) + flags |= ImGuiTabItemFlags_UnsavedDocument; + if (i64(i) == selectedProviderIndex) + flags |= ImGuiTabItemFlags_SetSelected; + + if (ImGui::BeginTabItem(tabProvider->getName().c_str(), &open, flags)) { ImGui::EndTabItem(); } + if (ImGui::IsItemClicked()) + ImHexApi::Provider::setCurrentProvider(i); if (ImGui::InfoTooltip()) { ImGui::BeginTooltip();