diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-29 11:45:18 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-29 11:45:18 +0530 |
| commit | bcecbced7e1af9d99443a7e823f18328c7943f09 (patch) | |
| tree | 612fac477acfa38358e15916bd4a44f386dc9206 /src/WindowMediator.cpp | |
| parent | f7392096d2d84be7143947d386528bf4f487ee83 (diff) | |
| download | null-browser-bcecbced7e1af9d99443a7e823f18328c7943f09.tar.gz null-browser-bcecbced7e1af9d99443a7e823f18328c7943f09.zip | |
Add window action router for multi-window
Diffstat (limited to 'src/WindowMediator.cpp')
| -rw-r--r-- | src/WindowMediator.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/WindowMediator.cpp b/src/WindowMediator.cpp new file mode 100644 index 0000000..8c49e94 --- /dev/null +++ b/src/WindowMediator.cpp @@ -0,0 +1,45 @@ +#include <QList> +#include <QWidget> +#include <QtCore> + +#include "LuaRuntime.hpp" +#include "WindowMediator.hpp" +#include "keymap/KeymapEvaluator.hpp" +#include "widgets/WebViewStack.hpp" + +WindowMediator::WindowMediator(WebViewStack *webview_stack, + LuaRuntime *lua_runtime, + KeymapEvaluator *keymap_evaluator) + : webview_stack(webview_stack), lua_runtime(lua_runtime), + keymap_evaluator(keymap_evaluator) { + + connect(this, &WindowMediator::keymap_added, this, + &WindowMediator::add_keymap); + + connect(this, &WindowMediator::history_back_requested, webview_stack, + &WebViewStack::webview_history_back); + connect(this, &WindowMediator::history_forward_requested, webview_stack, + &WebViewStack::webview_history_forward); + + connect(this, &WindowMediator::url_opened, webview_stack, + &WebViewStack::open_url); + connect(this, &WindowMediator::webview_closed, webview_stack, + &WebViewStack::close); + connect(this, &WindowMediator::webview_selected, webview_stack, + &WebViewStack::focus_webview); + + // TODO: Think of how to handle this for multi-window + 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 WindowMediator::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)); +} + +WindowMediator::~WindowMediator() { delete webview_stack; } |
