Addons Manager: only reload cache if needed

This commit is contained in:
Charles Dang 2017-02-19 00:38:24 +11:00
parent b11ff9689b
commit 1c4102abad
3 changed files with 19 additions and 4 deletions

View File

@ -782,7 +782,7 @@ bool addons_manager_ui(CVideo& v, const std::string& remote_address)
//if(gui2::new_widgets) {
gui2::dialogs::addon_manager dlg(client);
dlg.show(v);
return true;
return dlg.get_need_wml_cache_refresh_();
//}
if(!get_addons_list(client, addons)) {

View File

@ -217,6 +217,7 @@ addon_manager::addon_manager(addons_client& client)
, client_(client)
, addons_()
, tracking_info_()
, need_wml_cache_refresh_(false)
{
status_filter_types_ = {
{FILTER_ALL, _("addons_view^All Add-ons")},
@ -420,7 +421,9 @@ void addon_manager::pre_show(window& window)
void addon_manager::load_addon_list(window& window)
{
if(need_wml_cache_refresh_) {
refresh_addon_version_info_cache();
}
client_.request_addons_list(cfg_);
if(!cfg_) {
@ -514,10 +517,13 @@ void addon_manager::install_addon(addon_info addon, window& window)
{
addon_list& addons = find_widget<addon_list>(&window, "addons", false);
addons_client::install_result result =
client_.install_addon_with_checks(addons_, addon);
addons_client::install_result result = client_.install_addon_with_checks(addons_, addon);
need_wml_cache_refresh_ |= result.wml_changed; // take note if any wml_changes occurred
if(result.outcome != addons_client::install_outcome::abort) {
need_wml_cache_refresh_ = true;
load_addon_list(window);
// Reselect the add-on.
@ -554,6 +560,8 @@ void addon_manager::uninstall_addon(addon_info addon, window& window)
if(!success) {
show_error_message(window.video(), _("The following add-on could not be deleted properly:") + " " + addon.display_title());
} else {
need_wml_cache_refresh_ = true;
load_addon_list(window);
// Reselect the add-on.

View File

@ -38,6 +38,11 @@ class addon_manager : public modal_dialog
public:
explicit addon_manager(addons_client& client);
bool get_need_wml_cache_refresh_() const
{
return need_wml_cache_refresh_;
}
private:
void on_filtertext_changed(text_box_base* textbox, const std::string& text);
@ -65,6 +70,8 @@ private:
std::vector<std::pair<ADDON_STATUS_FILTER, std::string>> status_filter_types_;
std::vector<std::pair<ADDON_TYPE, std::string>> type_filter_types_;
bool need_wml_cache_refresh_;
void install_selected_addon(window& window);
void install_addon(addon_info addon, window& window);