import QtQuick import QtQuick.Controls import QtQuick.Layouts Item { id: pane property int docIndex: -1 property bool editMode: true property bool canOpenBeside: false property bool closable: false signal openBeside() signal closePane() function insertText(t) { textDisplay.insert(textDisplay.cursorPosition, t) } // Шапка файла — плавающий оверлей Rectangle { anchors.top: parent.top anchors.left: parent.left anchors.right: parent.right height: 30 z: 10 color: "#f0f0f0" border.color: "#ddd" RowLayout { anchors.fill: parent anchors.leftMargin: 8 anchors.rightMargin: 4 spacing: 6 Label { Layout.fillWidth: true elide: Text.ElideMiddle color: "#444" text: documentManager.titleAt(pane.docIndex) } ToolButton { text: "✎" checkable: true checked: pane.editMode onClicked: pane.editMode = true } ToolButton { text: "👁" checkable: true checked: !pane.editMode onClicked: pane.editMode = false } ToolButton { text: "\u2715" visible: pane.closable onClicked: pane.closePane() } } } // Текст файла — TextEdit напрямую TextEdit { id: textDisplay anchors.top: headerBar.bottom anchors.left: parent.left anchors.right: parent.right anchors.bottom: parent.bottom visible: pane.editMode text: documentManager.activeIndex >= 0 ? documentManager.contentAt(documentManager.activeIndex) : "" color: "black" font.family: "Menlo, Consolas, 'DejaVu Sans Mono', monospace" font.pixelSize: 14 wrapMode: TextEdit.NoWrap selectByMouse: true onTextEdited: documentManager.updateContent(pane.docIndex, text) } // Режим просмотра (read-only) TextEdit { id: viewDisplay anchors.top: headerBar.bottom anchors.left: parent.left anchors.right: parent.right anchors.bottom: parent.bottom visible: !pane.editMode readOnly: true text: pane.editMode ? "" : mdParser.render( documentManager.contentAt(pane.docIndex), fileStore.vault, filePathDir(documentManager.pathAt(pane.docIndex)) ) textFormat: TextEdit.RichText color: "black" font.family: "Menlo, Consolas, 'DejaVu Sans Mono', monospace" font.pixelSize: 14 wrapMode: TextEdit.Wrap onLinkActivated: (href) => { if (href.startsWith("flora://task/")) { const line = Number(href.substring(14)) if (line > 0) { const lines = textDisplay.text.split("\n") const ln = lines[line - 1] if (ln !== undefined) { if (/\[ \]/.test(ln)) lines[line - 1] = ln.replace("[ ]", "[x]") else if (/\[x\]/.test(ln)) lines[line - 1] = ln.replace("[x]", "[ ]") textDisplay.text = lines.join("\n") documentManager.updateContent(pane.docIndex, textDisplay.text) } } } else if (href.startsWith("flora://open/")) { documentManager.openDocument(decodeURIComponent(href.substring(13))) } } } // Загрузка контента при смене файла function refresh() { const idx = pane.docIndex if (idx >= 0) { const c = documentManager.contentAt(idx) textDisplay.text = c } else { textDisplay.text = "" } } function filePathDir(p) { const i = p.lastIndexOf("/") return i >= 0 ? p.substring(0, i) : p } onDocIndexChanged: refresh() onEditModeChanged: { refresh() } Connections { target: documentManager function onActiveIndexChanged() { if (documentManager.activeIndex === pane.docIndex) refresh() } } Component.onCompleted: refresh() }