helpers: cleanup properly if action throws an exception
This commit is contained in:
@@ -118,17 +118,27 @@ template <typename T, typename F>
|
||||
void withUnfilteredMenu(NC::Menu<T> &m, F action)
|
||||
{
|
||||
bool is_filtered = m.isFiltered();
|
||||
m.showAll();
|
||||
action();
|
||||
auto cleanup = [&]() {
|
||||
if (is_filtered)
|
||||
m.showFiltered();
|
||||
};
|
||||
m.showAll();
|
||||
try
|
||||
{
|
||||
action();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
cleanup();
|
||||
throw;
|
||||
}
|
||||
cleanup();
|
||||
}
|
||||
|
||||
template <typename T, typename F>
|
||||
void withUnfilteredMenuReapplyFilter(NC::Menu<T> &m, F action)
|
||||
{
|
||||
m.showAll();
|
||||
action();
|
||||
auto cleanup = [&]() {
|
||||
if (m.getFilter())
|
||||
{
|
||||
m.applyCurrentFilter(m.begin(), m.end());
|
||||
@@ -138,6 +148,18 @@ void withUnfilteredMenuReapplyFilter(NC::Menu<T> &m, F action)
|
||||
m.clearFilterResults();
|
||||
}
|
||||
}
|
||||
};
|
||||
m.showAll();
|
||||
try
|
||||
{
|
||||
action();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
cleanup();
|
||||
throw;
|
||||
}
|
||||
cleanup();
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
|
||||
Reference in New Issue
Block a user