From af18cc77d25c14355011f1414f7877a756f99fa0 Mon Sep 17 00:00:00 2001 From: Scharel Clemens Date: Wed, 28 Nov 2018 14:05:36 +0100 Subject: [PATCH] Implemented checkboxes --- harbour-nextcloudnotes.pro | 1 - qml/pages/EditPage.qml | 10 +++-- qml/pages/MITLicense.qml | 3 +- qml/pages/MarkdownPage.qml | 30 --------------- qml/pages/NotePage.qml | 51 +++++++++++++++++++++++++- rpm/harbour-nextcloudnotes.changes | 12 ++++-- rpm/harbour-nextcloudnotes.spec | 2 +- rpm/harbour-nextcloudnotes.yaml | 2 +- translations/harbour-nextcloudnotes.ts | 15 ++------ 9 files changed, 71 insertions(+), 55 deletions(-) delete mode 100644 qml/pages/MarkdownPage.qml diff --git a/harbour-nextcloudnotes.pro b/harbour-nextcloudnotes.pro index a675773..e66d78a 100644 --- a/harbour-nextcloudnotes.pro +++ b/harbour-nextcloudnotes.pro @@ -31,7 +31,6 @@ DISTFILES += qml/harbour-nextcloudnotes.qml \ qml/pages/EditPage.qml \ qml/pages/SettingsPage.qml \ qml/pages/AboutPage.qml \ - qml/pages/MarkdownPage.qml \ qml/pages/UnencryptedDialog.qml \ qml/pages/NotesApi.qml \ rpm/harbour-nextcloudnotes.changes \ diff --git a/qml/pages/EditPage.qml b/qml/pages/EditPage.qml index 09e1872..06a9d86 100644 --- a/qml/pages/EditPage.qml +++ b/qml/pages/EditPage.qml @@ -1,5 +1,6 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 +import Nemo.Notifications 1.0 Dialog { id: page @@ -17,10 +18,6 @@ Dialog { contentHeight: column.height PullDownMenu { - /*MenuItem { - text: qsTr("Markdown Cheatsheet") - onClicked: pageStack.push(Qt.resolvedUrl("MarkdownPage.qml")) - }*/ MenuItem { text: qsTr("Reset") onClicked: { @@ -29,6 +26,10 @@ Dialog { favoriteButton.selected = account.model.get(noteIndex).favorite } } + MenuItem { + text: qsTr("Markdown syntax") + onClicked: Qt.openUrlExternally("https://github.com/showdownjs/showdown/wiki/Showdown's-Markdown-syntax")//pageStack.push(Qt.resolvedUrl("MarkdownPage.qml")) + } } Column { @@ -42,6 +43,7 @@ Dialog { TextArea { id: contentArea width: parent.width + focus: true text: account.model.get(noteIndex).content } diff --git a/qml/pages/MITLicense.qml b/qml/pages/MITLicense.qml index 82d5339..593a077 100644 --- a/qml/pages/MITLicense.qml +++ b/qml/pages/MITLicense.qml @@ -17,9 +17,10 @@ Page { title: qsTr("MIT License") } - LinkedLabel { + Label { x: Theme.horizontalPageMargin width: parent.width - 2*x + wrapMode: Text.Wrap text: "

Copyright (c) 2018 Scharel Clemens

Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/qml/pages/MarkdownPage.qml b/qml/pages/MarkdownPage.qml deleted file mode 100644 index 4c91c6f..0000000 --- a/qml/pages/MarkdownPage.qml +++ /dev/null @@ -1,30 +0,0 @@ -import QtQuick 2.0 -import Sailfish.Silica 1.0 - -Page { - id: page - - SilicaFlickable { - id: flickable - anchors.fill: parent - contentHeight: column.height - - Column { - id: column - width: parent.width - spacing: Theme.paddingMedium - - PageHeader { - title: qsTr("Markdown Cheatsheet") - } - } - - VerticalScrollDecorator {} - } - - ViewPlaceholder { - enabled: true // TODO - text: qsTr("Markdown Cheatsheet") - hintText: qsTr("https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet") - } -} diff --git a/qml/pages/NotePage.qml b/qml/pages/NotePage.qml index 4016334..341b5bc 100644 --- a/qml/pages/NotePage.qml +++ b/qml/pages/NotePage.qml @@ -8,7 +8,20 @@ Dialog { property var converter: new showdown.Converter( { noHeaderId: true, simplifiedAutoLink: true, tables: true, tasklists: false, simpleLineBreaks: true, emoji: true } ) function reloadContent() { - contentLabel.text = converter.makeHtml(account.model.get(noteIndex).content) + var convertedText = converter.makeHtml(account.model.get(noteIndex).content) + var occurence = -1 + convertedText = convertedText.replace(/^

  • \[ \]\s(.*)<\/li>$/gm, + function(match, p1, offset) { + occurence++ + return '
  • ☐ ' + p1 + '
  • ' + } ) + occurence = -1 + convertedText = convertedText.replace(/^
  • \[x\]\s(.*)<\/li>$/gm, + function(match, p1, offset) { + occurence++ + return '
  • ☑ ' + p1 + '
  • ' + } ) + contentLabel.text = convertedText //console.log(contentLabel.text) } @@ -81,6 +94,7 @@ Dialog { DialogHeader { id: dialogHeader + dialog: noteDialog acceptText: qsTr("Edit") cancelText: qsTr("Notes") } @@ -94,7 +108,40 @@ Dialog { x: Theme.horizontalPageMargin width: parent.width - 2*x textFormat: Text.StyledText - defaultLinkActions: true + defaultLinkActions: false + onLinkActivated: { + var occurence = -1 + var newContent = account.model.get(noteIndex).content + if (/^tasklist:checkbox_(\d+)$/m.test(link)) { + newContent = newContent.replace(/^- \[ \]\s(.*)$/gm, + function(match, p1, offset, string) { + occurence++ + if (occurence === parseInt(link.split('_')[1])) { + return '- [x] ' + p1 + } + else { + return match + } + } ) + account.updateNote(account.model.get(noteIndex).id, { 'content': newContent } ) + } + else if (/^tasklist:uncheckbox_(\d+)$/m.test(link)) { + newContent = newContent.replace(/^- \[x\]\s(.*)$/gm, + function(match, p1, offset, string) { + occurence++ + if (occurence === parseInt(link.split('_')[1])) { + return '- [ ] ' + p1 + } + else { + return match + } + } ) + account.updateNote(account.model.get(noteIndex).id, { 'content': newContent } ) + } + else { + Qt.openUrlExternally(link) + } + } } Separator { diff --git a/rpm/harbour-nextcloudnotes.changes b/rpm/harbour-nextcloudnotes.changes index d762492..1d39fa1 100644 --- a/rpm/harbour-nextcloudnotes.changes +++ b/rpm/harbour-nextcloudnotes.changes @@ -12,6 +12,14 @@ # * date Author's Name version-release # - Summary of changes +* Wed Nov 28 2018 Scharel Clemens 0.1-3 +- Implemented checkboxes +- Link to external website containing the markdown syntax + +* Tue Nov 27 2018 Scharel Clemens 0.1-2 +- Improved "About" Page and included copies of the MIT and GPL licenses +- Automated version handling (based no yaml) + * Tue Nov 27 2018 Scharel Clemens 0.1-1 - List all notes of an account - Show the content of the notes @@ -22,7 +30,3 @@ - Edit category property - Markdown rendering powered by ShowdownJS - Multiple Nextcloud accounts - -* Tue Nov 27 2018 Scharel Clemens 0.1-2 -- Improved "About" Page and included copies of the MIT and GPL licenses -- Automated version handling (based no yaml) diff --git a/rpm/harbour-nextcloudnotes.spec b/rpm/harbour-nextcloudnotes.spec index 90de896..6ca4645 100644 --- a/rpm/harbour-nextcloudnotes.spec +++ b/rpm/harbour-nextcloudnotes.spec @@ -14,7 +14,7 @@ Name: harbour-nextcloudnotes %{?qtc_builddir:%define _builddir %qtc_builddir} Summary: Nextcloud Notes Version: 0.1 -Release: 2 +Release: 3 Group: Qt/Qt License: LICENSE URL: http://example.org/ diff --git a/rpm/harbour-nextcloudnotes.yaml b/rpm/harbour-nextcloudnotes.yaml index 1a61f70..8eea5fd 100644 --- a/rpm/harbour-nextcloudnotes.yaml +++ b/rpm/harbour-nextcloudnotes.yaml @@ -1,7 +1,7 @@ Name: harbour-nextcloudnotes Summary: Nextcloud Notes Version: 0.1 -Release: 2 +Release: 3 # The contents of the Group field should be one of the groups listed here: # https://github.com/mer-tools/spectacle/blob/master/data/GROUPS Group: Qt/Qt diff --git a/translations/harbour-nextcloudnotes.ts b/translations/harbour-nextcloudnotes.ts index 42fb4d5..cadd8b5 100644 --- a/translations/harbour-nextcloudnotes.ts +++ b/translations/harbour-nextcloudnotes.ts @@ -53,6 +53,10 @@ Reset + + Markdown syntax + + GPLLicense @@ -107,17 +111,6 @@ - - MarkdownPage - - Markdown Cheatsheet - - - - https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet - - - NotePage