From 10fcdec298ccef4971dc6d109222079a0f438004 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 9 Aug 2019 05:38:12 +0200 Subject: Do not allow search until results are available --- include/SearchBar.hpp | 3 ++- src/QuickMedia.cpp | 14 ++++++++------ src/SearchBar.cpp | 5 +++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/SearchBar.hpp b/include/SearchBar.hpp index f1ac3fd..46f4383 100644 --- a/include/SearchBar.hpp +++ b/include/SearchBar.hpp @@ -8,7 +8,8 @@ namespace QuickMedia { using TextUpdateCallback = std::function; - using TextSubmitCallback = std::function; + // Return true to consume the search (clear the search field) + using TextSubmitCallback = std::function; class SearchBar { public: diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index d010693..db2eeb0 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -215,16 +215,16 @@ namespace QuickMedia { update_search_text = text; }; - search_bar->onTextSubmitCallback = [this](const std::string &text) { + search_bar->onTextSubmitCallback = [this](const std::string &text) -> bool { Page next_page = current_plugin->get_page_after_search(); if(search_selected_suggestion(body, current_plugin, content_title, content_url) != SearchResult::OK) - return; + return false; if(next_page == Page::EPISODE_LIST) { Path content_storage_dir = get_storage_dir().join("manga"); if(create_directory_recursive(content_storage_dir) != 0) { show_notification("Storage", "Failed to create directory: " + content_storage_dir.data, Urgency::CRITICAL); - return; + return false; } content_storage_file = content_storage_dir.join(base64_encode(content_title)); @@ -239,6 +239,7 @@ namespace QuickMedia { next_page = Page::SEARCH_RESULT; } current_page = next_page; + return true; }; sf::Vector2f body_pos; @@ -575,10 +576,10 @@ namespace QuickMedia { body->clamp_selection(); }; - search_bar->onTextSubmitCallback = [this](const std::string &text) { + search_bar->onTextSubmitCallback = [this](const std::string &text) -> bool { BodyItem *selected_item = body->get_selected(); if(!selected_item) - return; + return false; images_url = selected_item->url; chapter_title = selected_item->title; @@ -594,7 +595,8 @@ namespace QuickMedia { image_index = current.asInt() - 1; } } - + + return true; }; const Json::Value &json_chapters = content_storage_json["chapters"]; diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp index b967224..5554a37 100644 --- a/src/SearchBar.cpp +++ b/src/SearchBar.cpp @@ -63,10 +63,11 @@ namespace QuickMedia { time_since_search_update.restart(); } } else if(codepoint == 13) { // Return + bool clear_search = true; if(onTextSubmitCallback) - onTextSubmitCallback(text.getString()); + clear_search = onTextSubmitCallback(text.getString()); - if(!show_placeholder) { + if(clear_search && !show_placeholder) { show_placeholder = true; text.setString("Search..."); text.setFillColor(text_placeholder_color); -- cgit v1.2.3