Warning, /office/klevernotes/src/contents/ui/textEditor/TextEditor.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2023 Louis Schul <schul9louis@gmail.com>
0003 
0004 import QtQuick 2.15
0005 import QtQuick.Controls 2.2
0006 
0007 import org.kde.Klever 1.0
0008 
0009 ScrollView {
0010     id: view
0011 
0012     readonly property TextArea textArea: textArea
0013 
0014     property string path
0015     property string text: textArea.text
0016     property bool modified : false
0017 
0018     // Without it the background is from Theme.Window instead of Theme.View
0019     background: Item {}
0020 
0021     onPathChanged: {
0022         textArea.tempBuff = true ;
0023         textArea.text = DocumentHandler.readFile(path) ;
0024         modified = false ;
0025         textArea.tempBuff = false
0026     }
0027 
0028     TextArea{
0029         id: textArea
0030 
0031         property bool tempBuff
0032 
0033         font: Config.editorFont
0034         wrapMode: TextEdit.Wrap
0035         persistentSelection: true
0036 
0037         onTextChanged: if (!tempBuff) {
0038             modified = true
0039         }
0040     }
0041 
0042     Timer {
0043         id: noteSaverTimer
0044 
0045         interval: 10000
0046 
0047         onTriggered: {
0048             saveNote(textArea.text, view.path)
0049         }
0050     }
0051 
0052     function saveNote (text, path) {
0053         if (modified) {
0054             DocumentHandler.writeFile(text, path)
0055             modified = false
0056         }
0057     }
0058 }