mirror of https://github.com/WerWolv/ImHex.git
fix: Properly fix possibility of no provider being selected when closing one
This commit is contained in:
parent
bcab657a06
commit
a62ede7840
|
@ -313,13 +313,37 @@ namespace hex {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!s_providers.empty()) {
|
if (!s_providers.empty()) {
|
||||||
if (it == s_providers.begin())
|
if (it == s_providers.begin()) {
|
||||||
|
// If the first provider is being closed, select the one that's the first one now
|
||||||
setCurrentProvider(0);
|
setCurrentProvider(0);
|
||||||
else if (std::distance(s_providers.begin(), it) < 0)
|
}
|
||||||
|
else if (std::distance(s_providers.begin(), it) == s_currentProvider) {
|
||||||
|
// If the current provider is being closed, select the one that's before it
|
||||||
setCurrentProvider(s_currentProvider - 1);
|
setCurrentProvider(s_currentProvider - 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// If any other provider is being closed, find the current provider in the list again and select it again
|
||||||
|
auto currentProvider = get();
|
||||||
|
auto currentIt = std::find(s_providers.begin(), s_providers.end(), currentProvider);
|
||||||
|
|
||||||
|
if (currentIt != s_providers.end()) {
|
||||||
|
auto newIndex = std::distance(s_providers.begin(), currentIt);
|
||||||
|
|
||||||
|
if (s_currentProvider == newIndex)
|
||||||
|
newIndex -= 1;
|
||||||
|
|
||||||
|
setCurrentProvider(newIndex);
|
||||||
|
} else {
|
||||||
|
// If the current provider is not in the list anymore, select the first one
|
||||||
|
setCurrentProvider(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s_providers.erase(it);
|
s_providers.erase(it);
|
||||||
|
if (s_currentProvider >= i64(s_providers.size()))
|
||||||
|
setCurrentProvider(0);
|
||||||
|
|
||||||
if (s_providers.empty())
|
if (s_providers.empty())
|
||||||
EventManager::post<EventProviderChanged>(provider, nullptr);
|
EventManager::post<EventProviderChanged>(provider, nullptr);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue