Add /clear chat command (#6457)
This commit is contained in:
parent
23a210ab80
commit
3035a1a1e3
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);
|
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_remove();
|
||||||
void do_display();
|
void do_display();
|
||||||
void do_version();
|
void do_version();
|
||||||
|
void do_clear_messages();
|
||||||
|
|
||||||
/** Request information about a user from the server. */
|
/** Request information about a user from the server. */
|
||||||
void do_info();
|
void do_info();
|
||||||
|
@ -113,6 +114,8 @@ protected:
|
||||||
_("Display version information."));
|
_("Display version information."));
|
||||||
register_command("info", &chat_command_handler::do_info,
|
register_command("info", &chat_command_handler::do_info,
|
||||||
_("Request information about a nickname."), _("<nickname>"));
|
_("Request information about a nickname."), _("<nickname>"));
|
||||||
|
register_command("clear", &chat_command_handler::do_clear_messages,
|
||||||
|
_("Clear chat history."));
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
chat_handler& chat_handler_;
|
chat_handler& chat_handler_;
|
||||||
|
|
|
@ -64,6 +64,8 @@ protected:
|
||||||
|
|
||||||
void change_logging(const std::string& data);
|
void change_logging(const std::string& data);
|
||||||
|
|
||||||
|
virtual void clear_messages() = 0;
|
||||||
|
|
||||||
friend class chat_command_handler;
|
friend class chat_command_handler;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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 bool chatbox_at_end = log.vertical_scrollbar_at_end();
|
||||||
const unsigned chatbox_position = log.get_vertical_scrollbar_item_position();
|
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()
|
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_use_markup(true);
|
||||||
log.set_label(new_text);
|
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);
|
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*/)
|
void chatbox::user_relation_changed(const std::string& /*name*/)
|
||||||
{
|
{
|
||||||
if(active_window_changed_callback_) {
|
if(active_window_changed_callback_) {
|
||||||
|
|
|
@ -195,6 +195,8 @@ public:
|
||||||
/** Inherited form @ref chat_handler */
|
/** Inherited form @ref chat_handler */
|
||||||
virtual void send_chat_message(const std::string& message, bool allies_only) override;
|
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
|
* Switch to the window given by a valid pointer (e.g. received from a call
|
||||||
* to *_window_open)
|
* to *_window_open)
|
||||||
|
|
|
@ -96,7 +96,7 @@ public:
|
||||||
void user_command();
|
void user_command();
|
||||||
void custom_command();
|
void custom_command();
|
||||||
void ai_formula();
|
void ai_formula();
|
||||||
void clear_messages();
|
virtual void clear_messages() override;
|
||||||
std::vector<std::string> get_commands_list();
|
std::vector<std::string> get_commands_list();
|
||||||
|
|
||||||
unit_map::iterator current_unit();
|
unit_map::iterator current_unit();
|
||||||
|
|
|
@ -870,6 +870,7 @@ class fake_chat_handler : public events::chat_handler {
|
||||||
MESSAGE_TYPE) {}
|
MESSAGE_TYPE) {}
|
||||||
void send_chat_message(const std::string&, bool) {}
|
void send_chat_message(const std::string&, bool) {}
|
||||||
void send_to_server(const config&) {}
|
void send_to_server(const config&) {}
|
||||||
|
void clear_messages() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
|
Loading…
Add table
Reference in a new issue