Add /clear chat command
This commit is contained in:
parent
560f70cfa2
commit
4a8d098a12
7 changed files with 23 additions and 2 deletions
|
@ -135,4 +135,8 @@ void chat_command_handler::do_info() {
|
|||
chat_handler_.send_to_server(data);
|
||||
}
|
||||
|
||||
void chat_command_handler::do_clear_messages() {
|
||||
chat_handler_.clear_messages();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ protected:
|
|||
void do_remove();
|
||||
void do_display();
|
||||
void do_version();
|
||||
void do_clear_messages();
|
||||
|
||||
/** Request information about a user from the server. */
|
||||
void do_info();
|
||||
|
@ -113,6 +114,8 @@ protected:
|
|||
_("Display version information."));
|
||||
register_command("info", &chat_command_handler::do_info,
|
||||
_("Request information about a nickname."), _("<nickname>"));
|
||||
register_command("clear", &chat_command_handler::do_clear_messages,
|
||||
_("Clear chat history."));
|
||||
}
|
||||
private:
|
||||
chat_handler& chat_handler_;
|
||||
|
|
|
@ -64,6 +64,8 @@ protected:
|
|||
|
||||
void change_logging(const std::string& data);
|
||||
|
||||
virtual void clear_messages() = 0;
|
||||
|
||||
friend class chat_command_handler;
|
||||
};
|
||||
|
||||
|
|
|
@ -226,8 +226,9 @@ void chatbox::append_to_chatbox(const std::string& text, std::size_t id, const b
|
|||
const bool chatbox_at_end = log.vertical_scrollbar_at_end();
|
||||
const unsigned chatbox_position = log.get_vertical_scrollbar_item_position();
|
||||
|
||||
const std::string before_message = log.get_label().empty() ? "" : "\n";
|
||||
const std::string new_text = formatter()
|
||||
<< log.get_label() << "\n" << "<span color='#bcb088'>" << preferences::get_chat_timestamp(std::time(0)) << text << "</span>";
|
||||
<< log.get_label() << before_message << "<span color='#bcb088'>" << preferences::get_chat_timestamp(std::time(0)) << text << "</span>";
|
||||
|
||||
log.set_use_markup(true);
|
||||
log.set_label(new_text);
|
||||
|
@ -255,6 +256,14 @@ void chatbox::send_chat_message(const std::string& message, bool /*allies_only*/
|
|||
send_to_server(c);
|
||||
}
|
||||
|
||||
void chatbox::clear_messages()
|
||||
{
|
||||
const auto id = active_window_;
|
||||
grid& grid = chat_log_container_->page_grid(id);
|
||||
scroll_label& log = find_widget<scroll_label>(&grid, "log_text", false);
|
||||
log.set_label("");
|
||||
}
|
||||
|
||||
void chatbox::user_relation_changed(const std::string& /*name*/)
|
||||
{
|
||||
if(active_window_changed_callback_) {
|
||||
|
|
|
@ -205,6 +205,8 @@ public:
|
|||
/** Inherited form @ref chat_handler */
|
||||
virtual void send_chat_message(const std::string& message, bool allies_only) override;
|
||||
|
||||
virtual void clear_messages() override;
|
||||
|
||||
/**
|
||||
* Switch to the window given by a valid pointer (e.g. received from a call
|
||||
* to *_window_open)
|
||||
|
|
|
@ -96,7 +96,7 @@ public:
|
|||
void user_command();
|
||||
void custom_command();
|
||||
void ai_formula();
|
||||
void clear_messages();
|
||||
virtual void clear_messages() override;
|
||||
std::vector<std::string> get_commands_list();
|
||||
|
||||
unit_map::iterator current_unit();
|
||||
|
|
|
@ -871,6 +871,7 @@ class fake_chat_handler : public events::chat_handler {
|
|||
MESSAGE_TYPE) {}
|
||||
void send_chat_message(const std::string&, bool) {}
|
||||
void send_to_server(const config&) {}
|
||||
void clear_messages() {}
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
Loading…
Add table
Reference in a new issue