Skip to content

Commit

Permalink
gui2/tchat_log: Add a button to copy the filtered page contents to cl…
Browse files Browse the repository at this point in the history
…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).
  • Loading branch information
irydacea committed Jun 12, 2014
1 parent 913333e commit 9b065fd
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog
Expand Up @@ -64,6 +64,7 @@ Version 1.13.0-dev:
WML in text form instead of a simplified version.
* Added a button to copy the currently displayed content from the :inspect
dialog to clipboard.
* Added a button to copy the in-game Chat Log dialog contents 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].
Expand Down
44 changes: 35 additions & 9 deletions data/gui/default/window/chat_log.cfg
Expand Up @@ -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;
1 change: 1 addition & 0 deletions players_changelog
Expand Up @@ -18,6 +18,7 @@ Version 1.13.0-dev:
* User interface:
* Classic Theme which restores the 1.10 UI.
* Made orb and minmap colors configurable by the game preferences.
* Added a button to copy the in-game Chat Log dialog contents to clipboard.

* Miscellaneous and bug fixes:
* Fixed halos glitching through locations that become shrouded after the
Expand Down
27 changes: 27 additions & 0 deletions src/gui/dialogs/chat_log.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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";
Expand All @@ -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()
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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_;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit 9b065fd

Please sign in to comment.