aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-08-09 05:38:12 +0200
committerdec05eba <dec05eba@protonmail.com>2019-08-09 05:38:14 +0200
commit10fcdec298ccef4971dc6d109222079a0f438004 (patch)
tree90124b9d9cfd51c582d4d212c08cd17893d0f4ea
parent452311e6bf54368a9dac94c8ee973febf015dfd1 (diff)
Do not allow search until results are available
-rw-r--r--include/SearchBar.hpp3
-rw-r--r--src/QuickMedia.cpp14
-rw-r--r--src/SearchBar.cpp5
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<void(const sf::String &text)>;
- using TextSubmitCallback = std::function<void(const sf::String &text)>;
+ // Return true to consume the search (clear the search field)
+ using TextSubmitCallback = std::function<bool(const sf::String &text)>;
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);