gui2/tgamestate_inspector: Add a button to copy contents to clipboard

This copies the contents of the main display area to clipboard. The
button currently lacks a tooltip because the tooltip causes map labels
to glitch through the dialog when displayed (noticeable in e.g. the test
scenario). I'll file a bug for this issue later using a (commented-out)
line introduced by this commit as a test case.
This commit is contained in:
Ignacio R. Morelle 2014-06-05 00:25:47 -04:00
parent 0e9f18d8eb
commit eab3e6fb64
3 changed files with 65 additions and 13 deletions

View file

@ -62,6 +62,8 @@ Version 1.13.0-dev:
* 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:
* Added customizable recall costs for unit types and individual units,
using the new recall_cost attribute in [unit_type] and [unit].

View file

@ -204,29 +204,54 @@
[column]
grow_factor = 6
border = "all"
border_size = 5
vertical_alignment = "top"
horizontal_alignment = "left"
[grid]
[row]
[column]
#
# Emulate the listbox headers' top/bottom padding
# here relative to the scroll_label below.
#
border = "top,bottom"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = _ "Contents"
[/label]
horizontal_grow = "true"
[grid]
[row]
[column]
#
# Emulate the listbox headers' top/bottom padding
# here relative to the scroll_label below.
#
border = "top,left,right"
border_size = 5
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]
[/row]
[row]
[column]
border = "left,bottom,right"
border_size = 5
horizontal_alignment = "left"
[scroll_label]
id = "inspect"
definition = "default"

View file

@ -26,6 +26,8 @@
#endif
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
#include "clipboard.hpp"
#include "serialization/parser.hpp" // for write()
#include "utils/foreach.tpp"
@ -72,6 +74,9 @@ namespace gui2
* inspect & & control & m &
* The state of the variable or event. $
*
* copy & & button & m &
* A button to copy the state to clipboard. $
*
* @end{table}
*/
@ -118,6 +123,7 @@ public:
, stuff_types_list()
, inspect()
, inspector_name()
, copy_button()
{
name = cfg["name"].str();
}
@ -129,6 +135,7 @@ public:
tlistbox* stuff_types_list;
tcontrol* inspect;
tcontrol* inspector_name;
tbutton* copy_button;
void clear_stuff_list()
@ -572,6 +579,11 @@ public:
c->update_view_from_model(); // TODO: 'activate'
}
void handle_copy_button_clicked()
{
copy_to_clipboard(model_.inspect->label(), false);
}
private:
model& model_;
@ -605,6 +617,11 @@ public:
controller_.handle_stuff_types_list_item_clicked();
}
void handle_copy_button_clicked(twindow& /*window*/)
{
controller_.handle_copy_button_clicked();
}
void bind(twindow& window)
{
@ -615,6 +632,8 @@ public:
model_.inspect = find_widget<tcontrol>(&window, "inspect", false, true);
model_.inspector_name
= &find_widget<tcontrol>(&window, "inspector_name", false);
model_.copy_button
= &find_widget<tbutton>(&window, "copy", false);
#ifdef GUI2_EXPERIMENTAL_LISTBOX
connect_signal_notify_modified(
@ -642,6 +661,12 @@ public:
&tgamestate_inspector::view::
handle_stuff_types_list_item_clicked>);
#endif
connect_signal_mouse_left_click(
*model_.copy_button,
boost::bind(&tgamestate_inspector::view::handle_copy_button_clicked,
this,
boost::ref(window)));
}
private: