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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#include <QList>
#include <QWidget>
#include <QtCore>
#include "CommandParser.hpp"
#include "InputMediator.hpp"
#include "LuaRuntime.hpp"
#include "keymap/KeymapEvaluator.hpp"
#include "widgets/WebViewStack.hpp"
// TODO: Rename this
InputMediator::InputMediator(WebViewStack *webViewStack, LuaRuntime *luaRuntime,
KeymapEvaluator *keymapEvaluator)
: QObject(), webViewStack(webViewStack), luaRuntime(luaRuntime),
keymapEvaluator(keymapEvaluator) {
connect(luaRuntime, &LuaRuntime::urlOpened, webViewStack,
&WebViewStack::openUrl);
connect(luaRuntime, &LuaRuntime::keymapAddRequested, this,
&InputMediator::addKeymap);
}
void InputMediator::addKeymap(QString modeString, QString keyseq,
std::function<void()> action) {
KeyMode mode = keymapEvaluator->modeFromString(modeString);
keymapEvaluator->addKeymap(mode, keyseq, action);
}
void InputMediator::evaluateCommand(QString command) {
CommandParser parser;
auto cmd = parser.parse(command);
switch (cmd.command) {
case CommandType::LuaEval:
luaRuntime->evaluate(cmd.argsString);
break;
case CommandType::Open:
openUrl(cmd.argsString, OpenType::OpenUrl);
break;
case CommandType::TabOpen:
openUrl(cmd.argsString, OpenType::OpenUrlInTab);
break;
case CommandType::TabNext:
nextWebView();
break;
case CommandType::TabPrev:
previousWebView();
break;
case CommandType::TabSelect:
webViewStack->focusWebView(cmd.argsString.toLong());
break;
case CommandType::Noop:
break;
}
}
InputMediator::~InputMediator() { delete webViewStack; }
|