Add /clear chat command (#6457)

This commit is contained in:
Bruno Macabeus 2022-01-30 20:18:19 +00:00 committed by GitHub
parent 23a210ab80
commit 3035a1a1e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 2 deletions

View file

@ -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();
}
}

View file

@ -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_;

View file

@ -64,6 +64,8 @@ protected:
void change_logging(const std::string& data);
virtual void clear_messages() = 0;
friend class chat_command_handler;
};

View file

@ -222,8 +222,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);
@ -251,6 +252,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_) {

View file

@ -195,6 +195,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)

View file

@ -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();

View file

@ -870,6 +870,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<>