Merge branch 'feature/inspect-copy-paste'

This commit is contained in:
Ignacio R. Morelle 2014-06-09 18:14:25 -04:00
commit 03021c0482
3 changed files with 88 additions and 19 deletions

View File

@ -60,6 +60,10 @@ Version 1.13.0-dev:
* Changed: A listbox can now update its size when rows are added. * Changed: A listbox can now update its size when rows are added.
* Changed: Avoid listboxes to handle mouse clicks twice. * Changed: Avoid listboxes to handle mouse clicks twice.
* Fixed bug #22144: An assertion failure with empty labels in a listbox. * Fixed bug #22144: An assertion failure with empty labels in a listbox.
* The :inspect dialog now uses the same function as saved games to generate
WML in text form instead of a simplified version.
* Added a button to copy the currently displayed content from the :inspect
dialog to clipboard.
* WML engine: * WML engine:
* Added customizable recall costs for unit types and individual units, * Added customizable recall costs for unit types and individual units,
using the new recall_cost attribute in [unit_type] and [unit]. using the new recall_cost attribute in [unit_type] and [unit].

View File

@ -204,29 +204,54 @@
[column] [column]
grow_factor = 6 grow_factor = 6
border = "all"
border_size = 5
vertical_alignment = "top" vertical_alignment = "top"
horizontal_alignment = "left" horizontal_alignment = "left"
[grid] [grid]
[row] [row]
[column] [column]
# horizontal_grow = "true"
# Emulate the listbox headers' top/bottom padding [grid]
# here relative to the scroll_label below. [row]
# [column]
border = "top,bottom" #
border_size = 5 # Emulate the listbox headers' top/bottom padding
horizontal_alignment = "left" # here relative to the scroll_label below.
[label] #
definition = "default" border = "top,left,right"
label = _ "Contents" border_size = 5
[/label] horizontal_alignment = "left"
[label]
definition = "default"
label = _ "Contents"
[/label]
[/column]
[column]
border = "top,left,right"
border_size = 5
horizontal_alignment = "right"
[button]
id = "copy"
definition = "action_copy"
label = _ "clipboard^Copy"
# FIXME: tooltips cause weird interactions with map
# labels while running a GUI2 dialog, so let's
# not use a tooltip yet.
#tooltip = _ "Copy this report to clipboard"
[/button]
[/column]
[/row]
[/grid]
[/column] [/column]
[/row] [/row]
[row] [row]
[column] [column]
border = "left,bottom,right"
border_size = 5
horizontal_alignment = "left" horizontal_alignment = "left"
[scroll_label] [scroll_label]
id = "inspect" id = "inspect"
definition = "default" definition = "default"

View File

