clipboard: remove redundant methods

This commit is contained in:
Subhraman Sarkar 2024-09-18 14:58:40 +05:30 committed by Charles Dang
parent 355ed849ee
commit b6dead682b
20 changed files with 35 additions and 114 deletions

View File

@ -20,21 +20,16 @@
#define CLIPBOARD_FUNCS_DEFINED
/*
* Note SDL 2.0 has its own clipboard routines, but they don't support
* different clipboards (yet).
*/
namespace desktop {
namespace clipboard {
void copy_to_clipboard(const std::string& text, const bool)
void copy_to_clipboard(const std::string& text)
{
SDL_SetClipboardText(text.c_str());
}
std::string copy_from_clipboard(const bool)
std::string copy_from_clipboard()
{
char* clipboard = SDL_GetClipboardText();
if(!clipboard) {
@ -46,15 +41,6 @@ std::string copy_from_clipboard(const bool)
return result;
}
void handle_system_event(const SDL_Event& /*event*/)
{
}
bool available()
{
return true;
}
} // end namespace clipboard
} // end namespace desktop

View File

@ -27,27 +27,15 @@ namespace clipboard {
* Copies text to the clipboard.
*
* @param text The text to copy.
* @param mouse Is the selection done by the mouse? On UNIX systems there
* are multiple clipboards and the mouse selection uses a
* different clipboard. Ignored on other systems.
*/
void copy_to_clipboard(const std::string& text, const bool mouse);
void copy_to_clipboard(const std::string& text);
/**
* Copies text from the clipboard.
*
* @param mouse Is the pasting done by the mouse?
*
* @returns String on clipbaord.
*/
std::string copy_from_clipboard(const bool mouse);
void handle_system_event(const SDL_Event& ev);
/**
* Whether wesnoth was compiled with support for a clipboard.
*/
bool available();
std::string copy_from_clipboard();
} // end namespace clipboard

View File

@ -1376,7 +1376,7 @@ void editor_controller::export_selection_coords()
++i;
}
ssx << "\n" << ssy.str() << "\n";
desktop::clipboard::copy_to_clipboard(ssx.str(), false);
desktop::clipboard::copy_to_clipboard(ssx.str());
}
}

View File

@ -694,14 +694,6 @@ void pump()
}
#endif
#if defined(_X11) && !defined(__APPLE__)
case SDL_SYSWMEVENT: {
// clipboard support for X11
desktop::clipboard::handle_system_event(event);
break;
}
#endif
#if defined _WIN32
case SDL_SYSWMEVENT: {
windows_tray_notification::handle_system_event(event);

View File

@ -193,7 +193,7 @@ public:
{
std::ostringstream s;
stream_log(s, first, last, true);
desktop::clipboard::copy_to_clipboard(s.str(), false);
desktop::clipboard::copy_to_clipboard(s.str());
}
};
@ -391,10 +391,6 @@ public:
std::bind(&view::handle_copy_button_clicked,
this,
std::ref(window)));
if (!desktop::clipboard::available()) {
model_.copy_button->set_active(false);
model_.copy_button->set_tooltip(_("Clipboard support not found, contact your packager"));
}
model_.page_label = find_widget<styled_widget>(&window, "page_label", false, true);

View File

