gui2/twml_error: Handle an optional list of faulty files separately

This allows us to be more self-contained and require less logic in the
instantiation site for preparing the report for display.

This requires adding a new row and label for displaying the list of
faulty files, which will be hidden when the list is empty or not
provided in the display() static member function.
This commit is contained in:
Ignacio R. Morelle 2014-02-11 23:06:06 -03:00
parent 9b26df2dbb
commit 458b36d007
3 changed files with 75 additions and 3 deletions

View file

@ -58,6 +58,22 @@
[/row]
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
id = "files"
definition = "default"
wrap = true
[/label]
[/column]
[/row]
[row]
[column]

View file

@ -14,7 +14,30 @@
#include "gui/dialogs/wml_error.hpp"
#include "addon/info.hpp"
#include "gui/auxiliary/find_widget.tpp"
#include "gui/widgets/control.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
#include "serialization/string_utils.hpp"
namespace
{
std::string format_file_list(const std::vector<std::string>& files)
{
if(files.empty()) {
return "";
}
if(files.size() == 1) {
return files.front();
}
return utils::bullet_list(files);
}
}
namespace gui2
{
@ -32,6 +55,11 @@ namespace gui2
* summary & & control & m &
* Label used for displaying a brief summary of the error(s). $
*
* files & & control & m &
* Label used to display the list of affected add-ons or files, if
* applicable. It is hidden otherwise. It is recommended to place it
* after the summary label. $
*
* details & & control & m &
* Full report of the parser or preprocessor error(s) found. $
*
@ -40,10 +68,22 @@ namespace gui2
REGISTER_DIALOG(wml_error)
twml_error::twml_error(const std::string& summary, const std::string& details)
twml_error::twml_error(const std::string& summary,
const std::vector<std::string>& files,
const std::string& details)
: have_files_(!files.empty())
{
register_label("summary", true, summary);
register_label("files", true, format_file_list(files));
register_label("details", true, details);
}
void twml_error::pre_show(CVideo& /*video*/, twindow& window)
{
if(!have_files_) {
tcontrol& filelist = find_widget<tcontrol>(&window, "files", false);
filelist.set_visible(tcontrol::tvisible::invisible);
}
}
} // end namespace gui2

View file

@ -22,19 +22,35 @@ namespace gui2 {
class twml_error : public tdialog
{
public:
twml_error(const std::string& summary, const std::string& details);
twml_error(const std::string& summary,
const std::vector<std::string>& files,
const std::string& details);
/** The display function; see @ref tdialog for more information. */
static void display(const std::string& summary,
const std::vector<std::string>& files,
const std::string& details,
CVideo& video)
{
twml_error(summary, files, details).show(video);
}
/** The display function; see @ref tdialog for more information. */
static void display(const std::string& summary,
const std::string& details,
CVideo& video)
{
twml_error(summary, details).show(video);
display(summary, std::vector<std::string>(), details, video);
}
private:
bool have_files_;
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
};
} // end namespace gui2