diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 57 | ||||
-rw-r--r-- | src/SearchBar.cpp | 7 |
2 files changed, 50 insertions, 14 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index f7d35d9..f11b69f 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1770,6 +1770,47 @@ namespace QuickMedia { } } + static void copy_body_item_text_to_clipboard(BodyItem *body_item) { + if(!body_item) + return; + + std::string title = body_item->get_title(); + std::string author = body_item->get_author(); + std::string description = body_item->get_description(); + + std::string clipboard = std::move(title); + + if(!author.empty()) { + if(!clipboard.empty()) + clipboard += '\n'; + clipboard += std::move(author); + } + + if(!description.empty()) { + if(!clipboard.empty()) + clipboard += '\n'; + clipboard += std::move(description); + } + + if(!clipboard.empty()) + sf::Clipboard::setString(sf::String::fromUtf8(clipboard.begin(), clipboard.end())); + } + + static void set_search_bar_to_body_item_text(BodyItem *body_item, SearchBar *search_bar) { + if(!body_item || !search_bar) + return; + + if(!body_item->get_title().empty()) { + search_bar->set_text(body_item->get_title()); + return; + } + + if(!body_item->get_author().empty()) { + search_bar->set_text(body_item->get_author()); + return; + } + } + bool Program::page_loop(std::vector<Tab> &tabs, int start_tab_index, PageLoopSubmitHandler after_submit_handler) { if(tabs.empty()) { show_notification("QuickMedia", "No tabs provided!", Urgency::CRITICAL); @@ -2153,23 +2194,13 @@ namespace QuickMedia { } } } else if(event.key.code == sf::Keyboard::C && event.key.control) { - BodyItem *selected_item = tabs[selected_tab].body->get_selected(); - if(selected_item) { - std::string title = selected_item->get_title(); - std::string description = selected_item->get_description(); - std::string clipboard = std::move(title); - if(!description.empty()) { - if(!clipboard.empty()) - clipboard += '\n'; - clipboard += std::move(description); - } - if(!clipboard.empty()) - sf::Clipboard::setString(sf::String::fromUtf8(clipboard.begin(), clipboard.end())); - } + copy_body_item_text_to_clipboard(tabs[selected_tab].body->get_selected()); } else if(event.key.code == sf::Keyboard::I && event.key.control) { BodyItem *selected_item = tabs[selected_tab].body->get_selected(); if(show_info_page(selected_item, false)) redraw = true; + } else if(event.key.code == sf::Keyboard::Tab && !event.key.control) { + set_search_bar_to_body_item_text(tabs[selected_tab].body->get_selected(), tabs[selected_tab].search_bar.get()); } } } diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp index 31e54fb..5b2d6ec 100644 --- a/src/SearchBar.cpp +++ b/src/SearchBar.cpp @@ -221,6 +221,11 @@ namespace QuickMedia { backspace_pressed = false; } + void SearchBar::set_text(const std::string &text) { + clear(); + append_text(text); + } + void SearchBar::append_text(const std::string &text_to_add) { if(text_to_add.empty()) return; @@ -232,7 +237,7 @@ namespace QuickMedia { } sf::String str = text.getString(); - str += text_to_add; + str += sf::String::fromUtf8(text_to_add.begin(), text_to_add.end());; text.setString(str); if(!updated_search) { |