@ -90,11 +90,6 @@ void custom_tod::pre_show(window& window)
connect_signal_mouse_left_click(copy_w,
std::bind(&custom_tod::copy_to_clipboard_callback, this, data));
if(!desktop::clipboard::available()) {
copy_w.set_active(false);
copy_w.set_tooltip(_("Clipboard support not found, contact your packager"));
}
}
connect_signal_mouse_left_click(
@ -333,7 +328,7 @@ void custom_tod::copy_to_clipboard_callback(std::pair<std::string, tod_attribute
{
auto& [type, getter] = data;
button& copy_w = find_widget<button>(get_window(), "copy_" + type, false);
desktop::clipboard::copy_to_clipboard(getter(get_selected_tod()).second, false);
desktop::clipboard::copy_to_clipboard(getter(get_selected_tod()).second);
copy_w.set_success(true);
}

View File

@ -63,10 +63,6 @@ void game_cache_options::pre_show(window& window)
connect_signal_mouse_left_click(copy,
std::bind(&game_cache_options::copy_to_clipboard_callback,
this));
if (!desktop::clipboard::available()) {
copy.set_active(false);
copy.set_tooltip(_("Clipboard support not found, contact your packager"));
}
button& browse = find_widget<button>(&window, "browse", false);
connect_signal_mouse_left_click(browse,
@ -110,7 +106,7 @@ void game_cache_options::update_cache_size_display()
void game_cache_options::copy_to_clipboard_callback()
{
desktop::clipboard::copy_to_clipboard(cache_path_, false);
desktop::clipboard::copy_to_clipboard(cache_path_);
}
void game_cache_options::browse_cache_callback()

View File

@ -152,11 +152,6 @@ void game_version::pre_show(window& window)
// open_object().
browse_w.set_visible(widget::visibility::invisible);
}
if(!desktop::clipboard::available()) {
copy_w.set_active(false);
copy_w.set_tooltip(_("Clipboard support not found, contact your packager"));
}
}
button& stderr_button = find_widget<button>(&window, "open_stderr", false);
@ -250,7 +245,7 @@ void game_version::run_migrator()
void game_version::copy_to_clipboard_callback(const std::string& path, const std::string btn_id)
{
desktop::clipboard::copy_to_clipboard(path, false);
desktop::clipboard::copy_to_clipboard(path);
button& copy_w = find_widget<button>(get_window(), btn_id, false);
copy_w.set_success(true);
@ -258,7 +253,7 @@ void game_version::copy_to_clipboard_callback(const std::string& path, const std
void game_version::report_copy_callback()
{
desktop::clipboard::copy_to_clipboard(report_, false);
desktop::clipboard::copy_to_clipboard(report_);
button& copy_all = find_widget<button>(get_window(), "copy_all", false);
copy_all.set_success(true);

View File

@ -328,7 +328,7 @@ public:
void handle_copy_button_clicked()
{
desktop::clipboard::copy_to_clipboard(model_.get_data_full(), false);
desktop::clipboard::copy_to_clipboard(model_.get_data_full());
}
void handle_lua_button_clicked(window& window)
@ -409,12 +409,6 @@ public:
left_button->set_visible(widget::visibility::invisible);
right_button->set_visible(widget::visibility::invisible);
if (!desktop::clipboard::available()) {
copy_button->set_active(false);
copy_button->set_tooltip(_("Clipboard support not found, contact your packager"));
}
build_stuff_list(window);
}

View File

@ -441,11 +441,6 @@ void lua_interpreter::controller::bind(window& window)
this,
std::ref(window)));
if (!desktop::clipboard::available()) {
copy_button->set_active(false);
copy_button->set_tooltip(_("Clipboard support not found, contact your packager"));
}
LOG_LUA << "Exiting lua_interpreter::controller::bind";
}
@ -453,7 +448,7 @@ void lua_interpreter::controller::bind(window& window)
void lua_interpreter::controller::handle_copy_button_clicked(window & /*window*/)
{
assert(lua_model_);
desktop::clipboard::copy_to_clipboard(lua_model_->get_raw_log(), false);
desktop::clipboard::copy_to_clipboard(lua_model_->get_raw_log());
}
/** Clear the text */

View File

@ -63,13 +63,9 @@ void screenshot_notification::pre_show(window& window)
button& copy_b = find_widget<button>(&window, "copy", false);
connect_signal_mouse_left_click(
copy_b, std::bind(&desktop::clipboard::copy_to_clipboard, std::ref(path_), false));
copy_b, std::bind(&desktop::clipboard::copy_to_clipboard, std::ref(path_)));
copy_b.set_active(false);
if (!desktop::clipboard::available()) {
copy_b.set_tooltip(_("Clipboard support not found, contact your packager"));
}
button& open_b = find_widget<button>(&window, "open", false);
connect_signal_mouse_left_click(
open_b, std::bind(&desktop::open_object, std::ref(path_)));
@ -108,10 +104,7 @@ void screenshot_notification::save_screenshot()
path_box.set_active(false);
find_widget<button>(get_window(), "open", false).set_active(true);
find_widget<button>(get_window(), "save", false).set_active(false);
if(desktop::clipboard::available()) {
find_widget<button>(get_window(), "copy", false).set_active(true);
}
find_widget<button>(get_window(), "copy", false).set_active(true);
const int filesize = filesystem::file_size(path_);
const std::string sizetext = utils::si_string(filesize, true, _("unit_byte^B"));

View File

@ -183,16 +183,11 @@ void wml_error::pre_show(window& window)
connect_signal_mouse_left_click(
copy_button, std::bind(&wml_error::copy_report_callback, this));
if (!desktop::clipboard::available()) {
copy_button.set_active(false);
copy_button.set_tooltip(_("Clipboard support not found, contact your packager"));
}
}
void wml_error::copy_report_callback()
{
desktop::clipboard::copy_to_clipboard(report_, false);
desktop::clipboard::copy_to_clipboard(report_);
}
} // end namespace dialogs

View File

@ -167,7 +167,7 @@ void label::signal_handler_right_button_click(bool& handled)
DBG_GUI_E << "Right Clicked Link:\"" << link << "\"";
desktop::clipboard::copy_to_clipboard(link, false);
desktop::clipboard::copy_to_clipboard(link);
(void) show_message("", _("Copied link!"), dialogs::message::auto_close);

View File

