2020-01-14 16:47:42 +03:00
|
|
|
import QtQuick 2.2
|
2018-10-21 02:44:23 +03:00
|
|
|
import Sailfish.Silica 1.0
|
2018-11-28 16:05:36 +03:00
|
|
|
import Nemo.Notifications 1.0
|
2018-10-21 02:44:23 +03:00
|
|
|
|
2018-11-18 13:25:28 +03:00
|
|
|
Dialog {
|
2018-12-20 20:53:29 +03:00
|
|
|
id: editDialog
|
2018-10-21 02:44:23 +03:00
|
|
|
|
2019-06-21 18:49:54 +03:00
|
|
|
property int id
|
2020-05-03 19:30:39 +03:00
|
|
|
property var note
|
|
|
|
|
|
|
|
onIdChanged: note = notesModel.getNoteById(id)
|
|
|
|
onNoteChanged: {
|
|
|
|
dialogHeader.title = note["title"]
|
|
|
|
contentArea.text = note["content"]
|
|
|
|
favoriteButton.selected = note["favorite"]
|
|
|
|
categoryField.text = note["category"]
|
|
|
|
modifiedDetail.modified = note["modified"]
|
|
|
|
//parseContent()
|
|
|
|
}
|
|
|
|
|
2019-06-21 18:49:54 +03:00
|
|
|
property int modified
|
|
|
|
property string title
|
|
|
|
property string category
|
|
|
|
property string content
|
|
|
|
property bool favorite
|
|
|
|
property string etag
|
|
|
|
property bool error
|
|
|
|
property string errorMessage
|
2018-12-04 01:08:41 +03:00
|
|
|
|
2018-11-18 13:25:28 +03:00
|
|
|
onAccepted: {
|
2020-05-05 20:44:31 +03:00
|
|
|
notesModel.updateNote(id, { 'category': categoryField.text, 'content': contentArea.text, 'favorite': favoriteButton.selected, 'modified': new Date().valueOf() / 1000 } )
|
2018-11-18 13:25:28 +03:00
|
|
|
}
|
|
|
|
|
2018-10-21 02:44:23 +03:00
|
|
|
SilicaFlickable {
|
|
|
|
anchors.fill: parent
|
2018-12-13 01:10:45 +03:00
|
|
|
contentHeight: mainColumn.height + Theme.paddingLarge
|
2018-10-21 02:44:23 +03:00
|
|
|
|
2018-10-23 23:15:59 +03:00
|
|
|
PullDownMenu {
|
2018-11-18 15:11:22 +03:00
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Reset")
|
2018-12-20 20:53:29 +03:00
|
|
|
onClicked: reloadContent()
|
2018-10-23 23:15:59 +03:00
|
|
|
}
|
2018-11-28 16:05:36 +03:00
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Markdown syntax")
|
2018-12-13 01:10:45 +03:00
|
|
|
onClicked: pageStack.push(Qt.resolvedUrl("SyntaxPage.qml"))
|
2018-11-28 16:05:36 +03:00
|
|
|
}
|
2018-10-23 23:15:59 +03:00
|
|
|
}
|
|
|
|
|
2018-10-21 02:44:23 +03:00
|
|
|
Column {
|
2018-12-07 02:30:18 +03:00
|
|
|
id: mainColumn
|
|
|
|
width: parent.width
|
2018-10-21 02:44:23 +03:00
|
|
|
|
2018-11-18 13:25:28 +03:00
|
|
|
DialogHeader {
|
2018-12-20 20:53:29 +03:00
|
|
|
id: dialogHeader
|
2020-01-11 15:32:26 +03:00
|
|
|
//title: editDialog.title
|
2018-10-21 02:44:23 +03:00
|
|
|
}
|
|
|
|
|
2018-12-07 02:30:18 +03:00
|
|
|
Column {
|
2018-10-21 02:44:23 +03:00
|
|
|
width: parent.width
|
2018-12-07 02:30:18 +03:00
|
|
|
spacing: Theme.paddingLarge
|
|
|
|
|
2020-01-11 15:32:26 +03:00
|
|
|
/*Separator {
|
2018-12-07 02:30:18 +03:00
|
|
|
width: parent.width
|
|
|
|
color: Theme.primaryColor
|
|
|
|
horizontalAlignment: Qt.AlignHCenter
|
2020-01-11 15:32:26 +03:00
|
|
|
}*/
|
2018-12-07 02:30:18 +03:00
|
|
|
|
|
|
|
TextArea {
|
|
|
|
id: contentArea
|
|
|
|
width: parent.width
|
2019-11-12 01:23:41 +03:00
|
|
|
text: content
|
2018-12-20 20:53:29 +03:00
|
|
|
placeholderText: qsTr("No content")
|
2018-12-11 19:44:00 +03:00
|
|
|
font.family: appSettings.useMonoFont ? "DejaVu Sans Mono" : Theme.fontFamily
|
2018-12-07 02:30:18 +03:00
|
|
|
property int preTextLength: 0
|
|
|
|
property var listPrefixes: [/^( *)- /gm, /^( *)\* /gm, /^( *)\+ /gm, /^( *)- \[ \] /gm, /^( *)- \[[xX]\] /gm, /^( *)> /gm, /^( *)\d+. /gm]
|
|
|
|
onTextChanged: {
|
2018-12-20 20:53:29 +03:00
|
|
|
if (editDialog.status === PageStatus.Active &&
|
2018-12-07 02:30:18 +03:00
|
|
|
text.length > preTextLength &&
|
|
|
|
text.charAt(cursorPosition-1) === "\n") {
|
|
|
|
var clipboard = ""
|
|
|
|
var preLine = text.substring(text.lastIndexOf("\n", cursorPosition-2), text.indexOf("\n", cursorPosition-1))
|
|
|
|
listPrefixes.forEach(function(currentValue, index) {
|
|
|
|
var prefix = preLine.match(currentValue)
|
|
|
|
if (prefix !== null) {
|
|
|
|
if (index === listPrefixes.length-1) {
|
|
|
|
var newListNumber = parseInt(prefix[0].split(". ")[0]) + 1
|
|
|
|
clipboard = prefix[0].replace(/\d/gm, newListNumber.toString())
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
clipboard = prefix[0]
|
|
|
|
}
|
2018-12-04 17:49:29 +03:00
|
|
|
}
|
2018-12-07 02:30:18 +03:00
|
|
|
})
|
|
|
|
if (clipboard !== "") {
|
|
|
|
var tmpClipboard = Clipboard.text
|
|
|
|
Clipboard.text = clipboard
|
|
|
|
contentArea.paste()
|
|
|
|
Clipboard.text = tmpClipboard
|
2018-12-04 17:49:29 +03:00
|
|
|
}
|
2018-12-04 02:46:04 +03:00
|
|
|
}
|
2018-12-07 02:30:18 +03:00
|
|
|
preTextLength = text.length
|
2018-12-04 02:46:04 +03:00
|
|
|
}
|
2018-11-30 03:06:35 +03:00
|
|
|
}
|
2018-11-18 13:25:28 +03:00
|
|
|
}
|
|
|
|
|
2018-12-06 15:37:29 +03:00
|
|
|
Flow {
|
|
|
|
x: Theme.horizontalPageMargin
|
|
|
|
width: parent.width - 2*x
|
|
|
|
spacing: Theme.paddingMedium
|
2018-12-06 18:01:43 +03:00
|
|
|
visible: opacity > 0.0
|
|
|
|
opacity: categoryField.focus ? 1.0 : 0.0
|
|
|
|
Behavior on opacity { FadeAnimator { } }
|
|
|
|
|
2018-12-06 15:37:29 +03:00
|
|
|
Repeater {
|
|
|
|
id: categoryRepeater
|
2019-11-12 01:23:41 +03:00
|
|
|
model: notesApi.categories
|
2018-12-06 15:37:29 +03:00
|
|
|
BackgroundItem {
|
2018-12-06 16:07:48 +03:00
|
|
|
id: categoryBackground
|
2018-12-06 15:37:29 +03:00
|
|
|
width: categoryRectangle.width
|
|
|
|
height: categoryRectangle.height
|
|
|
|
Rectangle {
|
|
|
|
id: categoryRectangle
|
|
|
|
width: categoryLabel.width + Theme.paddingLarge
|
|
|
|
height: categoryLabel.height + Theme.paddingSmall
|
|
|
|
color: "transparent"
|
|
|
|
border.color: Theme.highlightColor
|
|
|
|
radius: height / 4
|
|
|
|
Label {
|
|
|
|
id: categoryLabel
|
|
|
|
anchors.centerIn: parent
|
|
|
|
text: modelData
|
2018-12-06 16:07:48 +03:00
|
|
|
color: categoryBackground.highlighted ? Theme.highlightColor : Theme.primaryColor
|
2018-12-06 15:37:29 +03:00
|
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onClicked: categoryField.text = modelData
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-18 13:25:28 +03:00
|
|
|
Row {
|
|
|
|
x: Theme.horizontalPageMargin
|
|
|
|
width: parent.width - x
|
|
|
|
IconButton {
|
|
|
|
id: favoriteButton
|
2019-11-12 01:23:41 +03:00
|
|
|
property bool selected: favorite
|
2018-11-18 13:25:28 +03:00
|
|
|
width: Theme.iconSizeMedium
|
2018-11-18 15:11:22 +03:00
|
|
|
icon.source: (selected ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") +
|
2018-11-18 13:25:28 +03:00
|
|
|
(favoriteButton.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor)
|
2018-12-07 02:30:18 +03:00
|
|
|
onClicked: {
|
2019-11-12 01:23:41 +03:00
|
|
|
api.updateNote(id, {'favorite': !favorite})
|
2018-12-07 02:30:18 +03:00
|
|
|
}
|
2018-11-18 13:25:28 +03:00
|
|
|
}
|
|
|
|
TextField {
|
|
|
|
id: categoryField
|
|
|
|
width: parent.width - favoriteButton.width
|
2019-11-12 01:23:41 +03:00
|
|
|
text: category
|
2018-12-03 22:33:37 +03:00
|
|
|
placeholderText: qsTr("No category")
|
|
|
|
label: qsTr("Category")
|
2018-12-07 02:30:18 +03:00
|
|
|
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
|
|
|
|
EnterKey.onClicked: {
|
|
|
|
categoryField.focus = false
|
|
|
|
}
|
|
|
|
onFocusChanged: {
|
2019-11-12 01:23:41 +03:00
|
|
|
if (focus === false && text !== category) {
|
2020-05-05 20:44:31 +03:00
|
|
|
notesModel.updateNote(id, {'content': content, 'category': text}) // This does not seem to work without adding the content
|
2018-12-07 02:30:18 +03:00
|
|
|
}
|
|
|
|
}
|
2018-11-18 13:25:28 +03:00
|
|
|
}
|
2018-10-21 02:44:23 +03:00
|
|
|
}
|
2018-12-07 02:30:18 +03:00
|
|
|
|
|
|
|
DetailItem {
|
|
|
|
id: modifiedDetail
|
|
|
|
label: qsTr("Modified")
|
2020-05-03 19:30:39 +03:00
|
|
|
property int modified
|
|
|
|
onModifiedChanged: value = new Date(modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
|
2018-12-07 02:30:18 +03:00
|
|
|
}
|
2018-10-21 02:44:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VerticalScrollDecorator {}
|
|
|
|
}
|
2018-12-04 19:24:45 +03:00
|
|
|
|
|
|
|
allowedOrientations: defaultAllowedOrientations
|
2018-10-21 02:44:23 +03:00
|
|
|
}
|