Skip to content

Commit

Permalink
gui2/twml_error: Handle an optional list of faulty files separately
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
irydacea committed Feb 13, 2014
1 parent 9b26df2 commit 458b36d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
16 changes: 16 additions & 0 deletions data/gui/default/window/wml_error.cfg
Expand Up @@ -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]
Expand Down
42 changes: 41 additions & 1 deletion src/gui/dialogs/wml_error.cpp
Expand Up @@ -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
{
Expand All @@ -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. $
*
Expand All @@ -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
20 changes: 18 additions & 2 deletions src/gui/dialogs/wml_error.hpp
Expand Up @@ -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, details).show(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)
{
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
Expand Down

0 comments on commit 458b36d

Please sign in to comment.