feat: Added shortcut to switch between providers
This commit is contained in:
parent
be8c679d4a
commit
f79e2df11a
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user