@ -428,7 +428,7 @@ void multiline_text::signal_handler_left_button_down(const event::ui_event event
desktop::open_object(link);
}
} else {
desktop::clipboard::copy_to_clipboard(link, true);
desktop::clipboard::copy_to_clipboard(link);
show_message("", _("Opening links is not supported, contact your packager. Link URL has been copied to the clipboard."), dialogs::message::auto_close);
}
} else {

View File

@ -153,9 +153,9 @@ public:
private:
/** Inherited from text_box_base. */
void paste_selection(const bool mouse) override
void paste_selection() override
{
text_box_base::paste_selection(mouse);
text_box_base::paste_selection();
update_layout();
}

View File

@ -89,9 +89,9 @@ void password_box::insert_char(const std::string& unicode)
utf8::insert(real_value_, sel, unicode);
}
void password_box::paste_selection(const bool mouse)
void password_box::paste_selection()
{
const std::string& text = desktop::clipboard::copy_from_clipboard(mouse);
const std::string& text = desktop::clipboard::copy_from_clipboard();
if(text.empty()) {
return;
}

View File

@ -49,7 +49,7 @@ public:
protected:
void insert_char(const std::string& unicode) override;
void paste_selection(const bool mouse) override;
void paste_selection() override;
void delete_selection() override;
// We do not override copy_selection because we

View File

@ -139,10 +139,6 @@ void text_box_base::set_cursor(const std::size_t offset, const bool select)
if(select) {
selection_length_ = (selection_start_ == offset) ? 0 : -static_cast<int>(selection_start_ - offset);
#ifdef __unix__
// selecting copies on UNIX systems.
copy_selection(true);
#endif
} else {
selection_start_ = (offset <= text_.get_length()) ? offset : 0;
selection_length_ = 0;
@ -197,7 +193,7 @@ void text_box_base::interrupt_composition()
SDL_StartTextInput();
}
void text_box_base::copy_selection(const bool mouse)
void text_box_base::copy_selection()
{
if(selection_length_ == 0) {
return;
@ -214,17 +210,17 @@ void text_box_base::copy_selection(const bool mouse)
end = utf8::index(txt, start);
start = utf8::index(txt, start + selection_length_);
}
desktop::clipboard::copy_to_clipboard(txt.substr(start, end - start), mouse);
desktop::clipboard::copy_to_clipboard(txt.substr(start, end - start));
}
void text_box_base::paste_selection(const bool mouse)
void text_box_base::paste_selection()
{
if(!editable_)
{
return;
}
const std::string& text = desktop::clipboard::copy_from_clipboard(mouse);
const std::string& text = desktop::clipboard::copy_from_clipboard();
if(text.empty()) {
return;
}
@ -515,7 +511,7 @@ void text_box_base::signal_handler_middle_button_click(const event::ui_event eve
{
DBG_GUI_E << LOG_HEADER << ' ' << event << ".";
paste_selection(true);
paste_selection();
handled = true;
}
@ -620,7 +616,7 @@ void text_box_base::signal_handler_sdl_key_down(const event::ui_event event,
// atm we don't care whether there is something to copy or paste
// if nothing is there we still don't want to be chained.
copy_selection(false);
copy_selection();
handled = true;
break;
@ -629,7 +625,7 @@ void text_box_base::signal_handler_sdl_key_down(const event::ui_event event,
return;
}
copy_selection(false);
copy_selection();
if ( is_editable() ) {
delete_selection();
@ -642,7 +638,7 @@ void text_box_base::signal_handler_sdl_key_down(const event::ui_event event,
return;
}
paste_selection(false);
paste_selection();
handled = true;
break;

View File

@ -284,10 +284,10 @@ protected:
virtual void delete_selection() = 0;
/** Copies the current selection. */
virtual void copy_selection(const bool mouse);
virtual void copy_selection();
/** Pastes the current selection. */
virtual void paste_selection(const bool mouse);
virtual void paste_selection();
/***** ***** ***** ***** expose some functions ***** ***** ***** *****/

View File

@ -553,7 +553,7 @@ bool textbox::handle_key_down(const SDL_Event &event)
if(is_selection())
erase_selection();
std::string str = desktop::clipboard::copy_from_clipboard(false);
std::string str = desktop::clipboard::copy_from_clipboard();
//cut off anything after the first newline
str.erase(std::find_if(str.begin(),str.end(),utils::isnewline),str.end());
@ -581,7 +581,7 @@ bool textbox::handle_key_down(const SDL_Event &event)
std::u32string ws(text_.begin() + beg, text_.begin() + end);
std::string s = unicode_cast<std::string>(ws);
desktop::clipboard::copy_to_clipboard(s, false);
desktop::clipboard::copy_to_clipboard(s);
}
}
break;
@ -595,7 +595,7 @@ bool textbox::handle_key_down(const SDL_Event &event)
std::u32string ws(text_.begin() + beg, text_.begin() + end);
std::string s = unicode_cast<std::string>(ws);
desktop::clipboard::copy_to_clipboard(s, false);
desktop::clipboard::copy_to_clipboard(s);
erase_selection();
}
break;