From bcecbced7e1af9d99443a7e823f18328c7943f09 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 29 Mar 2025 11:45:18 +0530 Subject: Add window action router for multi-window --- src/WindowMediator.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/WindowMediator.cpp (limited to 'src/WindowMediator.cpp') 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 +#include +#include + +#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 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; } -- cgit v1.3.1