sculpt: sanitize depot-user selection

Should the selected depot user not be present in the depot - for example
after switching the sculpt partition to another - unfold the selection
of all present depot users so that the one can pick an existing one.

Issue #4820
This commit is contained in:
Norman Feske 2023-04-27 14:52:59 +02:00
parent 091db48843
commit 280fc45c5f
4 changed files with 27 additions and 1 deletions

View File

@ -407,6 +407,7 @@ struct Sculpt::Main : Input_event_handler,
{
_scan_rom.update();
_popup_dialog.depot_users_scan_updated();
_system_dialog.sanitize_user_selection();
}
Attached_rom_dataspace _image_index_rom { _env, "report -> runtime/depot_query/image_index" };

View File

@ -39,6 +39,8 @@ struct Sculpt::Depot_users_dialog
using Url_edit_field = Text_entry_field<50>;
User const _default_user;
Depot_users const &_depot_users;
Action &_action;
@ -227,7 +229,8 @@ struct Sculpt::Depot_users_dialog
User const &default_user,
Action &action)
:
_depot_users(depot_users), _action(action), _selected(default_user)
_default_user(default_user), _depot_users(depot_users),
_action(action), _selected(default_user)
{ }
User selected() const
@ -325,6 +328,24 @@ struct Sculpt::Depot_users_dialog
}
bool one_selected() const { return !_unfolded && _selected.length() > 1; }
void sanitize_unfold_state()
{
/*
* If the selected depot user does not exist in the depot, show
* list of available users.
*/
bool selected_user_exists = false;
_depot_users.xml().for_each_sub_node([&] (Xml_node const &user) {
if (_selected == user.attribute_value("name", User()))
selected_user_exists = true; });
if (!selected_user_exists) {
_selected = _default_user;
_unfolded = true;
}
}
};
#endif /* _VIEW__DEPOT_USERS_DIALOG_H_ */

View File

@ -356,6 +356,8 @@ struct Sculpt::Software_update_dialog
bool keyboard_needed() const { return _users.keyboard_needed(); }
void handle_key(Codepoint c) { _users.handle_key(c); }
void sanitize_user_selection() { _users.sanitize_unfold_state(); }
};
#endif /* _VIEW__SOFTWARE_UPDATE_DIALOG_H_ */

View File

@ -137,6 +137,8 @@ struct Sculpt::System_dialog : Noncopyable, Dialog
bool keyboard_needed() const { return _update_dialog.keyboard_needed(); }
void handle_key(Codepoint c) { _update_dialog.handle_key(c); }
void sanitize_user_selection() { _update_dialog.sanitize_user_selection(); }
};
#endif /* _VIEW__SYSTEM_DIALOG_H_ */