mirror of
https://github.com/aristocratos/btop.git
synced 2026-06-11 09:14:22 -04:00
Menu option to disable presets
refactor `current_preset` as `std::optional`
This commit is contained in:
@@ -253,22 +253,27 @@ namespace Input {
|
||||
Menu::show(Menu::Menus::SizeError);
|
||||
return;
|
||||
}
|
||||
Config::current_preset = -1;
|
||||
Config::current_preset.reset();
|
||||
Draw::calcSizes();
|
||||
Draw::update_clock(true);
|
||||
Runner::run("all", false, true);
|
||||
return;
|
||||
}
|
||||
else if (is_in(key, "p", "P") and Config::preset_list.size() > 1) {
|
||||
else if (is_in(key, "p", "P") and Config::getS("disable_presets") != "All") {
|
||||
if (Config::getS("disable_presets") == "Default" and Config::preset_list.size() <= 1) return;
|
||||
const auto old_preset = Config::current_preset;
|
||||
if (key == "p") {
|
||||
if (++Config::current_preset >= (int)Config::preset_list.size()) Config::current_preset = 0;
|
||||
}
|
||||
else {
|
||||
if (--Config::current_preset < 0) Config::current_preset = Config::preset_list.size() - 1;
|
||||
const int first_preset = (Config::getS("disable_presets") == "Default") ? 1 : 0;
|
||||
if (Config::getS("disable_presets") == "Custom") Config::current_preset = 0;
|
||||
else if (Config::current_preset.has_value()) {
|
||||
if (key == "p") {
|
||||
if(++(*Config::current_preset) >= static_cast<int>(Config::preset_list.size())) Config::current_preset = first_preset;
|
||||
}
|
||||
else if (--(*Config::current_preset) < first_preset) Config::current_preset = Config::preset_list.size() - 1;
|
||||
}
|
||||
else Config::current_preset = (key == "p") ? first_preset : Config::preset_list.size() - 1;
|
||||
if (Config::current_preset == old_preset) return;
|
||||
atomic_wait(Runner::active);
|
||||
if (not Config::apply_preset(Config::preset_list.at(Config::current_preset))) {
|
||||
if (not Config::apply_preset(Config::preset_list.at(Config::current_preset.value()))) {
|
||||
Menu::show(Menu::Menus::SizeError);
|
||||
Config::current_preset = old_preset;
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user