From 6ee61ee6b50f3f12a6901d450ab2a6b689dd81dc Mon Sep 17 00:00:00 2001 From: Toff Date: Sun, 8 Jan 2017 19:45:46 +0100 Subject: [PATCH] Merge chros73 suggestions (filter indicator, "start/stopped" view case) - Suffix filtered view name with "(filtered)" - Add a check to not filter "start" and "stopped" view --- src/command_ui.cc | 6 +++--- src/display/window_download_list.cc | 2 +- src/ui/download_list.cc | 10 ++++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/command_ui.cc b/src/command_ui.cc index c6f7d311..58abf54e 100644 --- a/src/command_ui.cc +++ b/src/command_ui.cc @@ -320,15 +320,15 @@ torrent::Object apply_match(rpc::target_type target, const torrent::Object::list std::transform(text.begin(), text.end(), text.begin(), ::tolower); std::transform(pattern.begin(), pattern.end(), pattern.begin(), ::tolower); - bool match = false; + bool isAMatch = false; try { std::regex re(pattern); - match = std::regex_match(text, re); + isAMatch = std::regex_match(text, re); } catch (const std::regex_error& exc) { control->core()->push_log_std("regex_error: " + std::string(exc.what())); } - return match ? (int64_t)true : (int64_t)false; + return isAMatch ? (int64_t)true : (int64_t)false; } torrent::Object diff --git a/src/display/window_download_list.cc b/src/display/window_download_list.cc index 74911555..b4a94324 100644 --- a/src/display/window_download_list.cc +++ b/src/display/window_download_list.cc @@ -81,7 +81,7 @@ WindowDownloadList::redraw() { if (m_view == NULL) return; - m_canvas->print(0, 0, "%s", ("[View: " + m_view->name() + "]").c_str()); + m_canvas->print(0, 0, "%s", ("[View: " + m_view->name() + (m_view->get_temp_filter().is_empty() ? "" : " (filtered)") + "]").c_str()); if (m_view->empty_visible() || m_canvas->width() < 5 || m_canvas->height() < 2) return; diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index a8dd3210..c88079af 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -263,6 +263,11 @@ DownloadList::receive_view_input(Input type) { break; case INPUT_FILTER: + // STARTED and STOPPED views are not allowed to being filtered: they are special + if (current_view()->name() == "started" || current_view()->name() == "stopped") { + control->core()->push_log_std("View '" + current_view()->name() + "' can't be filtered."); + return; + } title = "filter"; break; @@ -331,9 +336,10 @@ DownloadList::receive_exit_input(Input type) { case INPUT_FILTER: if (input->str().empty()) { - control->core()->push_log_std("Clear temporary filter."); + control->core()->push_log_std("Clear temporary filter on '" + current_view()->name() + "' view."); current_view()->set_temp_filter(torrent::Object()); current_view()->filter(); + current_view()->sort(); } else { std::string pattern = input->str(); if (pattern.back() != '$') @@ -342,7 +348,7 @@ DownloadList::receive_exit_input(Input type) { pattern = ".*" + pattern; std::transform(pattern.begin(), pattern.end(), pattern.begin(), ::tolower); std::string tempFilter = "match={d.name=," + pattern + "}"; - control->core()->push_log_std("Temporary filter: " + pattern); + control->core()->push_log_std("Temporary filter on '" + current_view()->name() + "' view: " + pattern); current_view()->set_temp_filter(tempFilter); current_view()->filter(); }