Files
Flora/qml/panels/EditorPane.qml
T

128 lines
3.5 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)
}
// Шапка файла — плавающий оверлей
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()
}
}
}
// Текст файла — Text вместо TextArea (гарантированный рендеринг)
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
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
MouseArea {
anchors.fill: parent
onWheel: (w) => {
if (w.angleDelta.y > 0)
flickable.contentY = Math.max(0, flickable.contentY - 30)
else
flickable.contentY = Math.min(flickable.contentHeight - flickable.height, flickable.contentY + 30)
}
}
}
}
// Загрузка контента при смене файла
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()
}