Lua: Add possibility to get all opened editors

Change-Id: Iae68fca2ec0f42043b3e4db7de91babba60e29e0
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Krzysztof Chrusciel
2025-04-08 15:42:23 +02:00
parent 3d7b75a352
commit 48a7c050c0
3 changed files with 15 additions and 0 deletions

View File

@@ -224,6 +224,15 @@ void setupTextEditorModule()
return BaseTextEditor::currentTextEditor(); return BaseTextEditor::currentTextEditor();
}; };
result["openedEditors"] = [lua]() mutable -> sol::table {
QList<BaseTextEditor *> editors = BaseTextEditor::openedTextEditors();
sol::table result = lua.create_table();
for (auto& editor : editors) {
result.add(TextEditorPtr(editor));
}
return result;
};
result.new_usertype<MultiTextCursor>( result.new_usertype<MultiTextCursor>(
"MultiTextCursor", "MultiTextCursor",
sol::no_constructor, sol::no_constructor,

View File

@@ -10364,6 +10364,11 @@ BaseTextEditor *BaseTextEditor::currentTextEditor()
return qobject_cast<BaseTextEditor *>(EditorManager::currentEditor()); return qobject_cast<BaseTextEditor *>(EditorManager::currentEditor());
} }
QList<BaseTextEditor *> BaseTextEditor::openedTextEditors()
{
return qobject_container_cast<BaseTextEditor *>(DocumentModel::editorsForOpenedDocuments());
}
QVector<BaseTextEditor *> BaseTextEditor::textEditorsForDocument(TextDocument *textDocument) QVector<BaseTextEditor *> BaseTextEditor::textEditorsForDocument(TextDocument *textDocument)
{ {
QVector<BaseTextEditor *> ret; QVector<BaseTextEditor *> ret;

View File

@@ -127,6 +127,7 @@ public:
virtual void finalizeInitialization() {} virtual void finalizeInitialization() {}
static BaseTextEditor *currentTextEditor(); static BaseTextEditor *currentTextEditor();
static QList<BaseTextEditor *> openedTextEditors();
static QVector<BaseTextEditor *> textEditorsForDocument(TextDocument *textDocument); static QVector<BaseTextEditor *> textEditorsForDocument(TextDocument *textDocument);
TextEditorWidget *editorWidget() const; TextEditorWidget *editorWidget() const;