Warning, /maui/buho/src/views/notes/NotesView.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.3
0004
0005 import org.mauikit.controls 1.3 as Maui
0006 import org.mauikit.accounts 1.0 as MA
0007
0008 import org.maui.buho 1.0
0009
0010 import "../../widgets"
0011
0012 StackView
0013 {
0014 id: control
0015 property var currentNote : ({})
0016
0017 property alias cardsView : cardsView
0018
0019 property alias list : notesList
0020 property alias model : notesModel
0021
0022 property alias currentIndex : cardsView.currentIndex
0023
0024 readonly property Flickable flickable : currentItem.flickable
0025
0026 readonly property bool editing : control.depth > 1
0027
0028 function setNote(note)
0029 {
0030 control.push(_editNoteComponent)
0031 control.currentItem.editor.body.forceActiveFocus()
0032 control.currentItem.noteIndex = control.currentIndex
0033 }
0034
0035 function newNote(contents)
0036 {
0037 control.push(_newNoteComponent, {'text': contents})
0038 control.currentItem.editor.body.forceActiveFocus()
0039 }
0040
0041 Action
0042 {
0043 id: _pasteAction
0044 text: i18n("Paste")
0045 icon.name: "edit-paste"
0046 shortcut: "Ctrl+V"
0047 onTriggered:
0048 {
0049 console.log("PASTE NOTE FROM CLIPBOARD")
0050 newNote(Maui.Handy.getClipboardText())
0051 }
0052 }
0053
0054 Component
0055 {
0056 id: _editNoteComponent
0057
0058 NewNoteDialog
0059 {
0060 note: control.currentNote
0061 onNoteSaved: (note, noteIndex) =>
0062 {
0063 console.log("updating note <<" , note , control.currentIndex , noteIndex, notesModel.mappedToSource(noteIndex))
0064 control.list.update(note, notesModel.mappedToSource(noteIndex))
0065 }
0066 }
0067 }
0068
0069 Component
0070 {
0071 id: _newNoteComponent
0072 NewNoteDialog
0073 {
0074 onNoteSaved: (note, noteIndex) => control.list.insert(note)
0075 }
0076 }
0077
0078 Maui.InfoDialog
0079 {
0080 id: _removeNotesDialog
0081
0082 property var notes
0083
0084 title: i18n("Remove notes")
0085 message: i18n("Are you sure you want to delete the selected notes?")
0086
0087 template.iconSource: "view-notes"
0088
0089 onAccepted:
0090 {
0091 console.log (notes)
0092 }
0093
0094 onRejected: close()
0095 }
0096
0097 initialItem: Maui.AltBrowser
0098 {
0099 id: cardsView
0100 gridView.itemSize: Math.min(300, control.width* 0.4)
0101 gridView.cellHeight: 180
0102
0103 enableLassoSelection: true
0104
0105 viewType: control.width > Maui.Style.units.gridUnit * 30 ? Maui.AltBrowser.ViewType.Grid : Maui.AltBrowser.ViewType.List
0106
0107 floatingFooter: true
0108 altHeader: Maui.Handy.isMobile
0109
0110 holder.visible: notesList.count === 0 || cardsView.count === 0
0111 holder.emoji: "qrc:/view-notes.svg"
0112 holder.title :i18n("No notes!")
0113 holder.body: i18n("You can quickly create a new note")
0114
0115 holder.actions:[ Action
0116 {
0117 text: i18n("New note")
0118 icon.name: "list-add"
0119 onTriggered: control.newNote()
0120 }]
0121
0122 headBar.rightContent: ToolButton
0123 {
0124 icon.name: "list-add"
0125 onClicked: control.newNote()
0126 }
0127
0128 headBar.forceCenterMiddleContent: root.isWide
0129 headBar.middleContent: Loader
0130 {
0131 Layout.fillWidth: true
0132 Layout.maximumWidth: 500
0133 Layout.alignment: Qt.AlignCenter
0134 // active: notesList.count > 0
0135 // visible: active
0136 asynchronous: true
0137
0138 sourceComponent: Maui.SearchField
0139 {
0140 placeholderText: i18n("Search ") + control.list.count + " " + i18n("notes")
0141 onAccepted: control.model.filter = text
0142 onCleared: control.model.filter = ""
0143 }
0144 }
0145
0146 headBar.leftContent: Maui.ToolButtonMenu
0147 {
0148 icon.name: "application-menu"
0149
0150 MA.AccountsMenuItem{}
0151
0152 MenuItem
0153 {
0154 text: i18n("Settings")
0155 icon.name: "settings-configure"
0156 onTriggered: _settingsDialog.open()
0157 }
0158
0159 MenuItem
0160 {
0161 text: i18n("About")
0162 icon.name: "documentinfo"
0163 onTriggered: root.about()
0164 }
0165 }
0166
0167 property string typingQuery
0168
0169 Maui.Chip
0170 {
0171 z: cardsView.z + 99999
0172 Maui.Theme.colorSet:Maui.Theme.Complementary
0173 visible: _typingTimer.running
0174 label.text: cardsView.typingQuery
0175 anchors.left: parent.left
0176 anchors.bottom: parent.bottom
0177 showCloseButton: false
0178 anchors.margins: Maui.Style.space.medium
0179 }
0180
0181 Timer
0182 {
0183 id: _typingTimer
0184 interval: 250
0185 onTriggered:
0186 {
0187 const index = notesList.indexOfName(cardsView.typingQuery)
0188 if(index > -1)
0189 {
0190 control.currentIndex = notesModel.mappedFromSource(index)
0191 }
0192
0193 cardsView.typingQuery = ""
0194 }
0195 }
0196
0197 Connections
0198 {
0199 target: cardsView.currentView
0200 ignoreUnknownSignals: true
0201
0202 function onItemsSelected(indexes)
0203 {
0204 console.log(indexes)
0205 for(var index of indexes)
0206 select(notesModel.get(index))
0207 }
0208
0209 function onKeyPress(event)
0210 {
0211 const index = cardsView.currentIndex
0212 const item = notesModel.get(index)
0213
0214 var pat = /^([a-zA-Z0-9 _-]+)$/
0215 if(event.count === 1 && pat.test(event.text))
0216 {
0217 cardsView.typingQuery += event.text
0218 _typingTimer.restart()
0219 }
0220
0221 if((event.key == Qt.Key_Left || event.key == Qt.Key_Right || event.key == Qt.Key_Down || event.key == Qt.Key_Up) && (event.modifiers & Qt.ControlModifier) && (event.modifiers & Qt.ShiftModifier))
0222 {
0223 cardsView.currentView.itemsSelected([index])
0224 }
0225
0226 if(event.key === Qt.Key_Return)
0227 {
0228 currentNote = item
0229 setNote()
0230 }
0231 }
0232 }
0233
0234 model: Maui.BaseModel
0235 {
0236 id: notesModel
0237 list: Notes
0238 {
0239 id: notesList
0240 }
0241 sortOrder: settings.sortOrder
0242 sort: settings.sortBy
0243 recursiveFilteringEnabled: true
0244 sortCaseSensitivity: Qt.CaseInsensitive
0245 filterCaseSensitivity: Qt.CaseInsensitive
0246 }
0247
0248 footer: Maui.SelectionBar
0249 {
0250 id: _selectionbar
0251 anchors.horizontalCenter: parent.horizontalCenter
0252 width: Math.min(parent.width-(Maui.Style.space.medium*2), implicitWidth)
0253
0254 maxListHeight: control.height - Maui.Style.space.medium
0255 display: ToolButton.IconOnly
0256
0257 onVisibleChanged:
0258 {
0259 if(!visible)
0260 {
0261 cardsView.selectionMode = false
0262 }
0263 }
0264
0265 onExitClicked:
0266 {
0267 clear()
0268 }
0269
0270 listDelegate: Maui.ListBrowserDelegate
0271 {
0272 height: Maui.Style.rowHeight
0273 width: ListView.view.width
0274
0275 background: Rectangle
0276 {
0277 color: model.color ? model.color : "transparent"
0278 radius:Maui.Style.radiusV
0279 }
0280
0281 label1.text: model.title
0282 template.iconVisible: false
0283 iconSource: "view-pim-notes"
0284 checkable: true
0285 checked: true
0286 onToggled: _selectionbar.removeAtIndex(index)
0287 }
0288
0289 Action
0290 {
0291 text: i18n("Favorite")
0292 icon.name: "love"
0293 onTriggered:
0294 {
0295 for(var item of _selectionbar.items)
0296 notesList.update(({"favorite": _notesMenu.isFav ? 0 : 1}), notesModel.mappedToSource(notesList.indexOfNote(item.path)))
0297
0298 _selectionbar.clear()
0299 }
0300 }
0301
0302 Action
0303 {
0304 text: i18n("Share")
0305 icon.name: "document-share"
0306 }
0307
0308 Action
0309 {
0310 text: i18n("Export")
0311 icon.name: "document-export"
0312 }
0313
0314 Action
0315 {
0316 text: i18n("Delete")
0317 Maui.Theme.textColor: Maui.Theme.negativeTextColor
0318 icon.name: "edit-delete"
0319
0320 onTriggered:
0321 {
0322 _removeNotesDialog.notes = _selectionbar.uris
0323 _removeNotesDialog.open()
0324 }
0325 }
0326 }
0327
0328 listDelegate: CardDelegate
0329 {
0330 id: _listDelegate
0331 width: ListView.view.width
0332 checkable: cardsView.selectionMode
0333 checked: _selectionbar.contains(model.path)
0334 isCurrentItem: ListView.isCurrentItem
0335
0336 onClicked: (mouse) =>
0337 {
0338 currentIndex = index
0339
0340 if(cardsView.selectionMode || (mouse.button == Qt.LeftButton && (mouse.modifiers & Qt.ControlModifier)))
0341 {
0342 cardsView.currentView.itemsSelected([index])
0343 }else if(Maui.Handy.singleClick)
0344 {
0345 currentNote = notesModel.get(index)
0346 setNote()
0347 }
0348 }
0349
0350 onDoubleClicked:
0351 {
0352 control.currentIndex = index
0353 if(!Maui.Handy.singleClick && !cardsView.selectionMode)
0354 {
0355 currentNote = notesModel.get(index)
0356 setNote()
0357 }
0358 }
0359
0360 onRightClicked:
0361 {
0362 currentIndex = index
0363 currentNote = notesModel.get(index)
0364 _notesMenu.show()
0365 }
0366
0367 onPressAndHold:
0368 {
0369 currentIndex = index
0370 currentNote = notesModel.get(index)
0371 _notesMenu.show()
0372 }
0373
0374 onToggled:
0375 {
0376 currentIndex = index
0377 select(notesModel.get(index))
0378 }
0379
0380 Connections
0381 {
0382 target: _selectionbar
0383 ignoreUnknownSignals: true
0384
0385 function onUriRemoved(uri)
0386 {
0387 if(uri === model.url)
0388 {
0389 _listDelegate.checked = false
0390 }
0391 }
0392
0393 function onUriAdded(uri)
0394 {
0395 if(uri === model.url)
0396 {
0397 _listDelegate.checked = true
0398 }
0399 }
0400
0401 function onCleared()
0402 {
0403 _listDelegate.checked = false
0404 }
0405 }
0406 }
0407
0408 gridDelegate: Item
0409 {
0410 id: delegate
0411 width: cardsView.gridView.cellWidth
0412 height: cardsView.gridView.cellHeight
0413
0414 property bool isCurrentItem: GridView.isCurrentItem
0415
0416 CardDelegate
0417 {
0418 id: _gridDelegate
0419 anchors.fill: parent
0420 anchors.margins: Maui.Style.space.medium
0421 checkable: cardsView.selectionMode
0422 checked: _selectionbar.contains(model.path)
0423 isCurrentItem: parent.isCurrentItem
0424
0425 onClicked: (mouse) =>
0426 {
0427 currentIndex = index
0428 console.log(index, notesModel.mappedToSource(index), notesList.indexOfNote(model.url))
0429
0430 if(cardsView.selectionMode || (mouse.button == Qt.LeftButton && (mouse.modifiers & Qt.ControlModifier)))
0431 {
0432 cardsView.currentView.itemsSelected([index])
0433 }else if(Maui.Handy.singleClick)
0434 {
0435 currentNote = notesModel.get(index)
0436 setNote()
0437 }
0438 }
0439
0440 onDoubleClicked:
0441 {
0442 control.currentIndex = index
0443 if(!Maui.Handy.singleClick && !cardsView.selectionMode)
0444 {
0445 currentNote = notesModel.get(index)
0446 setNote()
0447 }
0448 }
0449
0450 onRightClicked:
0451 {
0452 currentIndex = index
0453 currentNote = notesModel.get(index)
0454 _notesMenu.show()
0455 }
0456
0457 onPressAndHold:
0458 {
0459 currentIndex = index
0460 currentNote = notesModel.get(index)
0461 _notesMenu.show()
0462 }
0463
0464 onToggled:
0465 {
0466 currentIndex = index
0467 select(notesModel.get(index))
0468 }
0469 }
0470
0471 Connections
0472 {
0473 target: _selectionbar
0474 ignoreUnknownSignals: true
0475
0476 function onUriRemoved(uri)
0477 {
0478 if(uri === model.url)
0479 {
0480 _gridDelegate.checked = false
0481 }
0482 }
0483
0484 function onUriAdded(uri)
0485 {
0486 if(uri === model.url)
0487 {
0488 _gridDelegate.checked = true
0489 }
0490 }
0491
0492 function onCleared()
0493 {
0494 _gridDelegate.checked = false
0495 }
0496 }
0497 }
0498
0499 Connections
0500 {
0501 target: cardsView.holder
0502 function onActionTriggered()
0503 {
0504 newNote()
0505 }
0506 }
0507
0508 Maui.ContextualMenu
0509 {
0510 id: _notesMenu
0511
0512 property bool isFav: currentNote.favorite == 1
0513
0514 Maui.MenuItemActionRow
0515 {
0516 Action
0517 {
0518 icon.name: "love"
0519 text: _notesMenu.isFav? i18n("UnFav") : i18n("Fav")
0520 onTriggered:
0521 {
0522 notesList.update(({"favorite": _notesMenu.isFav ? 0 : 1}), notesModel.mappedToSource(cardsView.currentIndex))
0523 _notesMenu.close()
0524 }
0525 }
0526
0527 Action
0528 {
0529 icon.name: "document-export"
0530 text: i18n("Export")
0531 onTriggered:
0532 {
0533 _notesMenu.close()
0534 }
0535 }
0536
0537 Action
0538 {
0539 icon.name : "edit-copy"
0540 text: i18n("Copy")
0541 onTriggered:
0542 {
0543 Maui.Handy.copyToClipboard({'text': currentNote.content})
0544 _notesMenu.close()
0545 }
0546 }
0547
0548 Action
0549 {
0550 text: i18n("Share")
0551 icon.name: "document-share"
0552 // onTriggered: shareClicked()
0553 }
0554 }
0555
0556 MenuSeparator {}
0557
0558 MenuItem
0559 {
0560 text: i18n("Select")
0561 icon.name: "item-select"
0562 onTriggered:
0563 {
0564 if(Maui.Handy.isTouch)
0565 {
0566 cardsView.selectionMode = true
0567 }
0568
0569 cardsView.currentView.itemsSelected([cardsView.currentIndex])
0570 }
0571 }
0572
0573
0574 MenuSeparator { }
0575
0576 MenuItem
0577 {
0578 icon.name: "edit-delete"
0579 text: i18n("Remove")
0580 Maui.Theme.textColor: Maui.Theme.negativeTextColor
0581 onTriggered:
0582 {
0583 notesList.remove(notesModel.mappedToSource(cardsView.currentIndex))
0584 _notesMenu.close()
0585 }
0586 }
0587
0588 MenuSeparator { }
0589
0590
0591 ColorsBar
0592 {
0593 id: colorBar
0594 padding: control.padding
0595 width: parent.width
0596 currentColor: currentNote.color
0597 onColorPicked:
0598 {
0599 notesList.update(({"color": color}), notesModel.mappedToSource(cardsView.currentIndex))
0600 _notesMenu.close()
0601 }
0602 }
0603
0604 }
0605 }
0606
0607 function select(item)
0608 {
0609 if(_selectionbar.contains(item.path))
0610 {
0611 _selectionbar.removeAtUri(item.path)
0612 }else
0613 {
0614 _selectionbar.append(item.path, item)
0615
0616 }
0617 }
0618 }
0619