diff --git a/qml/TextEditor.qml b/qml/TextEditor.qml index 3d215bb..a5a349b 100644 --- a/qml/TextEditor.qml +++ b/qml/TextEditor.qml @@ -2,6 +2,7 @@ import QtQuick 2.15 import QtQml 2.15 import QtQuick.Window 2.15 import QtQuick.Controls 2.15 +import QtQuick.Layouts 1.15 import FishUI 1.0 as FishUI import Cutefish.TextEditor 1.0 @@ -9,9 +10,12 @@ Item { id: control property alias fileUrl: document.fileUrl - + property alias fileName: document.fileName property bool showLineNumbers: true + height: ListView.view.height + width: ListView.view.width + DocumentHandler { id: document document: body.textDocument @@ -34,8 +38,11 @@ Item { Keys.enabled: true Keys.forwardTo: body + contentWidth: availableWidth + Flickable { id: _flickable + boundsBehavior: Flickable.StopAtBounds boundsMovement: Flickable.StopAtBounds @@ -130,12 +137,12 @@ Item { id: _delegate readonly property int line : index - property bool foldable : control.document.isFoldable(line) + // property bool foldable : control.document.isFoldable(line) width: ListView.view.width height: Math.max(fontSize, document.lineHeight(line)) - readonly property real fontSize: control.body.font.pointSize + readonly property real fontSize: 11//control.body.font.pointSize readonly property bool isCurrentItem: ListView.isCurrentItem // Connections { diff --git a/qml/main.qml b/qml/main.qml index 3b0f500..fe48613 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -1,15 +1,127 @@ import QtQuick 2.15 import QtQuick.Window 2.15 +import QtQuick.Controls 2.15 +import QtQuick.Layouts 1.15 import FishUI 1.0 as FishUI FishUI.Window { width: 640 height: 480 visible: true - title: qsTr("Hello World") + title: qsTr("Text Editor") - TextEditor { + headerItem: Item { + TabBar { + anchors.fill: parent + + currentIndex : _container.currentIndex + + Repeater { + id: _repeater + model: _container.count + + TabButton { + text: _container.contentModel.get(index).fileName + implicitHeight: parent.height + implicitWidth: Math.max(parent.width / _repeater.count, 200) + + ToolTip.delay: 1000 + ToolTip.timeout: 5000 + hoverEnabled: true + + ToolTip.visible: hovered + ToolTip.text: _container.contentModel.get(index).fileUrl + + leftPadding: FishUI.Units.smallSpacing + rightPadding: FishUI.Units.smallSpacing + + onClicked: { + _container.currentIndex = index + _container.currentItem.forceActiveFocus() + } + } + } + } + } + + ColumnLayout { anchors.fill: parent - fileUrl: "file:///home/reion/Cutefish/core/notificationd/view.cpp" + spacing: 0 + + Container { + id: _container + + Layout.fillWidth: true + Layout.fillHeight: true + + contentItem: ColumnLayout { + spacing: 0 + + ListView { + id: _view + Layout.fillWidth: true + Layout.fillHeight: true + interactive: false + orientation: ListView.Horizontal + snapMode: ListView.SnapOneItem + currentIndex: _container.currentIndex + + model: _container.contentModel + + boundsBehavior: Flickable.StopAtBounds + boundsMovement :Flickable.StopAtBounds + + spacing: 0 + + preferredHighlightBegin: 0 + preferredHighlightEnd: width + + highlightRangeMode: ListView.StrictlyEnforceRange + highlightMoveDuration: 0 + highlightFollowsCurrentItem: true + highlightResizeDuration: 0 + highlightMoveVelocity: -1 + highlightResizeVelocity: -1 + + maximumFlickVelocity: 4 * width + + cacheBuffer: _view.count * width + keyNavigationEnabled : false + keyNavigationWraps : false + } + } + } + + Item { + Layout.fillWidth: true + Layout.preferredHeight: 20 + + ColumnLayout { + anchors.fill: parent + } + } + } + + function addTab() { + const component = textEditorCompeont + const object = component.createObject(_container.contentModel) + + _container.addItem(object) + _container.currentIndex = Math.max(_container.count - 1, 0) + object.forceActiveFocus() + } + + Component { + id: textEditorCompeont + + TextEditor { + fileUrl: "file:///home/reion/Cutefish/core/notificationd/view.cpp" + } + } + + Component.onCompleted: { + addTab() + addTab() + addTab() } } diff --git a/src/documenthandler.cpp b/src/documenthandler.cpp index 65844b3..fb67310 100644 --- a/src/documenthandler.cpp +++ b/src/documenthandler.cpp @@ -713,6 +713,10 @@ void DocumentHandler::setFileUrl(const QUrl &url) m_fileUrl = url; + QFileInfo info(m_fileUrl.toLocalFile()); + m_fileName = info.fileName(); + emit fileNameChanged(); + load(m_fileUrl); emit fileUrlChanged(); @@ -1135,6 +1139,11 @@ void DocumentHandler::setEnableSyntaxHighlighting(const bool &value) emit enableSyntaxHighlightingChanged(); } +QString DocumentHandler::fileName() +{ + return m_fileName; +} + bool DocumentHandler::enableSyntaxHighlighting() const { return m_enableSyntaxHighlighting; diff --git a/src/documenthandler.h b/src/documenthandler.h index 8642b79..c2c1105 100644 --- a/src/documenthandler.h +++ b/src/documenthandler.h @@ -288,6 +288,8 @@ class DocumentHandler : public QObject Q_PROPERTY(bool findCaseSensitively MEMBER m_findCaseSensitively NOTIFY findCaseSensitivelyChanged) + Q_PROPERTY(QString fileName MEMBER m_fileName NOTIFY fileNameChanged) + public: explicit DocumentHandler(QObject *parent = nullptr); ~DocumentHandler(); @@ -597,6 +599,8 @@ public: return (darkness > 0.5); } + QString fileName(); + public slots: /** * @brief load @@ -711,6 +715,8 @@ signals: void findWholeWordsChanged(); // void cursorYPosChanged(); + void fileNameChanged(); + private: void reset(); void setStyle(); @@ -766,6 +772,8 @@ private: QTimer m_autoSaveTimer; + QString m_fileName; + void refreshAllBlocks(); };