2026-08-17 01:14:00 +03:00
|
|
|
import QtQuick
|
|
|
|
|
import QtQuick.Controls
|
|
|
|
|
import QtQuick.Layouts
|
|
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
id: pane
|
|
|
|
|
|
|
|
|
|
property int docIndex: -1
|
|
|
|
|
property bool editMode: true
|
2026-08-17 19:22:41 +03:00
|
|
|
property bool canOpenBeside: false
|
|
|
|
|
property bool closable: false
|
2026-08-17 01:14:00 +03:00
|
|
|
|
|
|
|
|
signal openBeside()
|
|
|
|
|
signal closePane()
|
|
|
|
|
|
2026-08-17 12:34:03 +03:00
|
|
|
function insertText(t) {
|
2026-08-17 19:26:03 +03:00
|
|
|
textDisplay.insert(textDisplay.cursorPosition, t)
|
2026-08-17 12:34:03 +03:00
|
|
|
}
|
|
|
|
|
|
2026-08-18 00:17:12 +03:00
|
|
|
function refresh() {
|
|
|
|
|
const idx = pane.docIndex
|
|
|
|
|
if (idx >= 0) {
|
|
|
|
|
const c = documentManager.contentAt(idx)
|
|
|
|
|
textDisplay.text = c
|
|
|
|
|
} else {
|
|
|
|
|
textDisplay.text = ""
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-08-17 18:53:08 +03:00
|
|
|
|
2026-08-18 00:17:12 +03:00
|
|
|
function filePathDir(p) {
|
|
|
|
|
const i = p.lastIndexOf("/")
|
|
|
|
|
return i >= 0 ? p.substring(0, i) : p
|
|
|
|
|
}
|
2026-08-17 01:14:00 +03:00
|
|
|
|
2026-08-18 00:17:12 +03:00
|
|
|
onDocIndexChanged: refresh()
|
|
|
|
|
onEditModeChanged: refresh()
|
2026-08-17 01:14:00 +03:00
|
|
|
|
2026-08-18 00:17:12 +03:00
|
|
|
Connections {
|
|
|
|
|
target: documentManager
|
|
|
|
|
function onActiveIndexChanged() {
|
|
|
|
|
if (documentManager.activeIndex === pane.docIndex)
|
|
|
|
|
refresh()
|
2026-08-17 18:53:08 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-18 00:17:12 +03:00
|
|
|
Component.onCompleted: refresh()
|
|
|
|
|
|
|
|
|
|
// --- Текстовый редактор (сверху до низу, без шапки) ---
|
2026-08-17 19:41:26 +03:00
|
|
|
TextEdit {
|
|
|
|
|
id: textDisplay
|
2026-08-18 00:17:12 +03:00
|
|
|
anchors.fill: parent
|
|
|
|
|
anchors.bottomMargin: 32
|
2026-08-17 19:45:24 +03:00
|
|
|
visible: pane.editMode
|
2026-08-18 00:17:12 +03:00
|
|
|
clip: true
|
2026-08-17 19:41:26 +03:00
|
|
|
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
|
2026-08-17 19:45:24 +03:00
|
|
|
onTextEdited: documentManager.updateContent(pane.docIndex, text)
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-18 00:17:12 +03:00
|
|
|
// --- Режим просмотра ---
|
2026-08-17 19:45:24 +03:00
|
|
|
TextEdit {
|
|
|
|
|
id: viewDisplay
|
2026-08-18 00:17:12 +03:00
|
|
|
anchors.fill: parent
|
|
|
|
|
anchors.bottomMargin: 32
|
2026-08-17 19:45:24 +03:00
|
|
|
visible: !pane.editMode
|
|
|
|
|
readOnly: true
|
2026-08-18 00:17:12 +03:00
|
|
|
clip: true
|
2026-08-17 19:45:24 +03:00
|
|
|
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)))
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-08-17 19:22:41 +03:00
|
|
|
}
|
|
|
|
|
|
2026-08-18 00:17:12 +03:00
|
|
|
// --- Серая панель ВНИЗУ: кнопки ✎👁 × ---
|
|
|
|
|
Rectangle {
|
|
|
|
|
id: toolbar
|
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
height: 32
|
|
|
|
|
z: 10
|
|
|
|
|
color: "#e0e0e0"
|
|
|
|
|
border.color: "#ccc"
|
2026-08-17 13:05:19 +03:00
|
|
|
|
2026-08-18 00:17:12 +03:00
|
|
|
RowLayout {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
anchors.rightMargin: 4
|
|
|
|
|
spacing: 4
|
2026-08-17 19:22:41 +03:00
|
|
|
|
2026-08-18 00:17:12 +03:00
|
|
|
Item { Layout.fillWidth: true }
|
2026-08-17 19:22:41 +03:00
|
|
|
|
2026-08-18 00:17:12 +03:00
|
|
|
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()
|
|
|
|
|
}
|
2026-08-17 01:14:00 +03:00
|
|
|
}
|
|
|
|
|
}
|
2026-08-17 19:22:41 +03:00
|
|
|
}
|