Warning, /maui/buho/src/widgets/NewNoteDialog.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 2.14
0002 import QtQuick.Controls 2.14
0003 import QtQuick.Layouts 1.0
0004
0005 import org.mauikit.controls 1.3 as Maui
0006 import org.mauikit.filebrowsing 1.3 as FB
0007 import org.mauikit.texteditor 1.0 as TE
0008
0009
0010 Maui.Page
0011 {
0012
0013 id: control
0014
0015 property alias editor: _editor
0016 property alias document: _editor.document
0017
0018 property string tagColor: note.color ? note.color : "transparent"
0019 property bool showEditActions : false
0020 property var note : ({})
0021 property int noteIndex : -1
0022
0023 property alias text: _editor.text
0024
0025 signal noteSaved(var note, int noteIndex)
0026
0027 headBar.farLeftContent: ToolButton
0028 {
0029 icon.name: "go-previous"
0030 onClicked:
0031 {
0032 console.log(control.document.fileUrl, "File Url")
0033
0034
0035 if(FB.FM.fileExists(control.document.fileUrl) && control.document.modified)
0036 {
0037 control.document.saveAs(control.document.fileUrl)
0038 }
0039
0040 control.noteSaved(packNote(), control.noteIndex)
0041 control.clear()
0042 control.parent.pop()
0043 }
0044 }
0045
0046 headBar.visible: !editor.body.readOnly
0047 headBar.leftContent: [
0048
0049 Maui.ToolActions
0050 {
0051 expanded: true
0052 autoExclusive: false
0053 checkable: false
0054
0055 Action
0056 {
0057 icon.name: "edit-undo"
0058 enabled: editor.body.canUndo
0059 onTriggered: editor.body.undo()
0060 }
0061
0062 Action
0063 {
0064 icon.name: "edit-redo"
0065 enabled: editor.body.canRedo
0066 onTriggered: editor.body.redo()
0067 }
0068 },
0069
0070 Maui.ToolActions
0071 {
0072 visible: (document.isRich || editor.body.textFormat === Text.RichText) && !editor.body.readOnly
0073 expanded: true
0074 autoExclusive: false
0075 checkable: false
0076
0077 Action
0078 {
0079 icon.name: "format-text-bold"
0080 checked: document.bold
0081 onTriggered: document.bold = !document.bold
0082 }
0083
0084 Action
0085 {
0086 icon.name: "format-text-italic"
0087 checked: document.italic
0088 onTriggered: document.italic = !document.italic
0089 }
0090
0091 Action
0092 {
0093 icon.name: "format-text-underline"
0094 checked: document.underline
0095 onTriggered: document.underline = !document.underline
0096 }
0097
0098 Action
0099 {
0100 icon.name: "format-text-uppercase"
0101 checked: document.uppercase
0102 onTriggered: document.uppercase = !document.uppercase
0103 }
0104 }
0105 ]
0106
0107 headBar.rightContent: [
0108
0109 ToolButton
0110 {
0111 id: favButton
0112 icon.name: "love"
0113 checkable: true
0114 checked: note.favorite == 1
0115 icon.color: checked ? "#ff007f" : Maui.Theme.textColor
0116
0117 },
0118
0119 ToolButton
0120 {
0121 icon.name: "document-share"
0122
0123 onClicked: Maui.Handy.isAndroid ? Maui.Android.shareText(editor.body.text) :
0124 Maui.Platform.shareFiles(editor.fileUrl)
0125 },
0126
0127 Maui.ToolButtonMenu
0128 {
0129 icon.name: "overflow-menu"
0130
0131 MenuItem
0132 {
0133 icon.name: "edit-find"
0134 text: i18n("Find and Replace")
0135 checked: editor.showFindBar
0136 checkable: true
0137 onTriggered: editor.showFindBar = !editor.showFindBar
0138 }
0139
0140 MenuSeparator {}
0141
0142 MenuItem
0143 {
0144 text: i18n("Delete")
0145 icon.name: "entry-delete"
0146 Maui.Theme.textColor: Maui.Theme.negativeTextColor
0147 onTriggered: {}
0148 }
0149
0150 MenuSeparator {}
0151
0152 Item
0153 {
0154 height: Maui.Style.rowHeight
0155 width: parent.width
0156
0157 ColorsBar
0158 {
0159 anchors.centerIn: parent
0160 onColorPicked:
0161 {
0162 control.tagColor = color
0163 }
0164
0165 currentColor: control.tagColor
0166 }
0167 }
0168 }
0169 ]
0170
0171 TE.TextEditor
0172 {
0173 id: _editor
0174 anchors.fill: parent
0175
0176 fileUrl: control.note.url
0177 showLineNumbers: false
0178 document.autoReload: settings.autoReload
0179 document.autoSave: settings.autoSave
0180 spellcheckEnabled: settings.spellcheckEnabled
0181
0182 body.font: settings.font
0183
0184 document.enableSyntaxHighlighting: false
0185 body.placeholderText: i18n("Title\nBody")
0186
0187 Rectangle
0188 {
0189 anchors.bottom: parent.bottom
0190 anchors.left: parent.left
0191 anchors.right: parent.right
0192 color: control.tagColor
0193 height : 12
0194 }
0195
0196 Timer
0197 {
0198 id: _notifyTimer
0199 running: false
0200 interval: 2500
0201 }
0202
0203 Maui.Chip
0204 {
0205 anchors.top: parent.top
0206 anchors.right: parent.right
0207 anchors.margins: Maui.Style.space.big
0208 visible: _notifyTimer.running
0209 label.text: i18n("Note saved")
0210 iconSource: "document-save"
0211 Maui.Theme.backgroundColor: "yellow"
0212 }
0213
0214 Connections
0215 {
0216 target: control.document
0217 function onFileSaved()
0218 {
0219 console.log("NOTE SAVED")
0220 _notifyTimer.start()
0221 // control.noteSaved(packNote())
0222 }
0223 }
0224 }
0225
0226 function clear()
0227 {
0228 editor.body.clear()
0229 control.note = ({})
0230 }
0231
0232 function packNote()
0233 {
0234 var note = ({})
0235 const content = editor.body.text
0236 if(content.length > 0)
0237 {
0238 note = {
0239 url: editor.fileUrl,
0240 content: content,
0241 favorite: favButton.checked ? 1 : 0,
0242 format: ".txt" //for now only simple txt files
0243 }
0244
0245 if(control.tagColor !== "transparent")
0246 {
0247 note["color"] = control.tagColor
0248 }
0249 }
0250
0251 return note
0252 }
0253 }