Implemented checkboxes

This commit is contained in:
Scharel Clemens 2018-11-28 14:05:36 +01:00
parent 21aa7211ca
commit af18cc77d2
9 changed files with 71 additions and 55 deletions

View file

@ -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 \

View file

@ -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
}

View file

@ -17,9 +17,10 @@ Page {
title: qsTr("MIT License")
}
LinkedLabel {
Label {
x: Theme.horizontalPageMargin
width: parent.width - 2*x
wrapMode: Text.Wrap
text: "<p>Copyright (c) 2018 Scharel Clemens</p>
<p>Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -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")
}
}

View file

@ -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(/^<li>\[ \]\s(.*)<\/li>$/gm,
function(match, p1, offset) {
occurence++
return '<li><a href="tasklist:checkbox_' + occurence + '">☐ ' + p1 + '</a></li>'
} )
occurence = -1
convertedText = convertedText.replace(/^<li>\[x\]\s(.*)<\/li>$/gm,
function(match, p1, offset) {
occurence++
return '<li><a href="tasklist:uncheckbox_' + occurence + '">☑ ' + p1 + '</a></li>'
} )
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 {

View file

@ -12,6 +12,14 @@
# * date Author's Name <author's email> version-release
# - Summary of changes
* Wed Nov 28 2018 Scharel Clemens <harbour-nextcloudnotes@scharel.name> 0.1-3
- Implemented checkboxes
- Link to external website containing the markdown syntax
* Tue Nov 27 2018 Scharel Clemens <harbour-nextcloudnotes@scharel.name> 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 <harbour-nextcloudnotes@scharel.name> 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 <harbour-nextcloudnotes@scharel.name> 0.1-2
- Improved "About" Page and included copies of the MIT and GPL licenses
- Automated version handling (based no yaml)

View file

@ -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/

View file

@ -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

View file

@ -53,6 +53,10 @@
<source>Reset</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Markdown syntax</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GPLLicense</name>
@ -107,17 +111,6 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MarkdownPage</name>
<message>
<source>Markdown Cheatsheet</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>NotePage</name>
<message>