The Battle for Wesnoth  1.15.12+dev
depcheck_select_new.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2018 by Boldizs√°r Lipka <lipkab@zoho.com>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
20 #include "gui/widgets/settings.hpp"
21 #include "gui/widgets/window.hpp"
22 #include "gui/widgets/listbox.hpp"
23 #include "gettext.hpp"
24 
25 namespace gui2::dialogs
26 {
27 
28 REGISTER_DIALOG(depcheck_select_new)
29 
31  ng::depcheck::component_type name,
32  const std::vector<std::string>& items)
33  : items_(items), result_(-1)
34 {
35 
36  std::string message;
37 
38  switch(name) {
40  message = _("The currently chosen scenario "
41  "is not compatible with your setup."
42  "\nPlease select a compatible one.");
43  break;
44  case ng::depcheck::ERA:
45  message = _("The currently chosen era "
46  "is not compatible with your setup."
47  "\nPlease select a compatible one.");
48  break;
50  // currently this can't happen, but be prepared for anything...
51  message = _("The currently chosen modification "
52  "is not compatible with your setup."
53  "\nPlease select a compatible one.");
54  }
55 
56  register_label("message", false, message);
57 }
58 
60 {
61  listbox& items = find_widget<listbox>(&window, "itemlist", false);
62 
63  for(const auto & item : items_)
64  {
65  std::map<std::string, string_map> data;
66  data["option"]["label"] = item;
67 
68  items.add_row(data);
69  }
70 
71  items.select_row(0);
72 }
73 
75 {
76  if(get_retval() == retval::OK) {
77  listbox& items = find_widget<listbox>(&window, "itemlist", false);
78  result_ = items.get_selected_row();
79  }
80 }
81 } // namespace dialogs
int result_
the index of the selected item
Main class to show messages to the user.
Definition: message.hpp:34
This file contains the window object, this object is a top level container which has the event manage...
STL namespace.
const std::vector< std::string > items
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:276
static std::string _(const char *str)
Definition: gettext.hpp:92
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition: listbox.cpp:251
The listbox class.
Definition: listbox.hpp:42
This file contains the settings handling of the widget library.
std::vector< std::string > items_
the options available
Offers a list of compatible items if a currently selected one is incompatible.
grid & add_row(const string_map &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:67
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
int get_retval() const
Returns the cached window exit code.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Dialog was closed with the OK button.
Definition: retval.hpp:34
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:64
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:409