Skip to content

Commit

Permalink
UI: Added item search via 'Ctrl-F' and 'Shift-F' / 'F3'
Browse files Browse the repository at this point in the history
  • Loading branch information
pyroscope committed Jul 22, 2018
1 parent 6b895bf commit b8a640b
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/CHANGES.rst
Expand Up @@ -9,6 +9,7 @@ Change History

.. rubric:: UNRELEASED DEVELOPMENT VERSION

- UI: Added item search via ``Ctrl-F`` and ``Shift-F`` / ``F3``
- UI: Added *no data* indicator to alerts (in the ```` column)
- UI: Replaced problematic glyphs like ‘hourglass’ (caused visual defects on *Stretch* and *Bionic*)
- Fix: Compilation on 32bit platforms (issue #108)
Expand Down
3 changes: 3 additions & 0 deletions docs/manual.rst
Expand Up @@ -33,6 +33,9 @@ you will get the following additional features in your `rTorrent-PS` installatio
other value ``ui.focus.page_size`` has).
#. ``Home`` / ``End`` jump to the first / last item in the current
view.
#. :kbd:`Ctrl-F` opens a prompt where you can enter a search term,
and :kbd:`Shift-F` or :kbd:`F3` jump to the next hit for that term.
If nothing matches, a message is shown on the console.
#. The ``~`` key rotates through all available color themes, or a
user-selected subset. See :ref:`color-themes` for details.
#. The ``<`` and ``>`` keys rotate through all added category views
Expand Down
43 changes: 43 additions & 0 deletions patches/ps-dl-ui-find_all.patch
@@ -0,0 +1,43 @@
--- a/src/ui/download_list.cc
+++ b/src/ui/download_list.cc
@@ -259,6 +259,10 @@ DownloadList::receive_view_input(Input type) {
title = "command";
break;

+ case INPUT_FIND:
+ title = "find";
+ break;
+
default:
throw torrent::internal_error("DownloadList::receive_view_input(...) Invalid input type.");
}
@@ -322,6 +326,11 @@ DownloadList::receive_exit_input(Input type) {
input->str());
break;

+ case INPUT_FIND:
+ rpc::call_command("ui.find.term.set", rak::trim(input->str()), rpc::make_target());
+ rpc::call_command("ui.find.next", torrent::Object(), rpc::make_target());
+ break;
+
default:
throw torrent::internal_error("DownloadList::receive_exit_input(...) Invalid input type.");
}
@@ -353,2 +362,5 @@ DownloadList::setup_keys() {
m_uiArray[DISPLAY_DOWNLOAD_LIST]->bindings()['l'] = std::bind(&DownloadList::activate_display, this, DISPLAY_LOG);
+
+ // Replace Ctrl-F binding for setting 'ui.find.term'
+ m_uiArray[DISPLAY_DOWNLOAD_LIST]->bindings()['F' - '@'] = std::bind(&DownloadList::receive_view_input, this, INPUT_FIND);
}
--- a/src/ui/download_list.h
+++ b/src/ui/download_list.h
@@ -86,7 +86,8 @@ public:
INPUT_LOAD_DEFAULT,
INPUT_LOAD_MODIFIED,
INPUT_CHANGE_DIRECTORY,
- INPUT_COMMAND
+ INPUT_COMMAND,
+ INPUT_FIND
} Input;

DownloadList();
40 changes: 40 additions & 0 deletions patches/ui_pyroscope.cc
Expand Up @@ -1058,6 +1058,39 @@ torrent::Object apply_magnitude(const torrent::Object::list_type& args) {
}


torrent::Object ui_find_next() {
std::string term = rpc::call_command_string("ui.find.term");
if (term.empty())
return torrent::Object(); // no current search term set

ui::DownloadList* dl_list = control->ui()->download_list();
core::View* dl_view = dl_list->current_view();

if (dl_view->empty_visible()) {
control->core()->push_log("This view is empty, nothing to find!");
} else {
core::View::iterator itr = dl_view->focus() == dl_view->end_visible() ?
dl_view->begin_visible() : dl_view->focus();
bool found = false;

do {
if (++itr == dl_view->end_visible())
itr = dl_view->begin_visible();
found = (*itr)->info()->name().find(term) != std::string::npos;
} while (!found && itr != dl_view->focus());

if (!found) {
control->core()->push_log(("Cannot find anything matching '" + term + "'").c_str());
} else if (itr != dl_view->focus()) {
dl_view->set_focus(itr);
dl_view->set_last_changed();
}
}

return torrent::Object();
}


// register our commands
void initialize_command_ui_pyroscope() {
#define PS_VARIABLE_COLOR(key, value) \
Expand Down Expand Up @@ -1095,6 +1128,9 @@ void initialize_command_ui_pyroscope() {
CMD2_ANY("ui.column.sacrificial.list", _cxxstd_::bind(&display::ui_column_sacrificial_list));
CMD2_VAR_VALUE("ui.column.sacrificed", 0);

CMD2_ANY ("ui.find.next", _cxxstd_::bind(&ui_find_next));
CMD2_VAR_STRING("ui.find.term", "");

PS_VARIABLE_COLOR("ui.color.progress0", "red");
PS_VARIABLE_COLOR("ui.color.progress20", "bold bright red");
PS_VARIABLE_COLOR("ui.color.progress40", "bold bright magenta");
Expand Down Expand Up @@ -1166,6 +1202,10 @@ void initialize_command_ui_pyroscope() {
"schedule2 = collapsed_view_toggle, 0, 0, ((ui.bind_key, download_list, *, \""
"view.collapsed.toggle= ; ui.current_view.set = (ui.current_view)\"))\n"

// Bind 'F' / F3 to find the next item for 'ui.find.term'
"schedule2 = ui_find_next_f, 0, 0, ((ui.bind_key, download_list, F, \"ui.find.next=\"))\n"
"schedule2 = ui_find_next_f3, 0, 0, ((ui.bind_key, download_list, 0413, \"ui.find.next=\"))\n"

// Collapse built-in views
"view.collapsed.toggle = main\n"
"view.collapsed.toggle = name\n"
Expand Down

0 comments on commit b8a640b

Please sign in to comment.