Browse files

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.
  • Loading branch information...
1 parent 821feef commit 6a56da5f0f60558f0c15206a92b91a612a4dc5da @shikadilord shikadilord committed Jun 5, 2014
Showing with 65 additions and 13 deletions.
  1. +2 −0 changelog
  2. +38 −13 data/gui/default/window/gamestate_inspector.cfg
  3. +25 −0 src/gui/dialogs/gamestate_inspector.cpp
View
2 changelog
@@ -22,6 +22,8 @@ Version 1.11.15+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:
* Fixed a regression in 1.11.14 causing WML parser/preprocessor errors to
not interrupt the game load sequence or display an error message in-game,
View
51 data/gui/default/window/gamestate_inspector.cfg
@@ -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
25 src/gui/dialogs/gamestate_inspector.cpp
@@ -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}
*/
@@ -120,6 +125,7 @@ class tgamestate_inspector::model
, stuff_types_list()
, inspect()
, inspector_name()
+ , copy_button()
{
name = cfg["name"].str();
}
@@ -131,6 +137,7 @@ class tgamestate_inspector::model
tlistbox* stuff_types_list;
tcontrol* inspect;
tcontrol* inspector_name;
+ tbutton* copy_button;
void clear_stuff_list()
@@ -574,6 +581,11 @@ class tgamestate_inspector::controller
c->update_view_from_model(); // TODO: 'activate'
}
+ void handle_copy_button_clicked()
+ {
+ copy_to_clipboard(model_.inspect->label(), false);
+ }
+
private:
model& model_;
@@ -610,6 +622,11 @@ class tgamestate_inspector::view
window.invalidate_layout(); // workaround for assertion failure
}
+ void handle_copy_button_clicked(twindow& /*window*/)
+ {
+ controller_.handle_copy_button_clicked();
+ }
+
void bind(twindow& window)
{
@@ -620,6 +637,8 @@ class tgamestate_inspector::view
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(
@@ -649,6 +668,12 @@ class tgamestate_inspector::view
&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:

0 comments on commit 6a56da5

Please sign in to comment.