The Battle for Wesnoth  1.19.5+dev
uninstall_list.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2024
3  by Iris Morelle <shadowm2006@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
17 
18 #include "gui/widgets/grid.hpp"
19 #include "gui/widgets/listbox.hpp"
21 #include "gui/widgets/window.hpp"
22 
23 
24 namespace gui2::dialogs
25 {
26 
27 REGISTER_DIALOG(addon_uninstall_list)
28 
29 void addon_uninstall_list::pre_show()
30 {
31  listbox& list = find_widget<listbox>("addons_list");
32  keyboard_capture(&list);
33  selections_.clear();
34 
35  for(const auto & entry : titles_map_)
36  {
37  const std::string& id = entry.first;
38  const std::string& title = entry.second;
39 
40  ids_.push_back(id);
41  selections_[id] = false;
42 
44  widget_item column;
45 
46  column["label"] = title;
47  data.emplace("name", column);
48 
49  list.add_row(data);
50  }
51 }
52 
54 {
55  const listbox& list = find_widget<listbox>("addons_list");
56  const unsigned rows = list.get_item_count();
57 
58  assert(rows == ids_.size() && rows == titles_map_.size());
59 
60  if(!rows || get_retval() != retval::OK) {
61  return;
62  }
63 
64  for(unsigned k = 0; k < rows; ++k) {
65  const grid* g = list.get_row_grid(k);
66  const toggle_button& checkbox
67  = g->find_widget<const toggle_button>("checkbox");
68  selections_[ids_[k]] = checkbox.get_value_bool();
69  }
70 }
71 
72 std::vector<std::string> addon_uninstall_list::selected_addons() const
73 {
74  std::vector<std::string> retv;
75 
76  for(const auto & entry : selections_)
77  {
78  if(entry.second) {
79  retv.push_back(entry.first);
80  }
81  }
82 
83  return retv;
84 }
85 
86 } // namespace dialogs
double g
Definition: astarsearch.cpp:63
virtual void post_show() override
Actions to be taken after the window has been shown.
std::map< std::string, bool > selections_
std::vector< std::string > selected_addons() const
std::vector< std::string > ids_
std::map< std::string, std::string > titles_map_
int get_retval() const
Returns the cached window exit code.
Base container class.
Definition: grid.hpp:32
The listbox class.
Definition: listbox.hpp:43
grid & add_row(const widget_item &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
Definition: listbox.cpp:58
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
Definition: listbox.cpp:229
unsigned get_item_count() const
Returns the number of items in the listbox.
Definition: listbox.cpp:123
std::string id
Text to match against addon_info.tags()
Definition: manager.cpp:198
This file contains the window object, this object is a top level container which has the event manage...
REGISTER_DIALOG(editor_edit_unit)
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:36
std::map< std::string, t_string > widget_item
Definition: widget.hpp:33
@ OK
Dialog was closed with the OK button.
Definition: retval.hpp:35
std::string_view data
Definition: picture.cpp:178