import QtQuick 2.0 import Sailfish.Silica 1.0 Dialog { id: noteDialog function reloadContent() { dialogHeader.title = account.model.get(noteIndex).title contentLabel.plainText = account.model.get(noteIndex).content contentLabel.parse() } acceptDestination: Qt.resolvedUrl("EditPage.qml") acceptDestinationProperties: { account: account; noteIndex: noteIndex } Component.onCompleted: acceptDestinationProperties = { account: account, noteIndex: noteIndex } onStatusChanged: { if (status === PageStatus.Active) { account.getNote(account.model.get(noteIndex).id) reloadContent() } } Connections { target: account/*.model.get(noteIndex) onTitleChanged: { console.log("Title changed") dialogHeader.title = account.model.get(noteIndex).title } onContentChanged: { console.log("Content changed") contentLabel.plainText = account.model.get(noteIndex).content contentLabel.parse() }*/ onBusyChanged: { if (account.busy === false) { reloadContent() } } } property var account property int noteIndex property var markdown: [ { 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 { anchors.fill: parent contentHeight: column.height Column { id: column width: parent.width RemorsePopup { id: remorse onTriggered: pageStack.pop() } PullDownMenu { busy: account ? account.busy : false MenuItem { text: qsTr("Delete") enabled: account ? true : false //visible: appSettings.currentAccount >= 0 onClicked: remorse.execute("Deleting", function() { account.deleteNote(account.model.get(noteIndex).id) } ) } MenuItem { text: enabled ? qsTr("Reload") : qsTr("Updating...") enabled: account ? !account.busy : false //visible: appSettings.currentAccount >= 0 onClicked: account.getNote(account.model.get(noteIndex).id) } 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"))) : "" } } DialogHeader { id: dialogHeader acceptText: qsTr("Edit") cancelText: qsTr("Notes") } LinkedLabel { id: contentLabel x: Theme.horizontalPageMargin width: parent.width - 2*x textFormat: Text.StyledText function parse() { var lines = plainText.split('\n') lines.splice(0,1); var tmpText = lines.join('\n'); for (var i=0; i < markdown.length; i++) { tmpText = tmpText.replace(markdown[i].regex, markdown[i].replace) } text = tmpText //console.log(text) } } } VerticalScrollDecorator {} } }