From 82957296111c2bebfd1e14046bded24d0631ba70 Mon Sep 17 00:00:00 2001 From: Scharel Clemens Date: Sun, 18 Nov 2018 15:01:32 +0100 Subject: [PATCH] Reload Note view after editing --- qml/pages/NotePage.qml | 49 ++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/qml/pages/NotePage.qml b/qml/pages/NotePage.qml index 14d4e49..895732d 100644 --- a/qml/pages/NotePage.qml +++ b/qml/pages/NotePage.qml @@ -6,20 +6,37 @@ Dialog { acceptDestination: Qt.resolvedUrl("EditPage.qml") acceptDestinationProperties: { account: account; noteIndex: noteIndex } - Component.onCompleted: acceptDestinationProperties = { account: account, noteIndex: noteIndex }//acceptDestinationInstance.note = note + Component.onCompleted: acceptDestinationProperties = { account: account, noteIndex: noteIndex } + onStatusChanged: { + if (status === PageStatus.Active) { + dialogHeader.title = account.model.get(noteIndex).title + contentLabel.plainText = account.model.get(noteIndex).content + contentLabel.parse() + } + } + Connections { + target: account.model.get(noteIndex) + onTitleChanged: dialogHeader.title = account.model.get(noteIndex).title + onContentChanged: { + contentLabel.plainText = account.model.get(noteIndex).content + contentLabel.parse() + } + } property var account property int noteIndex property var markdown: [ - { regex: new RegExp(/(^#\s)(.*)$/gm), replace: '

$2

' }, - { regex: new RegExp(/(^##\s)(.*)$/gm), replace: '

$2

' }, - { regex: new RegExp(/(^###\s)(.*)$/gm), replace: '

$2

' }, - { regex: new RegExp(/(^####\s)(.*)$/gm), replace: '

$2

' }, - { regex: new RegExp(/(^#####\s)(.*)$/gm), replace: '
$2
' }, - { regex: new RegExp(/(^######\s)(.*)$/gm), replace: '
$2
' }, - { regex: new RegExp(/(^-\s)(.*)$/gm), replace: '' }, - { regex: new RegExp(/(^\d{1,}.\s)(.*)$/gm), replace: '
  1. $2
' } + { regex: new RegExp(/^#\s(.*)$/gm), replace: '

$1

' }, + { regex: new RegExp(/^##\s(.*)$/gm), replace: '

$1

' }, + { regex: new RegExp(/^###\s(.*)$/gm), replace: '

$1

' }, + { regex: new RegExp(/^####\s(.*)$/gm), replace: '

$1

' }, + { regex: new RegExp(/^#####\s(.*)$/gm), replace: '
$1
' }, + { regex: new RegExp(/^######\s(.*)$/gm), replace: '
$1
' }, + { regex: new RegExp(/^-\s(.*)$/gm), replace: '' }, + { regex: new RegExp(/^\d{1,}.\s(.*)$/gm), replace: '
  1. $1
' }, + //{ regex: new RegExp(/(
  • [\s\S]*<\/li>)/igm), replace: '' }, + //{ regex: new RegExp(/(
  • [\s\S]*<\/li>)/igm), replace: '
      $1
    ' } ] SilicaFlickable { @@ -31,22 +48,26 @@ Dialog { width: parent.width DialogHeader { - title: account.model.get(noteIndex).title + id: dialogHeader acceptText: qsTr("Edit") cancelText: qsTr("Notes") } LinkedLabel { + id: contentLabel x: Theme.horizontalPageMargin width: parent.width - 2*x textFormat: Text.StyledText - Component.onCompleted: { - var lines = account.model.get(noteIndex).content.split('\n') + + function parse() { + var lines = plainText.split('\n') lines.splice(0,1); - text = lines.join('\n'); + var tmpText = lines.join('\n'); for (var i=0; i < markdown.length; i++) { - text = text.replace(markdown[i].regex, markdown[i].replace) + tmpText = tmpText.replace(markdown[i].regex, markdown[i].replace) } + text = tmpText + console.log(text) } } }