2026-08-17 01:14:00 +03:00
|
|
|
import QtQuick
|
|
|
|
|
import QtQuick.Controls
|
|
|
|
|
import QtQuick.Layouts
|
2026-09-01 19:25:07 +03:00
|
|
|
import Flora
|
2026-08-17 01:14:00 +03:00
|
|
|
|
|
|
|
|
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-09-01 19:25:07 +03:00
|
|
|
function insertText(t) { 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)
|
2026-09-01 19:25:07 +03:00
|
|
|
if (textDisplay.text !== c && !textDisplay.activeFocus)
|
|
|
|
|
textDisplay.text = c
|
|
|
|
|
if (!pane.editMode) {
|
|
|
|
|
viewDisplay.text = mdParser.render(c, fileStore.vault, filePathDir(documentManager.pathAt(idx)))
|
|
|
|
|
} else {
|
|
|
|
|
viewDisplay.text = ""
|
|
|
|
|
}
|
2026-08-18 00:17:12 +03:00
|
|
|
} else {
|
|
|
|
|
textDisplay.text = ""
|
2026-09-01 19:25:07 +03:00
|
|
|
viewDisplay.text = ""
|
2026-08-18 00:17:12 +03:00
|
|
|
}
|
|
|
|
|
}
|
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
|
2026-09-01 19:25:07 +03:00
|
|
|
function onContentChanged(idx) { if (idx === pane.docIndex && !textDisplay.activeFocus) refresh() }
|
|
|
|
|
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-09-01 19:25:07 +03:00
|
|
|
function applyInline(pre, post) {
|
|
|
|
|
if (!pane.editMode) return
|
|
|
|
|
textDisplay.forceActiveFocus()
|
|
|
|
|
const s = textDisplay.selectionStart, e = textDisplay.selectionEnd
|
|
|
|
|
if (s !== e) {
|
|
|
|
|
const sel = textDisplay.selectedText
|
|
|
|
|
textDisplay.remove(s, e)
|
|
|
|
|
textDisplay.insert(s, pre + sel + post)
|
|
|
|
|
textDisplay.select(s, s + pre.length + sel.length + post.length)
|
|
|
|
|
} else {
|
|
|
|
|
const pos = textDisplay.cursorPosition
|
|
|
|
|
textDisplay.insert(pos, pre + post)
|
|
|
|
|
textDisplay.cursorPosition = pos + pre.length
|
|
|
|
|
}
|
|
|
|
|
documentManager.updateContent(pane.docIndex, textDisplay.text)
|
|
|
|
|
}
|
|
|
|
|
function applyHeading(level) {
|
|
|
|
|
if (!pane.editMode) return
|
|
|
|
|
textDisplay.forceActiveFocus()
|
|
|
|
|
const txt = textDisplay.text
|
|
|
|
|
const pos = textDisplay.cursorPosition
|
|
|
|
|
let start = txt.lastIndexOf("\n", pos - 1) + 1
|
|
|
|
|
let end = txt.indexOf("\n", pos)
|
|
|
|
|
if (end < 0) end = txt.length
|
|
|
|
|
let line = txt.substring(start, end)
|
|
|
|
|
line = line.replace(/^#{1,6}\s*/, "")
|
|
|
|
|
const newLine = "#".repeat(level) + " " + line
|
|
|
|
|
textDisplay.remove(start, end)
|
|
|
|
|
textDisplay.insert(start, newLine)
|
|
|
|
|
textDisplay.cursorPosition = start + newLine.length
|
|
|
|
|
documentManager.updateContent(pane.docIndex, textDisplay.text)
|
|
|
|
|
}
|
|
|
|
|
function applyLinePrefix(prefix) {
|
|
|
|
|
if (!pane.editMode) return
|
|
|
|
|
textDisplay.forceActiveFocus()
|
|
|
|
|
const txt = textDisplay.text
|
|
|
|
|
const s = textDisplay.selectionStart, e = textDisplay.selectionEnd
|
|
|
|
|
let start = txt.lastIndexOf("\n", s - 1) + 1
|
|
|
|
|
let finish = txt.indexOf("\n", e)
|
|
|
|
|
if (finish < 0) finish = txt.length
|
|
|
|
|
const block = txt.substring(start, finish)
|
|
|
|
|
const newBlock = block.split("\n").map(l => prefix + l).join("\n")
|
|
|
|
|
textDisplay.remove(start, finish)
|
|
|
|
|
textDisplay.insert(start, newBlock)
|
|
|
|
|
textDisplay.select(start, start + newBlock.length)
|
|
|
|
|
documentManager.updateContent(pane.docIndex, textDisplay.text)
|
|
|
|
|
}
|
|
|
|
|
function applyTaskToggle() { applyLinePrefix("- [ ] ") }
|
|
|
|
|
function applyCallout(kind) { applyLinePrefix("> [!" + kind + "] ") }
|
|
|
|
|
function applyFloatWrap() {
|
|
|
|
|
if (!pane.editMode) return
|
|
|
|
|
textDisplay.forceActiveFocus()
|
|
|
|
|
textDisplay.insert(textDisplay.cursorPosition, "![[image.png|float:left|width:40%]]")
|
|
|
|
|
documentManager.updateContent(pane.docIndex, textDisplay.text)
|
|
|
|
|
}
|
|
|
|
|
function applyColor(color, highlightMode) {
|
|
|
|
|
if (highlightMode) applyInline('<span style="background-color:' + color + '">', '</span>')
|
|
|
|
|
else applyInline('<span style="color:' + color + '">', '</span>')
|
|
|
|
|
}
|
|
|
|
|
function applySubSup(kind) {
|
|
|
|
|
if (kind === "sup") applyInline("<sup>", "</sup>")
|
|
|
|
|
else applyInline("<sub>", "</sub>")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Текстовый редактор ---
|
|
|
|
|
ScrollView {
|
|
|
|
|
id: editScroll
|
2026-08-18 00:17:12 +03:00
|
|
|
anchors.fill: parent
|
2026-09-01 19:25:07 +03:00
|
|
|
anchors.bottomMargin: 36
|
2026-08-17 19:45:24 +03:00
|
|
|
visible: pane.editMode
|
2026-08-18 00:17:12 +03:00
|
|
|
clip: true
|
2026-09-01 19:25:07 +03:00
|
|
|
ScrollBar.vertical.policy: ScrollBar.AsNeeded
|
|
|
|
|
TextArea {
|
|
|
|
|
id: textDisplay
|
|
|
|
|
placeholderText: qsTr("Начните писать…")
|
|
|
|
|
placeholderTextColor: Theme.textFaint
|
|
|
|
|
color: Theme.editorText
|
|
|
|
|
selectionColor: Theme.selectionBg
|
|
|
|
|
selectedTextColor: Theme.text
|
|
|
|
|
font.family: "Menlo, Consolas, 'DejaVu Sans Mono', monospace"
|
|
|
|
|
font.pixelSize: 14
|
|
|
|
|
wrapMode: TextArea.NoWrap
|
|
|
|
|
selectByMouse: true
|
|
|
|
|
background: Rectangle { color: Theme.editorBg }
|
|
|
|
|
onTextChanged: if (activeFocus && text !== documentManager.contentAt(pane.docIndex)) editDebounce.restart()
|
|
|
|
|
}
|
2026-08-17 19:45:24 +03:00
|
|
|
}
|
2026-09-01 19:25:07 +03:00
|
|
|
Timer { id: editDebounce; interval: 250; onTriggered: documentManager.updateContent(pane.docIndex, textDisplay.text) }
|
2026-08-17 19:45:24 +03:00
|
|
|
|
2026-09-01 19:25:07 +03:00
|
|
|
ScrollView {
|
|
|
|
|
id: viewScroll
|
2026-08-18 00:17:12 +03:00
|
|
|
anchors.fill: parent
|
2026-09-01 19:25:07 +03:00
|
|
|
anchors.bottomMargin: 36
|
2026-08-17 19:45:24 +03:00
|
|
|
visible: !pane.editMode
|
2026-08-18 00:17:12 +03:00
|
|
|
clip: true
|
2026-09-01 19:25:07 +03:00
|
|
|
ScrollBar.vertical.policy: ScrollBar.AsNeeded
|
|
|
|
|
TextArea {
|
|
|
|
|
id: viewDisplay
|
|
|
|
|
readOnly: true
|
|
|
|
|
textFormat: Text.RichText
|
|
|
|
|
color: Theme.text
|
|
|
|
|
selectionColor: Theme.selectionBg
|
|
|
|
|
font.family: "Menlo, Consolas, 'DejaVu Sans Mono', monospace"
|
|
|
|
|
font.pixelSize: 14
|
|
|
|
|
wrapMode: TextArea.Wrap
|
|
|
|
|
background: Rectangle { color: Theme.editorBg }
|
|
|
|
|
onLinkActivated: (href) => {
|
|
|
|
|
if (href.startsWith("flora://copycode/")) {
|
2026-09-06 22:17:13 +03:00
|
|
|
if (mdParser.copyCodeBlock(href.substring(17))) { copyFeedback.visible = true; copyTimer.restart() }
|
2026-09-01 19:25:07 +03:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
}
|
2026-08-17 19:45:24 +03:00
|
|
|
}
|
2026-09-01 19:25:07 +03:00
|
|
|
} else if (href.startsWith("flora://open/")) {
|
|
|
|
|
documentManager.openDocument(decodeURIComponent(href.substring(13)))
|
|
|
|
|
} else {
|
|
|
|
|
Qt.openUrlExternally(href)
|
2026-08-17 19:45:24 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-09-01 19:25:07 +03:00
|
|
|
// Тост копирования
|
|
|
|
|
Rectangle {
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
anchors.topMargin: 8
|
|
|
|
|
visible: copyFeedback.visible
|
|
|
|
|
color: "#333"
|
|
|
|
|
radius: 6
|
|
|
|
|
width: copyFeedback.implicitWidth + 16
|
|
|
|
|
height: copyFeedback.implicitHeight + 10
|
|
|
|
|
z: 11
|
|
|
|
|
Label { id: copyFeedback; anchors.centerIn: parent; visible: false; text: qsTr("Скопировано!"); color: "white"; font.pixelSize: 11 }
|
|
|
|
|
}
|
|
|
|
|
Timer { id: copyTimer; interval: 1500; onTriggered: copyFeedback.visible = false }
|
2026-08-17 19:22:41 +03:00
|
|
|
}
|
|
|
|
|
|
2026-09-01 19:25:07 +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
|
2026-09-01 19:25:07 +03:00
|
|
|
height: 36
|
2026-08-18 00:17:12 +03:00
|
|
|
z: 10
|
2026-09-01 19:25:07 +03:00
|
|
|
color: Theme.toolbarBg
|
|
|
|
|
border.color: Theme.divider
|
2026-08-17 13:05:19 +03:00
|
|
|
|
2026-08-18 00:17:12 +03:00
|
|
|
RowLayout {
|
|
|
|
|
anchors.fill: parent
|
2026-09-01 19:25:07 +03:00
|
|
|
anchors.leftMargin: 8
|
|
|
|
|
anchors.rightMargin: 8
|
2026-08-18 00:17:12 +03:00
|
|
|
spacing: 4
|
2026-09-01 19:25:07 +03:00
|
|
|
Label {
|
|
|
|
|
visible: pane.docIndex >= 0
|
|
|
|
|
text: pane.docIndex >= 0 ? documentManager.titleAt(pane.docIndex) : ""
|
|
|
|
|
color: Theme.textMuted
|
|
|
|
|
font.pixelSize: 11
|
|
|
|
|
elide: Text.ElideMiddle
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
}
|
2026-08-18 00:17:12 +03:00
|
|
|
ToolButton {
|
|
|
|
|
text: "✎"
|
|
|
|
|
checkable: true
|
|
|
|
|
checked: pane.editMode
|
2026-09-01 19:25:07 +03:00
|
|
|
ToolTip.text: qsTr("Редактирование")
|
|
|
|
|
ToolTip.visible: hovered
|
2026-08-18 00:17:12 +03:00
|
|
|
onClicked: pane.editMode = true
|
|
|
|
|
}
|
|
|
|
|
ToolButton {
|
|
|
|
|
text: "👁"
|
|
|
|
|
checkable: true
|
|
|
|
|
checked: !pane.editMode
|
2026-09-01 19:25:07 +03:00
|
|
|
ToolTip.text: qsTr("Просмотр")
|
|
|
|
|
ToolTip.visible: hovered
|
2026-08-18 00:17:12 +03:00
|
|
|
onClicked: pane.editMode = false
|
|
|
|
|
}
|
|
|
|
|
ToolButton {
|
|
|
|
|
text: "\u2715"
|
|
|
|
|
visible: pane.closable
|
2026-09-01 19:25:07 +03:00
|
|
|
ToolTip.text: qsTr("Закрыть")
|
|
|
|
|
ToolTip.visible: hovered
|
2026-08-18 00:17:12 +03:00
|
|
|
onClicked: pane.closePane()
|
|
|
|
|
}
|
2026-08-17 01:14:00 +03:00
|
|
|
}
|
|
|
|
|
}
|
2026-08-17 19:22:41 +03:00
|
|
|
}
|