Skip to content

Commit

Permalink
Fixed minor issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
rakshasa committed Jun 9, 2019
1 parent 35d98c9 commit a3a384b
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 30 deletions.
4 changes: 4 additions & 0 deletions src/command_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,10 @@ initialize_command_ui() {
CMD2_ANY ("ui.current_view", std::bind(&cmd_ui_current_view));
CMD2_ANY_STRING("ui.current_view.set", std::bind(&cmd_ui_set_view, std::placeholders::_2));

CMD2_ANY ("ui.input.history.size", std::bind(&ui::Root::get_input_history_size, control->ui()));
CMD2_ANY_VALUE_V("ui.input.history.size.set", std::bind(&ui::Root::set_input_history_size, control->ui(), std::placeholders::_2));
CMD2_ANY_V ("ui.input.history.clear", std::bind(&ui::Root::clear_input_history, control->ui()));

CMD2_VAR_VALUE ("ui.throttle.global.step.small", 5);
CMD2_VAR_VALUE ("ui.throttle.global.step.medium", 50);
CMD2_VAR_VALUE ("ui.throttle.global.step.large", 500);
Expand Down
2 changes: 2 additions & 0 deletions src/core/download_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include "download.h"
#include "download_list.h"
#include "download_store.h"
#include "ui/root.h"

#define DL_TRIGGER_EVENT(download, event_name) \
rpc::commands.call_catch(event_name, rpc::make_target(download), torrent::Object(), "Event '" event_name "' failed: ");
Expand Down Expand Up @@ -93,6 +94,7 @@ DownloadList::session_save() {
lt_log_print(torrent::LOG_ERROR, "Failed to save session torrents.");

control->dht_manager()->save_dht_cache();
control->ui()->save_input_history();
}

DownloadList::iterator
Expand Down
21 changes: 0 additions & 21 deletions src/input/text_input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,6 @@ TextInput::pressed(int key) {
if (m_bindings.pressed(key)) {
return true;

} else if (m_alt) {
m_alt = false;

switch (key) {
// case 'b':
// Base::insert(m_pos, "M^b");
// break;

// case 'f':
// Base::insert(m_pos, "M^f");
// break;

default:
return false;
}

} else if (key >= 0x20 && key < 0x7F) {
Base::insert(m_pos++, 1, key);

Expand Down Expand Up @@ -113,11 +97,6 @@ TextInput::pressed(int key) {
Base::erase(m_pos, size()-m_pos);
break;

case 0x1B:
m_alt = true;

break;

default:
return false;
}
Expand Down
5 changes: 2 additions & 3 deletions src/input/text_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ class TextInput : private std::string {
using Base::size_type;
using Base::npos;

TextInput() : m_pos(0), m_alt(false) {}
TextInput() : m_pos(0) {}
virtual ~TextInput() {}

size_type get_pos() { return m_pos; }
void set_pos(size_type pos) { m_pos = pos; }

virtual bool pressed(int key);

void clear() { m_pos = 0; m_alt = false; Base::clear(); }
void clear() { m_pos = 0; Base::clear(); }

void slot_dirty(slot_void s) { m_slot_dirty = s; }
void mark_dirty() { if (m_slot_dirty) m_slot_dirty(); }
Expand All @@ -74,7 +74,6 @@ class TextInput : private std::string {
private:
size_type m_pos;

bool m_alt;
slot_void m_slot_dirty;

Bindings m_bindings;
Expand Down
2 changes: 2 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "display/window.h"
#include "display/manager.h"
#include "input/bindings.h"
#include "ui/root.h"

#include "rpc/command_scheduler.h"
#include "rpc/command_scheduler_item.h"
Expand Down Expand Up @@ -466,6 +467,7 @@ main(int argc, char** argv) {
}

control->initialize();
control->ui()->load_input_history();

// Load session torrents and perform scheduled tasks to ensure
// session torrents are loaded before arg torrents.
Expand Down
14 changes: 12 additions & 2 deletions src/ui/download_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,31 @@ DownloadList::receive_view_input(Input type) {
std::placeholders::_1,
std::placeholders::_2));

// reset ESC delay for input prompt
set_escdelay(0);

input->bindings()['\n'] = std::bind(&DownloadList::receive_exit_input, this, type);
input->bindings()[KEY_ENTER] = std::bind(&DownloadList::receive_exit_input, this, type);
input->bindings()['\x07'] = std::bind(&DownloadList::receive_exit_input, this, INPUT_NONE);
input->bindings()['\x07'] = std::bind(&DownloadList::receive_exit_input, this, INPUT_NONE); // ^G
input->bindings()['\x1B'] = std::bind(&DownloadList::receive_exit_input, this, INPUT_NONE); // ESC , ^[

control->ui()->enable_input(title, input);
control->ui()->enable_input(title, input, type);
}

void
DownloadList::receive_exit_input(Input type) {
// set back ESC delay to default
set_escdelay(1000);

input::TextInput* input = control->ui()->current_input();

// We should check that this object is the one holding the input.
if (input == NULL)
return;

if (type != INPUT_NONE && type != INPUT_EOI)
control->ui()->add_to_input_history(type, input->str());

control->ui()->disable_input();

try {
Expand Down
3 changes: 2 additions & 1 deletion src/ui/download_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ class DownloadList : public ElementBase {
INPUT_LOAD_DEFAULT,
INPUT_LOAD_MODIFIED,
INPUT_CHANGE_DIRECTORY,
INPUT_COMMAND
INPUT_COMMAND,
INPUT_EOI
} Input;

DownloadList();
Expand Down
Loading

0 comments on commit a3a384b

Please sign in to comment.