Files
Flora/qml/panels/EditorPane.qml
T

141 lines
4.1 KiB
QML

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)
}
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()
// --- Текстовый редактор (сверху до низу, без шапки) ---
TextEdit {
id: textDisplay
anchors.fill: parent
anchors.bottomMargin: 32
visible: pane.editMode
clip: true
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)
}
// --- Режим просмотра ---
TextEdit {
id: viewDisplay
anchors.fill: parent
anchors.bottomMargin: 32
visible: !pane.editMode
readOnly: true
clip: 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)))
}
}
}
// --- Серая панель ВНИЗУ: кнопки ✎👁 × ---
Rectangle {
id: toolbar
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
height: 32
z: 10
color: "#e0e0e0"
border.color: "#ccc"
RowLayout {
anchors.fill: parent
anchors.rightMargin: 4
spacing: 4
Item { Layout.fillWidth: true }
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()
}
}
}
}