aboutsummaryrefslogtreecommitdiff
path: root/src/InputMediator.cpp
blob: 91393c257dcb6630eaadebc002f3669bac90f05a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <QList>
#include <QWidget>
#include <QtCore>

#include "InputMediator.hpp"
#include "LuaRuntime.hpp"
#include "keymap/KeymapEvaluator.hpp"
#include "widgets/WebViewStack.hpp"

// TODO: Rename this
InputMediator::InputMediator(WebViewStack *webview_stack,
                             LuaRuntime *lua_runtime,
                             KeymapEvaluator *keymap_evaluator)
    : webview_stack(webview_stack), lua_runtime(lua_runtime),
      keymap_evaluator(keymap_evaluator) {
  connect(lua_runtime, &LuaRuntime::url_opened, webview_stack,
          &WebViewStack::open_url);
  connect(lua_runtime, &LuaRuntime::keymap_added, this,
          &InputMediator::add_keymap);
  connect(lua_runtime, &LuaRuntime::history_back_requested, webview_stack,
          &WebViewStack::webview_history_back);
  connect(lua_runtime, &LuaRuntime::history_forward_requested, webview_stack,
          &WebViewStack::webview_history_forward);
  connect(lua_runtime, &LuaRuntime::webview_closed, webview_stack,
          &WebViewStack::close);
  connect(lua_runtime, &LuaRuntime::webview_selected, webview_stack,
          &WebViewStack::focus_webview);

  lua_runtime->set_current_tab_id_fetcher(
      [this]() { return this->webview_stack->current_webview_id(); });
  lua_runtime->set_webview_data_list_fetcher(
      [this]() { return this->webview_stack->get_webview_list(); });
}

void InputMediator::add_keymap(const QString &mode_string,
                               const QString &keyseq,
                               std::function<void()> action) {
  const KeyMode mode = keymap_evaluator->mode_from_string(mode_string);
  keymap_evaluator->add_keymap(mode, keyseq, std::move(action));
}

InputMediator::~InputMediator() { delete webview_stack; }