harbour-nextcloudnotes/qml/pages/EditPage.qml

110 lines
4 KiB
QML
Raw Normal View History

2018-10-21 02:44:23 +03:00
import QtQuick 2.0
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-10-21 02:44:23 +03:00
id: page
2018-12-04 01:08:41 +03:00
property var account
property var note
2018-11-18 13:25:28 +03:00
onAccepted: {
account.updateNote(note.id, { 'category': categoryField.text, 'content': contentArea.text, 'favorite': favoriteButton.selected } )
2018-11-18 13:25:28 +03:00
}
2018-12-04 01:08:41 +03:00
onStatusChanged: {
if (status === PageStatus.Active) {
note = account.getNote(note.id, false)
favoriteButton.selected = note.favorite
2018-12-04 01:08:41 +03:00
}
}
2018-10-21 02:44:23 +03:00
SilicaFlickable {
id: flickable
anchors.fill: parent
contentHeight: column.height
2018-10-23 23:15:59 +03:00
PullDownMenu {
2018-11-18 15:11:22 +03:00
MenuItem {
text: qsTr("Reset")
onClicked: {
2018-12-04 01:08:41 +03:00
note = account.getNote(note.id, false)
favoriteButton.selected = note.favorite
2018-11-18 15:11:22 +03:00
}
2018-10-23 23:15:59 +03:00
}
2018-11-28 16:05:36 +03:00
MenuItem {
text: qsTr("Markdown syntax")
onClicked: Qt.openUrlExternally("https://github.com/showdownjs/showdown/wiki/Showdown's-Markdown-syntax")
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 {
id: column
width: parent.width// - 2*x
2018-11-18 13:25:28 +03:00
DialogHeader {
2018-11-25 16:08:00 +03:00
//title: account.model.get(noteIndex).title
2018-10-21 02:44:23 +03:00
}
TextArea {
2018-11-18 13:25:28 +03:00
id: contentArea
2018-10-21 02:44:23 +03:00
width: parent.width
2018-11-28 16:05:36 +03:00
focus: true
text: note.content
font.family: appSettings.useMonoFont ? "DejaVu Sans Mono" : Theme.fontFamily // "Courier"
property int preTextLength: 0
2018-12-04 17:49:29 +03:00
property var listPrefixes: [/^- /gm, /^\* /gm, /^\+ /gm, /^- \[ \] /gm, /^- \[[xX]\] /gm, /^\d+. /gm]
onTextChanged: {
if (page.status === PageStatus.Active &&
text.length > preTextLength &&
text.charAt(cursorPosition-1) === "\n") {
var clipboard = ""
var preLine = text.substring(text.lastIndexOf("\n", cursorPosition-2), text.indexOf("\n", cursorPosition-1))
2018-12-04 17:49:29 +03:00
listPrefixes.forEach(function(currentValue, index) {
var prefix = preLine.match(currentValue)
if (prefix !== null) {
if (index === 5) {
var newListNumber = parseInt(prefix[0].split(". ")[0]) + 1
clipboard = newListNumber.toString() + ". "
}
else {
clipboard = prefix[0]
}
}
})
if (clipboard !== "") {
var tmpClipboard = Clipboard.text
Clipboard.text = clipboard
contentArea.paste()
Clipboard.text = tmpClipboard
}
}
preTextLength = text.length
}
2018-11-18 13:25:28 +03:00
}
Row {
x: Theme.horizontalPageMargin
width: parent.width - x
IconButton {
id: favoriteButton
property bool selected: note.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-11-18 15:11:22 +03:00
onClicked: selected = !selected
2018-11-18 13:25:28 +03:00
}
TextField {
id: categoryField
width: parent.width - favoriteButton.width
text: note.category
placeholderText: qsTr("No category")
label: qsTr("Category")
2018-11-18 13:25:28 +03:00
}
2018-10-21 02:44:23 +03:00
}
}
VerticalScrollDecorator {}
}
}