From 2d1f007e7586b7745380060a506ba351a609aa3a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 3 Jul 2020 18:32:16 +0200 Subject: Allow changing the placeholder text, fix dmenu empty search selection --- README.md | 9 +++++---- include/SearchBar.hpp | 3 ++- src/QuickMedia.cpp | 23 ++++++++++++++++------- src/SearchBar.cpp | 9 +++++---- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index f34ad10..388110b 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,12 @@ Config data, including manga progress is stored under `$HOME/.config/quickmedia` Cache is stored under `$HOME/.cache/quickmedia`. ## Usage ``` -usage: QuickMedia [--tor] +usage: QuickMedia [--tor] [--use-system-mpv-config] [-p placeholder-text] OPTIONS: -plugin The plugin to use. Should be either 4chan, manganelo, mangatown, mangadex, youtube or dmenu ---tor Use tor. Disabled by default ---use-system-mpv-config Use system mpv config instead of no config. Disabled by default + plugin The plugin to use. Should be either 4chan, manganelo, mangatown, mangadex, youtube or dmenu + --tor Use tor. Disabled by default + --use-system-mpv-config Use system mpv config instead of no config. Disabled by default + -p Change the placeholder text for dmenu EXAMPLES: QuickMedia manganelo QuickMedia youtube --tor diff --git a/include/SearchBar.hpp b/include/SearchBar.hpp index 6222da4..0cffff5 100644 --- a/include/SearchBar.hpp +++ b/include/SearchBar.hpp @@ -16,7 +16,7 @@ namespace QuickMedia { class SearchBar { public: - SearchBar(sf::Font &font, sf::Texture &plugin_logo); + SearchBar(sf::Font &font, sf::Texture &plugin_logo, const std::string &placeholder); void draw(sf::RenderWindow &window, bool draw_shadow = true); void update(); void onWindowResize(const sf::Vector2f &window_size); @@ -45,6 +45,7 @@ namespace QuickMedia { sf::RectangleShape background_shadow; sf::RectangleShape shade; sf::Sprite plugin_logo_sprite; + std::string placeholder_str; bool show_placeholder; bool updated_search; bool updated_autocomplete; diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 0845d43..29deaa3 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -109,11 +109,12 @@ namespace QuickMedia { } static void usage() { - fprintf(stderr, "usage: QuickMedia [--tor]\n"); + fprintf(stderr, "usage: QuickMedia [--tor] [--use-system-mpv-config] [-p placeholder-text]\n"); fprintf(stderr, "OPTIONS:\n"); - fprintf(stderr, "plugin The plugin to use. Should be either 4chan, manganelo, mangatown, mangadex, pornhub, youtube or dmenu\n"); - fprintf(stderr, "--tor Use tor. Disabled by default\n"); - fprintf(stderr, "--use-system-mpv-config Use system mpv config instead of no config. Disabled by default\n"); + fprintf(stderr, " plugin The plugin to use. Should be either 4chan, manganelo, mangatown, mangadex, pornhub, youtube or dmenu\n"); + fprintf(stderr, " --tor Use tor. Disabled by default\n"); + fprintf(stderr, " --use-system-mpv-config Use system mpv config instead of no config. Disabled by default\n"); + fprintf(stderr, " -p Change the placeholder text for dmenu\n"); fprintf(stderr, "EXAMPLES:\n"); fprintf(stderr, "QuickMedia manganelo\n"); fprintf(stderr, "QuickMedia youtube --tor\n"); @@ -147,6 +148,7 @@ namespace QuickMedia { current_plugin = nullptr; std::string plugin_logo_path; + std::string search_placeholder = "Search..."; for(int i = 1; i < argc; ++i) { if(!current_plugin) { @@ -181,6 +183,11 @@ namespace QuickMedia { use_tor = true; } else if(strcmp(argv[i], "--use-system-mpv-config") == 0) { use_system_mpv_config = true; + } else if(strcmp(argv[i], "-p") == 0) { + if(i < argc - 1) { + search_placeholder = argv[i + 1]; + ++i; + } } else if(argv[i][0] == '-') { fprintf(stderr, "Invalid option %s\n", argv[i]); usage(); @@ -204,7 +211,7 @@ namespace QuickMedia { plugin_logo.setSmooth(true); } - search_bar = std::make_unique(font, plugin_logo); + search_bar = std::make_unique(font, plugin_logo, search_placeholder); search_bar->text_autosearch_delay = current_plugin->get_search_delay(); while(window.isOpen()) { @@ -415,8 +422,10 @@ namespace QuickMedia { }; search_bar->onTextSubmitCallback = [this, &tabs, &selected_tab, &typing](const std::string &text) -> bool { - if(typing || text.empty()) - return false; + if(current_plugin->name != "dmenu") { + if(typing || text.empty()) + return false; + } Page next_page = current_plugin->get_page_after_search(); bool skip_search = next_page == Page::VIDEO_CONTENT; diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp index 9d8a168..5c3c35c 100644 --- a/src/SearchBar.cpp +++ b/src/SearchBar.cpp @@ -11,15 +11,16 @@ const float PADDING_HORIZONTAL = 50.0f; const float padding_vertical = 20.0f; namespace QuickMedia { - SearchBar::SearchBar(sf::Font &font, sf::Texture &plugin_logo) : + SearchBar::SearchBar(sf::Font &font, sf::Texture &plugin_logo, const std::string &placeholder) : onTextUpdateCallback(nullptr), onTextSubmitCallback(nullptr), onTextBeginTypingCallback(nullptr), onAutocompleteRequestCallback(nullptr), text_autosearch_delay(0), autocomplete_search_delay(0), - text("Search...", font, 18), + text(placeholder, font, 18), autocomplete_text("", font, 18), + placeholder_str(placeholder), show_placeholder(true), updated_search(false), updated_autocomplete(false), @@ -116,7 +117,7 @@ namespace QuickMedia { text.setString(str); if(str.getSize() == 0) { show_placeholder = true; - text.setString("Search..."); + text.setString(placeholder_str); text.setFillColor(text_placeholder_color); autocomplete_text.setString(""); } else { @@ -158,7 +159,7 @@ namespace QuickMedia { if(show_placeholder) return; show_placeholder = true; - text.setString("Search..."); + text.setString(placeholder_str); text.setFillColor(text_placeholder_color); autocomplete_text.setString(""); needs_update = true; -- cgit v1.2.3