0.3.0: ricerca nel testo, caselle di spunta toccabili, tag

- Ricerca nel testo: la cartella viene percorsa ricorsivamente e le note .md
  scaricate una alla volta (il WebDAV non cerca nel contenuto), con avanzamento,
  possibilità di fermare e il passaggio che contiene la parola. La ricerca per
  titolo nella lista resta istantanea.
- Caselle di spunta: "- [ ]" e "- [x]" diventano caselle toccabili
  nell'anteprima; il tocco riscrive quella sola riga e salva subito, e l'editor
  segue (senza, uscendo riscriverebbe la versione vecchia sul server).
- Tag: front-matter (tags: [a, b], lista a trattini o separata da virgole) e
  #tag nel testo; pastiglie in cima all'anteprima, #tag toccabili, nuova
  schermata Tag con il conteggio per tag. Il blocco front-matter non viene più
  stampato come testo.
- tests/qml_contract_check.py: confronta i nomi JS e le proprietà usati dalla
  QML con i sorgenti, le pagine raggiungibili e i parametri dei gestori dei
  segnali — la classe di errori che la compilazione non vede.
- Catalogo italiano aggiornato (25 stringhe nuove); repo ripulito dai residui di
  build e .gitignore esteso.
This commit is contained in:
kaneda committed 2026-11-08 20:55:22 +01:00
1 parent aab29c76cb
commit 8259297a27
15 files changed
+1280 -64

No files matched your search

