Permalink
Browse files

gui2/tchat_log: Add a button to copy the filtered page contents to cl…

…ipboard

This copies the current contents of the dialog to clipboard. The button
currently lacks a tooltip because the tooltip has the potential to cause
map labels to glitch through the dialog when displayed (see commit
eab3e6f and bug #22176).

(The tooltip should also remain commented-out because this is a backport
to 1.12.)
  • Loading branch information...
1 parent 16e642b commit 799e09d94a4774854ddd29fbb9bd1362105da9cd @shikadilord shikadilord committed Jun 12, 2014
Showing with 64 additions and 9 deletions.
  1. +1 −0 changelog
  2. +35 −9 data/gui/default/window/chat_log.cfg
  3. +1 −0 players_changelog
  4. +27 −0 src/gui/dialogs/chat_log.cpp
View
@@ -31,6 +31,7 @@ Version 1.11.15+dev:
* Fixed most of the minimap buttons and the End Turn button appearing
without contents or in the wrong state during WML start events until they
are interacted with or control is given to the player for the first time.
+ * Added a button to copy the in-game Chat Log dialog contents 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,
@@ -162,17 +162,43 @@
grow_factor = 0
[column]
- grow_factor = 0
- border = "all"
- border_size = 5
- horizontal_alignment = "right"
- [button]
- id = "cancel"
- definition = "default"
- label = _ "Close"
- [/button]
+ horizontal_grow = "true"
+
+ [grid]
+ [row]
+ [column]
+ grow_factor = 0
+ border = "all"
+ border_size = 5
+ horizontal_alignment = "left"
+ [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 log to clipboard"
+ [/button]
+ [/column]
+
+ [column]
+ grow_factor = 0
+ border = "all"
+ border_size = 5
+ horizontal_alignment = "right"
+ [button]
+ id = "cancel"
+ definition = "default"
+ label = _ "Close"
+ [/button]
+ [/column]
+ [/row]
+ [/grid]
[/column]
[/row]
[/grid]
[/resolution]
[/window]
+
+# kate: indent-mode normal; encoding utf-8; space-indent on;
View
@@ -10,6 +10,7 @@ Version 1.11.15+dev:
* Fixed most of the minimap buttons and the End Turn button appearing
without contents or in the wrong state during WML start events until they
are interacted with or control is given to the player for the first time.
+ * Added a button to copy the in-game Chat Log dialog contents to clipboard.
* WML engine:
* Fixed a regression in 1.11.14 causing WML parser/preprocessor errors to
@@ -30,6 +30,7 @@
#include "gui/widgets/slider.hpp"
#include "utils/foreach.tpp"
+#include "../../clipboard.hpp"
#include "../../game_preferences.hpp"
#include "../../gamestatus.hpp"
#include "../../log.hpp"
@@ -77,6 +78,7 @@ class tchat_log::model
, previous_page()
, next_page()
, filter()
+ , copy_button()
{
LOG_CHAT_LOG << "entering tchat_log::model...\n";
LOG_CHAT_LOG << "finished tchat_log::model...\n";
@@ -91,6 +93,7 @@ class tchat_log::model
tbutton* previous_page;
tbutton* next_page;
ttext_box* filter;
+ tbutton* copy_button;
void clear_chat_msg_list()
{
@@ -192,6 +195,13 @@ class tchat_log::model
stream_log(s, first, last);
msg_label->set_label(s.str());
}
+
+ void chat_message_list_to_clipboard(int first, int last)
+ {
+ std::ostringstream s;
+ stream_log(s, first, last, true);
+ copy_to_clipboard(s.str(), false);
+ }
};
// The controller acts upon the model. It retrieves data from repositories,
@@ -305,6 +315,11 @@ class tchat_log::controller
<< std::endl;
}
+ void handle_copy_button_clicked()
+ {
+ const std::pair<int, int>& range = calculate_log_line_range();
+ model_.chat_message_list_to_clipboard(range.first, range.second);
+ }
private:
model& model_;
@@ -352,6 +367,11 @@ class tchat_log::view
window.invalidate_layout(); // workaround for assertion failure
}
+ void handle_copy_button_clicked(twindow& /*window*/)
+ {
+ controller_.handle_copy_button_clicked();
+ }
+
void bind(twindow& window)
{
LOG_CHAT_LOG << "Entering tchat_log::view::bind" << std::endl;
@@ -378,6 +398,13 @@ class tchat_log::view
boost::bind(&view::filter, this, boost::ref(window)));
window.keyboard_capture(model_.filter);
+ model_.copy_button = &find_widget<tbutton>(&window, "copy", false);
+ connect_signal_mouse_left_click(
+ *model_.copy_button,
+ boost::bind(&view::handle_copy_button_clicked,
+ this,
+ boost::ref(window)));
+
LOG_CHAT_LOG << "Exiting tchat_log::view::bind" << std::endl;
}

0 comments on commit 799e09d

Please sign in to comment.