@ -26,6 +26,9 @@
#endif #endif
#include "gui/widgets/settings.hpp" #include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp" #include "gui/widgets/window.hpp"
#include "clipboard.hpp"
#include "serialization/parser.hpp" // for write()
#include "utils/foreach.tpp" #include "utils/foreach.tpp"
#include "../../gamestatus.hpp" #include "../../gamestatus.hpp"
@ -37,6 +40,18 @@
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
namespace
{
inline std::string config_to_string(const config& cfg)
{
std::ostringstream s;
write(s, cfg);
return s.str();
}
}
namespace gui2 namespace gui2
{ {
@ -59,6 +74,9 @@ namespace gui2
* inspect & & control & m & * inspect & & control & m &
* The state of the variable or event. $ * The state of the variable or event. $
* *
* copy & & button & m &
* A button to copy the state to clipboard. $
*
* @end{table} * @end{table}
*/ */
@ -70,7 +88,7 @@ static void inspect_ai(twindow& window, int side)
NEW_find_widget<tcontrol>( NEW_find_widget<tcontrol>(
&window, &window,
"inspect", "inspect",
false).set_label(ai_cfg.debug()); false).set_label(config_to_string(ai_cfg.debug));
} }
*/ */
@ -105,6 +123,7 @@ public:
, stuff_types_list() , stuff_types_list()
, inspect() , inspect()
, inspector_name() , inspector_name()
, copy_button()
{ {
name = cfg["name"].str(); name = cfg["name"].str();
} }
@ -116,6 +135,7 @@ public:
tlistbox* stuff_types_list; tlistbox* stuff_types_list;
tcontrol* inspect; tcontrol* inspect;
tcontrol* inspector_name; tcontrol* inspector_name;
tbutton* copy_button;
void clear_stuff_list() void clear_stuff_list()
@ -243,7 +263,7 @@ public:
FOREACH(const AUTO & c, vars.all_children_range()) FOREACH(const AUTO & c, vars.all_children_range())
{ {
if(selected == i) { if(selected == i) {
model_.set_inspect_window_text(c.cfg.debug()); model_.set_inspect_window_text(config_to_string(c.cfg));
return; return;
} }
i++; i++;
@ -317,7 +337,9 @@ public:
if(selected == i) { if(selected == i) {
config c_unit; config c_unit;
u->write(c_unit); u->write(c_unit);
model_.set_inspect_window_text(c_unit.debug()); std::ostringstream cfg_str;
write(cfg_str, c_unit);
model_.set_inspect_window_text(cfg_str.str());
return; return;
} }
i++; i++;
@ -375,7 +397,7 @@ public:
: config(); : config();
c.clear_children("ai"); c.clear_children("ai");
c.clear_children("village"); c.clear_children("village");
model_.set_inspect_window_text(c.debug()); model_.set_inspect_window_text(config_to_string(c));
return; return;
} }
@ -387,7 +409,7 @@ public:
if(selected == 2) { if(selected == 2) {
model_.set_inspect_window_text( model_.set_inspect_window_text(
ai::manager::to_config(side_).debug()); config_to_string(ai::manager::to_config(side_)));
return; return;
} }
@ -427,7 +449,7 @@ public:
u.write(c_unit); u.write(c_unit);
c.add_child("unit", c_unit); c.add_child("unit", c_unit);
} }
model_.set_inspect_window_text(c.debug()); model_.set_inspect_window_text(config_to_string(c));
return; return;
} }
@ -557,6 +579,11 @@ public:
c->update_view_from_model(); // TODO: 'activate' c->update_view_from_model(); // TODO: 'activate'
} }
void handle_copy_button_clicked()
{
copy_to_clipboard(model_.inspect->label(), false);
}
private: private:
model& model_; model& model_;
@ -590,6 +617,11 @@ public:
controller_.handle_stuff_types_list_item_clicked(); controller_.handle_stuff_types_list_item_clicked();
} }
void handle_copy_button_clicked(twindow& /*window*/)
{
controller_.handle_copy_button_clicked();
}
void bind(twindow& window) void bind(twindow& window)
{ {
@ -600,6 +632,8 @@ public:
model_.inspect = find_widget<tcontrol>(&window, "inspect", false, true); model_.inspect = find_widget<tcontrol>(&window, "inspect", false, true);
model_.inspector_name model_.inspector_name
= &find_widget<tcontrol>(&window, "inspector_name", false); = &find_widget<tcontrol>(&window, "inspector_name", false);
model_.copy_button
= &find_widget<tbutton>(&window, "copy", false);
#ifdef GUI2_EXPERIMENTAL_LISTBOX #ifdef GUI2_EXPERIMENTAL_LISTBOX
connect_signal_notify_modified( connect_signal_notify_modified(
@ -627,6 +661,12 @@ public:
&tgamestate_inspector::view:: &tgamestate_inspector::view::
handle_stuff_types_list_item_clicked>); handle_stuff_types_list_item_clicked>);
#endif #endif
connect_signal_mouse_left_click(
*model_.copy_button,
boost::bind(&tgamestate_inspector::view::handle_copy_button_clicked,
this,
boost::ref(window)));
} }
private: private: