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-17 19:22:41 +03:00
|
|
|
// Шапка файла — плавающий оверлей
|
2026-08-17 18:53:08 +03:00
|
|
|
Rectangle {
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
height: 30
|
2026-08-17 19:13:10 +03:00
|
|
|
z: 10
|
|
|
|
|
color: "#f0f0f0"
|
|
|
|
|
border.color: "#ddd"
|
2026-08-17 18:53:08 +03:00
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
anchors.leftMargin: 8
|
|
|
|
|
anchors.rightMargin: 4
|
|
|
|
|
spacing: 6
|
2026-08-17 01:14:00 +03:00
|
|
|
|
2026-08-17 18:53:08 +03:00
|
|
|
Label {
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
elide: Text.ElideMiddle
|
|
|
|
|
color: "#444"
|
2026-08-17 19:22:41 +03:00
|
|
|
text: documentManager.titleAt(pane.docIndex)
|
2026-08-17 01:14:00 +03:00
|
|
|
}
|
|
|
|
|
|
2026-08-17 18:53:08 +03:00
|
|
|
ToolButton {
|
|
|
|
|
text: "✎"
|
|
|
|
|
checkable: true
|
|
|
|
|
checked: pane.editMode
|
2026-08-17 19:22:41 +03:00
|
|
|
onClicked: pane.editMode = true
|
2026-08-17 01:14:00 +03:00
|
|
|
}
|
2026-08-17 18:53:08 +03:00
|
|
|
ToolButton {
|
|
|
|
|
text: "👁"
|
|
|
|
|
checkable: true
|
|
|
|
|
checked: !pane.editMode
|
2026-08-17 19:22:41 +03:00
|
|
|
onClicked: pane.editMode = false
|
2026-08-17 16:38:22 +03:00
|
|
|
}
|
2026-08-17 18:53:08 +03:00
|
|
|
ToolButton {
|
|
|
|
|
text: "\u2715"
|
|
|
|
|
visible: pane.closable
|
|
|
|
|
onClicked: pane.closePane()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-17 19:33:17 +03:00
|
|
|
// Текст файла — TextEdit внутри Flickable
|
2026-08-17 19:26:03 +03:00
|
|
|
Flickable {
|
|
|
|
|
id: flickable
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
contentWidth: textDisplay.paintedWidth
|
|
|
|
|
contentHeight: textDisplay.paintedHeight
|
|
|
|
|
clip: true
|
|
|
|
|
flickableDirection: Flickable.VerticalFlick
|
2026-08-17 19:22:41 +03:00
|
|
|
|
2026-08-17 19:33:17 +03:00
|
|
|
// ВРЕМЕННЫЙ красный фон для отладки размеров
|
|
|
|
|
Rectangle {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
color: "red"
|
|
|
|
|
z: -1
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-17 19:26:03 +03:00
|
|
|
TextEdit {
|
|
|
|
|
id: textDisplay
|
|
|
|
|
width: flickable.width
|
|
|
|
|
text: documentManager.activeIndex >= 0
|
|
|
|
|
? documentManager.contentAt(documentManager.activeIndex)
|
|
|
|
|
: ""
|
|
|
|
|
color: "black"
|
|
|
|
|
font.family: "Menlo, Consolas, 'DejaVu Sans Mono', monospace"
|
|
|
|
|
font.pixelSize: 14
|
|
|
|
|
wrapMode: TextEdit.NoWrap
|
|
|
|
|
readOnly: true
|
|
|
|
|
selectByMouse: true
|
2026-08-17 19:22:41 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Загрузка контента при смене файла
|
|
|
|
|
function refresh() {
|
|
|
|
|
const idx = pane.docIndex
|
|
|
|
|
if (idx >= 0) {
|
|
|
|
|
const c = documentManager.contentAt(idx)
|
2026-08-17 19:26:03 +03:00
|
|
|
textDisplay.text = c
|
2026-08-17 16:24:28 +03:00
|
|
|
} else {
|
2026-08-17 19:26:03 +03:00
|
|
|
textDisplay.text = ""
|
2026-08-17 16:24:28 +03:00
|
|
|
}
|
|
|
|
|
}
|
2026-08-17 13:05:19 +03:00
|
|
|
|
2026-08-17 19:22:41 +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-17 19:22:41 +03:00
|
|
|
|
|
|
|
|
onDocIndexChanged: refresh()
|
2026-08-17 19:26:03 +03:00
|
|
|
onEditModeChanged: { refresh() }
|
2026-08-17 19:22:41 +03:00
|
|
|
|
2026-08-17 01:14:00 +03:00
|
|
|
Connections {
|
|
|
|
|
target: documentManager
|
2026-08-17 16:24:28 +03:00
|
|
|
function onActiveIndexChanged() {
|
2026-08-17 19:22:41 +03:00
|
|
|
if (documentManager.activeIndex === pane.docIndex)
|
|
|
|
|
refresh()
|
2026-08-17 01:14:00 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-17 19:22:41 +03:00
|
|
|
Component.onCompleted: refresh()
|
|
|
|
|
}
|