- NewNoteDialog riceve la cartella corrente: il file va dove sei, non nella radice del caveau. Un nome gia' presente viene rifiutato (la PUT avrebbe sovrascritto la nota senza chiedere) e il nome non puo' contenere "/". - PropfindParser.listing(): scarta la collezione stessa (il PROPFIND Depth:1 la include, e dentro una cartella sembrava di non essere entrati) e le voci nascoste (.obsidian/, .trash/), anche nella scansione di ricerca e tag: le note nel cestino non finiscono piu' nei risultati. - MainPage: se il client e' occupato la navigazione va in coda invece di essere persa, e l'elenco precedente viene svuotato subito (non resta sotto l'intestazione nuova). - Test del filtro con la risposta reale di Libro/; verificatore aggiornato per i segnali di cambio proprieta' (onBusyChanged).
94 lines
2.8 KiB
QML
94 lines
2.8 KiB
QML
import QtQuick 2.2
|
|
import Sailfish.Silica 1.0
|
|
|
|
Dialog {
|
|
id: dialog
|
|
|
|
property var dav
|
|
// Cartella corrente (finisce sempre con "/", vuota in radice): la nota
|
|
// nasce qui, non nella radice del caveau.
|
|
property string folder: ""
|
|
// Nomi già presenti nella cartella: un nome ripetuto non si accetta,
|
|
// perché la PUT sovrascriverebbe la nota esistente senza chiedere.
|
|
property var existingNames: []
|
|
|
|
property string resultPath: ""
|
|
property string resultName: ""
|
|
|
|
function fileName() {
|
|
var name = nameField.text.trim().replace(/^\/+/, "").replace(/\/+$/, "")
|
|
var lower = name.toLowerCase()
|
|
if (lower.indexOf(".md") !== lower.length - 3) name = name + ".md"
|
|
return name
|
|
}
|
|
|
|
function alreadyExists() {
|
|
var name = fileName().toLowerCase()
|
|
for (var i = 0; i < existingNames.length; i++) {
|
|
if (String(existingNames[i]).toLowerCase() === name) return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
function invalidChars() {
|
|
return nameField.text.indexOf("/") >= 0
|
|
}
|
|
|
|
canAccept: nameField.text.trim().length > 0 && !alreadyExists() && !invalidChars()
|
|
|
|
onAccepted: {
|
|
var name = fileName()
|
|
if (!name) return
|
|
resultName = name
|
|
resultPath = folder ? folder + name : name
|
|
dav.writeFile(resultPath, "# " + name.replace(/\.md$/, "") + "\n\n")
|
|
}
|
|
|
|
Column {
|
|
width: parent.width
|
|
|
|
DialogHeader { title: qsTr("New note") }
|
|
|
|
TextField {
|
|
id: nameField
|
|
width: parent.width
|
|
label: qsTr("Name")
|
|
placeholderText: qsTr("e.g. Idea")
|
|
EnterKey.enabled: dialog.canAccept
|
|
EnterKey.onClicked: {
|
|
if (dialog.canAccept) dialog.accept()
|
|
}
|
|
}
|
|
|
|
Label {
|
|
visible: dialog.alreadyExists()
|
|
x: Theme.paddingLarge
|
|
width: parent.width - 2 * Theme.paddingLarge
|
|
text: qsTr("A note with this name already exists here")
|
|
color: Theme.highlightColor
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
wrapMode: Text.Wrap
|
|
}
|
|
|
|
Label {
|
|
visible: dialog.invalidChars()
|
|
x: Theme.paddingLarge
|
|
width: parent.width - 2 * Theme.paddingLarge
|
|
text: qsTr("The name cannot contain /")
|
|
color: Theme.highlightColor
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
wrapMode: Text.Wrap
|
|
}
|
|
|
|
Label {
|
|
visible: dialog.folder !== ""
|
|
x: Theme.paddingLarge
|
|
width: parent.width - 2 * Theme.paddingLarge
|
|
text: qsTr("In %1").arg(dialog.folder)
|
|
color: Theme.secondaryColor
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
truncationMode: TruncationMode.Fade
|
|
}
|
|
}
|
|
}
|