Warning, /maui/nota/src/views/editor/Editor.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.14
0002 import QtQuick.Controls 2.14
0003 
0004 import org.mauikit.controls 1.3 as Maui
0005 import org.mauikit.texteditor 1.0 as TE
0006 
0007 import org.maui.nota 1.0 as Nota
0008 
0009 Maui.SplitViewItem
0010 {
0011     id: control
0012 
0013     property alias editor : _editor
0014     property alias fileUrl : _editor.fileUrl
0015     property alias title : _editor.title
0016 
0017     TE.TextEditor
0018     {
0019         id: _editor
0020         anchors.fill: parent
0021 
0022         showLineNumbers: settings.showLineNumbers
0023         property alias showLineCount : _linesCount.visible
0024 
0025         body.color: settings.textColor
0026         body.font.family: settings.font.family
0027         body.font.pointSize: settings.font.pointSize
0028 
0029         document.backgroundColor: settings.backgroundColor
0030         Maui.Theme.backgroundColor: settings.backgroundColor
0031 
0032         document.theme: settings.theme
0033         document.enableSyntaxHighlighting: settings.enableSyntaxHighlighting
0034         document.autoSave: settings.autoSave
0035         document.tabSpace: ((settings.tabSpace+1) * body.font.pointSize) / 2
0036 
0037         onFileUrlChanged: syncTerminal(_editor.fileUrl)
0038 
0039 //        footBar.visible: settings.showSyntaxHighlightingLanguages
0040 //        footBar.rightContent: ComboBox
0041 //        {
0042 //            model: editor.document.getLanguageNameList()
0043 //            currentIndex: -1
0044 //            onCurrentIndexChanged: editor.document.formatName = model[currentIndex]
0045 //        }
0046 
0047         Keys.enabled: true
0048         Keys.onPressed: (event) =>
0049         {
0050             if((event.key === Qt.Key_S) && (event.modifiers & Qt.ControlModifier))
0051             {
0052                 saveFile(document.fileUrl, _editor)
0053                 event.accepted = true
0054             }
0055 
0056             if((event.key === Qt.Key_T) && (event.modifiers & Qt.ControlModifier))
0057             {
0058                 syncTerminal(_editor.fileUrl)
0059                 _editor.terminal.forceActiveFocus()
0060                 event.accepted = true
0061             }
0062 
0063             if((event.key === Qt.Key_O) && (event.modifiers & Qt.ControlModifier))
0064             {
0065                 openFileDialog()
0066                 event.accepted = true
0067             }
0068 
0069             if((event.key === Qt.Key_N) && (event.modifiers & Qt.ControlModifier))
0070             {
0071                 openTab("")
0072                 event.accepted = true
0073             }
0074 
0075             if((event.key === Qt.Key_L) && (event.modifiers & Qt.ControlModifier))
0076             {
0077                 settings.showLineNumbers = !settings.showLineNumbers
0078                 event.accepted = true
0079             }
0080         }
0081 
0082         Loader
0083         {
0084             asynchronous: true
0085             anchors.fill: parent
0086 
0087             sourceComponent: DropArea
0088             {
0089                 id: _dropArea
0090                 property var urls : []
0091                 onDropped: (drop) =>
0092                 {
0093                     if(drop.urls)
0094                     {
0095                         var m_urls = drop.urls.join(",")
0096                         _dropArea.urls = m_urls.split(",")
0097                         _dropAreaMenu.show()
0098                     }
0099                 }
0100 
0101                 Maui.ContextualMenu
0102                 {
0103                     id: _dropAreaMenu
0104 
0105                     MenuItem
0106                     {
0107                         text: i18n("Open Here")
0108                         icon.name : "open-for-editing"
0109                         onTriggered:
0110                         {
0111                             _editor.fileUrl = _dropArea.urls[0]
0112                         }
0113                     }
0114 
0115                     MenuItem
0116                     {
0117                         text: i18n("Open in New Tab")
0118                         icon.name: "tab-new"
0119                         onTriggered:
0120                         {
0121                            openFiles( _dropArea.urls )
0122                         }
0123                     }
0124 
0125                     MenuItem
0126                     {
0127                         enabled: _dropArea.urls.length === 1 && currentTab.count <= 1 && settings.supportSplit
0128                         text: i18n("Open in New Split")
0129                         icon.name: "view-split-left-right"
0130                         onTriggered:
0131                         {
0132                             currentTab.split(_dropArea.urls[0])
0133                         }
0134                     }
0135 
0136                     MenuSeparator{}
0137 
0138                     MenuItem
0139                     {
0140                         text: i18n("Cancel")
0141                         icon.name: "dialog-cancel"
0142                         onTriggered:
0143                         {
0144                             _dropAreaMenu.close()
0145                         }
0146                     }
0147 
0148                     onClosed: _editor.forceActiveFocus()
0149                 }
0150             }
0151         }
0152 
0153         Maui.Chip
0154         {
0155             id: _linesCount
0156             visible: settings.showWordCount
0157             text: _editor.body.length + " / " + _editor.body.lineCount
0158             color: _editor.body.color
0159 
0160             anchors
0161             {
0162                 right: parent.right
0163                 top: parent.top
0164                 margins: Maui.Style.space.medium
0165             }
0166 
0167             opacity: 0.5
0168         }
0169     }
0170 
0171     Component.onCompleted:
0172     {
0173         _editor.forceActiveFocus()
0174     }
0175 }