2018-11-27 12:21:50 +03:00
|
|
|
import "../js/showdown-1.9.0/dist/showdown.js" as ShowDown
|
2018-10-16 18:50:58 +03:00
|
|
|
import QtQuick 2.0
|
|
|
|
import Sailfish.Silica 1.0
|
|
|
|
|
2018-11-18 13:25:28 +03:00
|
|
|
Dialog {
|
|
|
|
id: noteDialog
|
2018-11-30 20:40:03 +03:00
|
|
|
|
|
|
|
property var account
|
|
|
|
property var note
|
|
|
|
|
2018-11-27 11:58:21 +03:00
|
|
|
property var showdown: ShowDown.showdown
|
2018-11-30 17:12:16 +03:00
|
|
|
property var converter: new showdown.Converter(
|
2018-12-04 17:22:57 +03:00
|
|
|
{ simplifiedAutoLink: true,
|
|
|
|
excludeTrailingPunctuationFromURLs: true,
|
|
|
|
strikethrough: true,
|
2018-11-30 17:12:16 +03:00
|
|
|
tables: true,
|
2018-12-03 22:33:37 +03:00
|
|
|
tasklists: false, // this is handled by the function parseContent() because LinkedLabel HTML support is to basic
|
2018-12-04 17:22:57 +03:00
|
|
|
parseImgDimensions: true,
|
2018-11-30 17:12:16 +03:00
|
|
|
simpleLineBreaks: true,
|
|
|
|
emoji: true } )
|
2018-11-18 13:25:28 +03:00
|
|
|
|
2018-12-04 01:08:41 +03:00
|
|
|
acceptDestination: Qt.resolvedUrl("EditPage.qml")
|
|
|
|
acceptDestinationProperties: { account: account; note: note }
|
|
|
|
Component.onCompleted: {
|
|
|
|
acceptDestinationProperties = { account: account, note: note }
|
2018-12-04 17:22:57 +03:00
|
|
|
//showdown.setFlavor('original')
|
|
|
|
parseContent()
|
2018-12-04 01:08:41 +03:00
|
|
|
}
|
|
|
|
Connections {
|
|
|
|
target: account
|
|
|
|
onBusyChanged: {
|
|
|
|
if (account.busy === false) {
|
|
|
|
note = account.getNote(note.id, false)
|
2018-12-04 17:22:57 +03:00
|
|
|
acceptDestinationProperties = { account: account, note: note }
|
2018-12-04 01:08:41 +03:00
|
|
|
parseContent()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-03 22:33:37 +03:00
|
|
|
function parseContent() {
|
|
|
|
note = account.getNote(note.id, false)
|
2018-11-30 20:40:03 +03:00
|
|
|
var convertedText = converter.makeHtml(note.content)
|
2018-11-28 16:05:36 +03:00
|
|
|
var occurence = -1
|
2018-12-04 17:22:57 +03:00
|
|
|
convertedText = convertedText.replace(/^<li>(<p>)?\[ \] (.*)<\/li>$/gm,
|
|
|
|
function(match, p1, p2, offset) {
|
2018-11-28 16:05:36 +03:00
|
|
|
occurence++
|
2018-12-04 17:22:57 +03:00
|
|
|
return '<li><font size="' + 4 + '"><a href="tasklist:checkbox_' + occurence + '">' + (p1 ? p1 : "") + '☐ ' + p2 + '</a></font></li>'
|
2018-11-28 16:05:36 +03:00
|
|
|
} )
|
|
|
|
occurence = -1
|
2018-12-04 17:22:57 +03:00
|
|
|
convertedText = convertedText.replace(/^<li>(<p>)?\[[xX]\] (.*)<\/li>$/gm,
|
|
|
|
function(match, p1, p2, offset) {
|
2018-11-28 16:05:36 +03:00
|
|
|
occurence++
|
2018-12-04 17:22:57 +03:00
|
|
|
return '<li><font size="' + 4 + '"><a href="tasklist:uncheckbox_' + occurence + '">' + (p1 ? p1 : "") + '☑ ' + p2 + '</a></font></li>'
|
2018-11-28 16:05:36 +03:00
|
|
|
} )
|
2018-12-04 17:22:57 +03:00
|
|
|
convertedText = convertedText.replace("<table>", "<table border='1' cellpadding='" + Theme.paddingMedium + "'>")
|
|
|
|
contentLabel.text = "<style>ul,ol,table,img { margin-bottom: " + Theme.paddingLarge + "px; margin-top: " + Theme.paddingLarge + "px; }\n" +
|
|
|
|
"a:link { color: " + Theme.primaryColor + "; }\n" +
|
|
|
|
"table { border-color: " + Theme.secondaryColor + "; }</style>" + convertedText
|
|
|
|
console.log(contentLabel.text)
|
2018-11-24 21:34:01 +03:00
|
|
|
}
|
|
|
|
|
2018-10-16 18:50:58 +03:00
|
|
|
SilicaFlickable {
|
|
|
|
anchors.fill: parent
|
2018-11-26 19:21:33 +03:00
|
|
|
contentHeight: mainColumn.height
|
2018-10-16 18:50:58 +03:00
|
|
|
|
|
|
|
Column {
|
2018-11-26 19:21:33 +03:00
|
|
|
id: mainColumn
|
2018-10-21 02:44:23 +03:00
|
|
|
width: parent.width
|
2018-11-26 19:21:33 +03:00
|
|
|
|
2018-11-24 21:34:01 +03:00
|
|
|
RemorsePopup {
|
|
|
|
id: remorse
|
|
|
|
onTriggered: pageStack.pop()
|
|
|
|
}
|
|
|
|
PullDownMenu {
|
|
|
|
busy: account ? account.busy : false
|
|
|
|
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Delete")
|
|
|
|
enabled: account ? true : false
|
2018-11-30 20:40:03 +03:00
|
|
|
onClicked: remorse.execute("Deleting", function() { account.deleteNote(notey.id) } )
|
2018-11-24 21:34:01 +03:00
|
|
|
}
|
|
|
|
MenuItem {
|
|
|
|
text: enabled ? qsTr("Reload") : qsTr("Updating...")
|
|
|
|
enabled: account ? !account.busy : false
|
2018-11-30 20:40:03 +03:00
|
|
|
onClicked: account.getNote(note.id)
|
2018-11-24 21:34:01 +03:00
|
|
|
}
|
|
|
|
MenuLabel {
|
|
|
|
visible: appSettings.currentAccount >= 0
|
|
|
|
text: account ? (
|
|
|
|
qsTr("Last update") + ": " + (
|
|
|
|
new Date(account.update).valueOf() !== 0 ?
|
|
|
|
new Date(account.update).toLocaleString(Qt.locale(), Locale.ShortFormat) :
|
|
|
|
qsTr("never"))) : ""
|
|
|
|
}
|
|
|
|
}
|
2018-10-16 18:50:58 +03:00
|
|
|
|
2018-11-18 13:25:28 +03:00
|
|
|
DialogHeader {
|
2018-11-18 17:01:32 +03:00
|
|
|
id: dialogHeader
|
2018-11-28 16:05:36 +03:00
|
|
|
dialog: noteDialog
|
2018-11-18 13:25:28 +03:00
|
|
|
acceptText: qsTr("Edit")
|
|
|
|
cancelText: qsTr("Notes")
|
2018-10-16 18:50:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-26 19:21:33 +03:00
|
|
|
Column {
|
|
|
|
width: parent.width
|
|
|
|
spacing: Theme.paddingLarge
|
|
|
|
|
|
|
|
LinkedLabel {
|
|
|
|
id: contentLabel
|
|
|
|
x: Theme.horizontalPageMargin
|
|
|
|
width: parent.width - 2*x
|
2018-12-04 17:22:57 +03:00
|
|
|
textFormat: Text.RichText
|
|
|
|
linkColor: Theme.primaryColor
|
2018-11-28 16:05:36 +03:00
|
|
|
defaultLinkActions: false
|
|
|
|
onLinkActivated: {
|
|
|
|
var occurence = -1
|
2018-11-30 20:40:03 +03:00
|
|
|
var newContent = note.content
|
2018-11-28 16:05:36 +03:00
|
|
|
if (/^tasklist:checkbox_(\d+)$/m.test(link)) {
|
2018-12-03 22:33:37 +03:00
|
|
|
newContent = newContent.replace(/^- \[ \] (.*)$/gm,
|
2018-11-28 16:05:36 +03:00
|
|
|
function(match, p1, offset, string) {
|
|
|
|
occurence++
|
|
|
|
if (occurence === parseInt(link.split('_')[1])) {
|
2018-12-04 13:44:06 +03:00
|
|
|
return (appSettings.useCapitalX ? '- [X] ' : '- [x] ') + p1 }
|
2018-12-03 22:33:37 +03:00
|
|
|
else { return match }
|
2018-11-28 16:05:36 +03:00
|
|
|
} )
|
2018-12-03 22:33:37 +03:00
|
|
|
note.content = newContent
|
|
|
|
parseContent()
|
|
|
|
account.updateNote(note.id, { 'content': note.content } )
|
2018-11-28 16:05:36 +03:00
|
|
|
}
|
|
|
|
else if (/^tasklist:uncheckbox_(\d+)$/m.test(link)) {
|
2018-12-03 22:33:37 +03:00
|
|
|
newContent = newContent.replace(/^- \[[xX]\] (.*)$/gm,
|
2018-11-28 16:05:36 +03:00
|
|
|
function(match, p1, offset, string) {
|
|
|
|
occurence++
|
|
|
|
if (occurence === parseInt(link.split('_')[1])) {
|
2018-12-03 22:33:37 +03:00
|
|
|
return '- [ ] ' + p1 }
|
|
|
|
else { return match }
|
2018-11-28 16:05:36 +03:00
|
|
|
} )
|
2018-12-03 22:33:37 +03:00
|
|
|
note.content = newContent
|
|
|
|
parseContent()
|
|
|
|
account.updateNote(note.id, { 'content': note.content } )
|
2018-11-28 16:05:36 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
Qt.openUrlExternally(link)
|
|
|
|
}
|
|
|
|
}
|
2018-11-26 19:21:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Separator {
|
|
|
|
id: separator
|
|
|
|
width: parent.width
|
|
|
|
color: Theme.primaryColor
|
|
|
|
horizontalAlignment: Qt.AlignHCenter
|
|
|
|
}
|
|
|
|
|
2018-12-04 17:22:57 +03:00
|
|
|
Column {
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
Row {
|
|
|
|
x: Theme.horizontalPageMargin
|
|
|
|
width: parent.width - x
|
|
|
|
IconButton {
|
|
|
|
id: favoriteButton
|
|
|
|
property bool selected: note.favorite
|
|
|
|
width: Theme.iconSizeMedium
|
|
|
|
icon.source: (selected ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") +
|
|
|
|
(favoriteButton.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor)
|
|
|
|
onClicked: {
|
|
|
|
account.updateNote(note.id, {'favorite': !note.favorite})
|
|
|
|
}
|
2018-12-03 22:33:37 +03:00
|
|
|
}
|
2018-12-04 17:22:57 +03:00
|
|
|
TextField {
|
|
|
|
id: categoryField
|
|
|
|
width: parent.width - favoriteButton.width
|
|
|
|
text: note.category
|
|
|
|
placeholderText: qsTr("No category")
|
|
|
|
label: qsTr("Category")
|
|
|
|
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
|
|
|
|
EnterKey.onClicked: {
|
|
|
|
categoryField.focus = false
|
|
|
|
}
|
|
|
|
onFocusChanged: {
|
|
|
|
if (focus === false) {
|
|
|
|
account.updateNote(note.id, {'content': note.content, 'category': text}) // This does not seem to work without adding the content
|
|
|
|
}
|
2018-12-03 22:33:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-04 17:22:57 +03:00
|
|
|
|
2018-11-26 19:21:33 +03:00
|
|
|
DetailItem {
|
2018-12-04 17:22:57 +03:00
|
|
|
id: modifiedDetail
|
|
|
|
label: qsTr("Modified")
|
|
|
|
value: new Date(note.modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
|
|
|
|
}
|
|
|
|
}
|
2018-10-16 18:50:58 +03:00
|
|
|
}
|
|
|
|
}
|
2018-10-21 02:44:23 +03:00
|
|
|
|
2018-10-16 18:50:58 +03:00
|
|
|
VerticalScrollDecorator {}
|
|
|
|
}
|
|
|
|
}
|