+12 -1
View File
@@ -47,6 +47,16 @@ Page {
if (notify) banner.show(qsTr("Saving..."), false)
}
// Called by the preview when it changes the note (a checked box): the text
// typed here must follow, or leaving the editor would write the old version
// back over the server copy. `saved` says whether the change already
// reached the server, and therefore whether the note is still dirty.
function externalUpdate(text, saved) {
if (saved) initialContent = text
editor.text = text
dirty = !saved
}
Connections {
target: dav
onFileReady: {
@@ -100,7 +110,8 @@ Page {
MenuItem {
text: qsTr("Preview")
onClicked: pageStack.push(Qt.resolvedUrl("PreviewPage.qml"),
{ dav: page.dav, noteName: page.noteName, notePath: page.notePath, markdown: editor.text })
{ dav: page.dav, noteName: page.noteName, notePath: page.notePath,
markdown: editor.text, owner: page })
}
MenuItem {
text: qsTr("Delete note")
+11 -1
View File
@@ -86,7 +86,7 @@ Page {
SearchField {
id: searchField
width: parent.width
placeholderText: qsTr("Search")
placeholderText: qsTr("Filter by title")
// Bound to the page property so the delegates (which cannot
// see header ids) can clear it via page.filterText.
text: page.filterText
@@ -170,6 +170,16 @@ Page {
})
}
}
MenuItem {
text: qsTr("Search in the text")
onClicked: pageStack.push(Qt.resolvedUrl("SearchPage.qml"),
{ dav: page.dav, rootPath: page.currentPath })
}
MenuItem {
text: qsTr("Tags")
onClicked: pageStack.push(Qt.resolvedUrl("TagPage.qml"),
{ dav: page.dav, rootPath: "" })
}
MenuItem {
text: qsTr("Refresh")
onClicked: page.reload()
+82 -3
View File
@@ -14,6 +14,11 @@ Page {
property string baseUrl: ""
property var imageMap: ({})
property string pendingOpen: ""
// The editor below: it must follow every change made here (a checked box),
// otherwise leaving the editor would save the old text back.
property var owner: null
// Front-matter tags: the block itself is not rendered, these chips are it.
property var fmTags: []
Component.onCompleted: {
// Base for relative links: the note's WebDAV folder. Relative links
@@ -23,10 +28,19 @@ Page {
if (notePath && notePath.indexOf("/") >= 0) {
baseUrl += "/" + notePath.substring(0, notePath.lastIndexOf("/"))
}
refreshTags()
renderPreview()
extractImages()
}
function refreshTags() {
try {
page.fmTags = Markdown.tagDetails(page.markdown).frontMatter
} catch (e) {
page.fmTags = []
}
}
function resolveImg(u) {
if (/^[a-z]+:/i.test(u) || u.charAt(0) === "/" || u.charAt(0) === "#") return u
return String(page.baseUrl).replace(/\/+$/, "") + "/" + u
@@ -35,7 +49,10 @@ Page {
function renderPreview() {
try {
htmlText = Markdown.render(markdown, baseUrl,
{ imageMap: page.imageMap, imageLabel: qsTr("image") })
{ imageMap: page.imageMap,
imageLabel: qsTr("image"),
checkOff: Theme.secondaryColor,
checkOn: Theme.highlightColor })
} catch (e) {
console.log("Quill markdown render error:", e)
htmlText = "<tt>" + String(markdown).replace(/&/g, "&amp;").replace(/</g, "&lt;") + "</tt>"
@@ -63,6 +80,31 @@ Page {
dav.readFile(page.pendingOpen)
}
// A tapped checkbox rewrites exactly one line and saves it at once: the
// note on the server is the only copy, so waiting for the editor to be left
// would lose the tick if the app were closed first.
function toggleLine(lineIndex) {
var next = Markdown.toggleTask(page.markdown, lineIndex)
if (next === null) {
banner.show(qsTr("This line is not a task"), true)
return
}
page.markdown = next
page.refreshTags()
page.renderPreview()
if (page.owner && page.owner.externalUpdate) page.owner.externalUpdate(next, false)
if (page.dav.busy) {
banner.show(qsTr("Save in progress, the change is kept"), false)
return
}
page.dav.writeFile(page.notePath, next)
}
function openTag(tag) {
pageStack.push(Qt.resolvedUrl("SearchPage.qml"),
{ dav: page.dav, tagFilter: tag, rootPath: "" })
}
Connections {
target: dav
onFileReady: {
@@ -79,6 +121,8 @@ Page {
if (page.pendingOpen) {
page.pendingOpen = ""
banner.show(qsTr("Cannot open the note: %1").arg(message), true)
} else {
banner.show(message, true)
}
}
}
@@ -94,24 +138,59 @@ Page {
SilicaFlickable {
anchors.fill: parent
contentHeight: previewLabel.height + Theme.paddingLarge * 2
contentHeight: column.height + Theme.paddingLarge * 2
Column {
id: column
width: parent.width
PageHeader { title: noteName }
Flow {
x: Theme.paddingLarge
width: column.width - 2 * Theme.paddingLarge
spacing: Theme.paddingSmall
visible: page.fmTags.length > 0
Repeater {
model: page.fmTags
delegate: Rectangle {
width: tagLabel.implicitWidth + Theme.paddingMedium * 2
height: tagLabel.implicitHeight + Theme.paddingSmall
radius: height / 2
color: Theme.rgba(Theme.highlightBackgroundColor, 0.2)
Label {
id: tagLabel
anchors.centerIn: parent
text: "#" + modelData
color: Theme.highlightColor
font.pixelSize: Theme.fontSizeExtraSmall
}
MouseArea {
anchors.fill: parent
onClicked: page.openTag(modelData)
}
}
}
}
Label {
id: previewLabel
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
topPadding: Theme.paddingMedium
text: page.htmlText
textFormat: Text.RichText
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
linkColor: Theme.highlightColor
onLinkActivated: {
var l = String(link)
if (l.indexOf("quill://") === 0) {
if (l.indexOf("quill-check://") === 0) {
page.toggleLine(parseInt(l.substring("quill-check://".length), 10))
} else if (l.indexOf("quill-tag://") === 0) {
page.openTag(decodeURIComponent(l.substring("quill-tag://".length)))
} else if (l.indexOf("quill://") === 0) {
page.openWikiLink(decodeURIComponent(l.substring("quill://".length)))
} else if (l.indexOf("file:") === 0) {
// A link that still resolved to a local file (no base):
+221
View File
@@ -0,0 +1,221 @@
import QtQuick 2.2
import Sailfish.Silica 1.0
import "../components/Markdown.js" as Markdown
import "../components"
// Search across the TEXT of the notes (WebDAV cannot do it: the folder is
// walked and the .md files are downloaded one at a time).
//
// The scan runs once, when the page opens; typing afterwards filters what is
// already in memory, so the field stays responsive. Notes are kept in memory up
// to a budget: past it a note is still listed (and searchable by title) but its
// text is not held, and a banner says so.
//
// With tagFilter set the page becomes a tag listing: no search field, only the
// notes that carry that tag.
Page {
id: page
property var dav
property string rootPath: "" // folder to scan ("" = whole vault root)
property string tagFilter: "" // when set: notes carrying this tag
property string term: ""
property bool scanning: false
property int total: 0
property int read: 0
property int errors: 0
property int matched: 0
property var notes: []
property real storedBytes: 0
property real maxStoredBytes: 16777216 // 16 MB of note text
property bool truncated: false
property string coverText: tagFilter !== "" ? "#" + tagFilter : qsTr("Search")
ListModel { id: results }
onTermChanged: refresh()
Component.onCompleted: start()
function start() {
if (!dav) return
results.clear()
notes = []
storedBytes = 0
truncated = false
matched = 0
total = 0
read = 0
errors = 0
scanning = true
dav.scanVault(rootPath)
}
function addNote(notePath, content) {
var name = notePath.substring(notePath.lastIndexOf("/") + 1)
var text = content || ""
if (storedBytes + text.length > maxStoredBytes) {
text = ""
truncated = true
} else {
storedBytes += text.length
}
notes.push({ path: notePath, name: name, content: text })
}
// Rebuild the result list from what is in memory.
function refresh() {
results.clear()
matched = 0
var t = term.trim().toLowerCase()
for (var i = 0; i < notes.length; i++) {
var n = notes[i]
var hitTitle = false
var hit = null
if (tagFilter !== "") {
if (!n.content) continue
if (!Markdown.hasTag(n.content, tagFilter)) continue
} else {
if (t === "") {
// No query yet: the whole scanned tree, folder paths
// included, so the page doubles as an index of the vault.
} else {
hitTitle = n.name.toLowerCase().indexOf(t) >= 0
hit = n.content ? Markdown.searchText(n.content, t) : null
if (!hitTitle && !hit) continue
}
}
results.append({
name: n.name,
path: n.path,
snippet: hit ? hit.snippet : ""
})
matched++
if (matched >= 500) break
}
}
Connections {
target: page.dav
onScanStart: {
page.total = count
page.scanning = count > 0
}
onScanProgress: {
page.read = done
page.total = all
}
onScanFile: page.addNote(path, content)
onScanFinished: {
page.read = done
page.errors = errs
page.scanning = false
page.refresh()
if (page.truncated) banner.show(qsTr("Only the first notes are kept in memory"), true)
}
onFailed: banner.show(message, true)
}
SilicaListView {
id: listView
anchors.fill: parent
model: results
header: Column {
width: parent.width
PageHeader { title: page.tagFilter !== "" ? "#" + page.tagFilter : qsTr("Search in the text") }
SearchField {
visible: page.tagFilter === ""
width: parent.width
placeholderText: qsTr("Search the notes")
text: page.term
onTextChanged: {
if (text !== page.term) page.term = text
}
}
Label {
visible: page.scanning
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
text: page.total > 0 ? qsTr("Reading notes: %1 of %2").arg(page.read).arg(page.total)
: qsTr("Looking for notes...")
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeSmall
}
Label {
visible: !page.scanning
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
text: (page.matched === 1 ? qsTr("1 note") : qsTr("%1 notes").arg(page.matched)) +
(page.errors > 0 ? qsTr(" · %1 unreadable").arg(page.errors) : "")
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeSmall
}
}
ViewPlaceholder {
enabled: !page.scanning && results.count === 0
text: page.tagFilter !== "" ? qsTr("No note with this tag")
: qsTr("No note contains this text")
}
delegate: ListItem {
id: resultItem
contentHeight: model.snippet !== "" ? Theme.itemSizeLarge : Theme.itemSizeMedium
onClicked: pageStack.push(Qt.resolvedUrl("EditorPage.qml"),
{ dav: page.dav, notePath: model.path, noteName: model.name })
Column {
anchors.verticalCenter: parent.verticalCenter
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
Label {
text: model.name
font.pixelSize: Theme.fontSizeMedium
truncationMode: TruncationMode.Fade
}
Label {
visible: model.snippet !== ""
text: model.snippet
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeExtraSmall
maximumLineCount: 2
truncationMode: TruncationMode.Fade
}
}
}
VerticalScrollDecorator { id: decorator }
PullDownMenu {
MenuItem {
text: qsTr("Search again")
onClicked: page.start()
}
MenuItem {
visible: page.dav && page.dav.scanning
text: qsTr("Stop")
onClicked: page.dav.cancelScan()
}
}
BusyIndicator {
anchors.centerIn: parent
size: BusyIndicatorSize.Large
running: page.scanning
}
}
onStatusChanged: {
// Leaving the page must not leave a scan running in the background:
// it would keep the network busy for the next screen.
if (status === PageStatus.Inactive && page.dav && page.dav.scanning) page.dav.cancelScan()
}
Banner { id: banner }
}
+174
View File
@@ -0,0 +1,174 @@
import QtQuick 2.2
import Sailfish.Silica 1.0
import "../components/Markdown.js" as Markdown
import "../components"
// Every tag in the vault, with how many notes carry it. Built from a scan (the
// tags live inside the notes, so the only way to know them is to read them):
// front-matter tags and inline #tags both count, case-insensitively.
Page {
id: page
property var dav
property string rootPath: "" // "" = whole vault
property bool scanning: false
property int total: 0
property int read: 0
property int errors: 0
// tag (lower case) -> { name: original case, count: n }
property var found: ({})
property int tagCount: 0
property string coverText: qsTr("Tags")
ListModel { id: tagsModel }
Component.onCompleted: start()
function start() {
if (!dav) return
tagsModel.clear()
found = ({})
tagCount = 0
total = 0
read = 0
errors = 0
scanning = true
dav.scanVault(rootPath)
}
function addTags(content) {
var d = Markdown.tagDetails(content || "")
var all = d.frontMatter.concat(d.inline)
for (var i = 0; i < all.length; i++) {
var name = all[i]
var key = name.toLowerCase()
var known = found[key]
if (known) {
known.count += 1
} else {
found[key] = { name: name, count: 1 }
tagCount += 1
}
}
}
// Most used first, then alphabetical: the list is a map of the vault.
function rebuild() {
tagsModel.clear()
var list = []
for (var key in found) {
if (found.hasOwnProperty(key)) list.push(found[key])
}
list.sort(function (a, b) {
if (a.count !== b.count) return b.count - a.count
var an = a.name.toLowerCase(), bn = b.name.toLowerCase()
return an < bn ? -1 : (an > bn ? 1 : 0)
})
for (var i = 0; i < list.length; i++) {
tagsModel.append({ tag: list[i].name, uses: list[i].count })
}
}
Connections {
target: page.dav
onScanStart: {
page.total = count
page.scanning = count > 0
}
onScanProgress: {
page.read = done
page.total = all
}
onScanFile: page.addTags(content)
onScanFinished: {
page.read = done
page.errors = errs
page.scanning = false
page.rebuild()
}
onFailed: banner.show(message, true)
}
SilicaListView {
id: listView
anchors.fill: parent
model: tagsModel
header: Column {
width: parent.width
PageHeader { title: qsTr("Tags") }
Label {
visible: page.scanning
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
text: page.total > 0 ? qsTr("Reading notes: %1 of %2").arg(page.read).arg(page.total)
: qsTr("Looking for notes...")
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeSmall
}
Label {
visible: !page.scanning
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
text: page.tagCount === 1 ? qsTr("1 tag in the notes")
: qsTr("%1 tags in the notes").arg(page.tagCount)
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeSmall
}
}
ViewPlaceholder {
enabled: !page.scanning && tagsModel.count === 0
text: qsTr("No tags in the notes. Write #tag in a note or add a tags: field at the top.")
}
delegate: ListItem {
contentHeight: Theme.itemSizeSmall
onClicked: pageStack.push(Qt.resolvedUrl("SearchPage.qml"),
{ dav: page.dav, tagFilter: model.tag, rootPath: "" })
Label {
x: Theme.paddingLarge
anchors.verticalCenter: parent.verticalCenter
width: parent.width - 2 * Theme.paddingLarge - usesLabel.width - Theme.paddingLarge
text: "#" + model.tag
color: Theme.highlightColor
truncationMode: TruncationMode.Fade
}
Label {
id: usesLabel
anchors.right: parent.right
anchors.rightMargin: Theme.paddingLarge
anchors.verticalCenter: parent.verticalCenter
text: model.uses
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeSmall
}
}
VerticalScrollDecorator { id: decorator }
PullDownMenu {
MenuItem {
text: qsTr("Scan again")
onClicked: page.start()
}
MenuItem {
visible: page.dav && page.dav.scanning
text: qsTr("Stop")
onClicked: page.dav.cancelScan()
}
}
BusyIndicator {
anchors.centerIn: parent
size: BusyIndicatorSize.Large
running: page.scanning
}
}
onStatusChanged: {
if (status === PageStatus.Inactive && page.dav && page.dav.scanning) page.dav.cancelScan()
}
Banner { id: banner }
}