Files
qt-creator/src/plugins/lua/bindings/hook.cpp

39 lines
1.2 KiB
C++
Raw Normal View History

// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "../luaengine.h"
#include <coreplugin/editormanager/editormanager.h>
#include <texteditor/textdocument.h>
namespace Lua {
namespace Internal {
void addHookModule()
{
LuaEngine::registerHook("editors.documentOpened", [](const sol::protected_function &func) {
QObject::connect(
Core::EditorManager::instance(),
&Core::EditorManager::documentOpened,
[func](Core::IDocument *document) {
Utils::expected_str<void> res = LuaEngine::void_safe_call(func, document);
QTC_CHECK_EXPECTED(res);
});
});
LuaEngine::registerHook("editors.documentClosed", [](const sol::protected_function &func) {
QObject::connect(
Core::EditorManager::instance(),
&Core::EditorManager::documentClosed,
[func](Core::IDocument *document) {
Utils::expected_str<void> res = LuaEngine::void_safe_call(func, document);
QTC_CHECK_EXPECTED(res);
});
});
}
} // namespace Internal
} // namespace Lua