Merge branch '5-allow-selection-of-zettel-ids-being-in-zettel-titles-or-zettel-bodies' into 'master'
Resolve "Allow Selection of Zettel IDs being in Zettel Titles or Zettel Bodies" Closes #5 See merge request marty.oehme/qown-zettelkasten!2
This commit is contained in:
commit
e2a238e812
1 changed files with 57 additions and 8 deletions
65
zettel.qml
65
zettel.qml
|
@ -3,21 +3,29 @@ import QOwnNotesTypes 1.0
|
|||
import com.qownnotes.noteapi 1.0
|
||||
|
||||
QtObject {
|
||||
property bool anchorInFilename;
|
||||
property string idMarker;
|
||||
property bool wikiLinks;
|
||||
|
||||
property variant settingsVariables: [
|
||||
{
|
||||
"identifier": "anchorInFilename",
|
||||
"name": "Display Zettel anchors in note filenames",
|
||||
"description": "By default, the anchor of a Zettel will appear in its body, prepended with its ID Marker selected below.\nIf enabled, this will instead put the anchor in the filename itself and disregard any anchors in Zettel bodies.",
|
||||
"type": "boolean",
|
||||
"default": "false",
|
||||
},
|
||||
{
|
||||
"identifier": "idMarker",
|
||||
"name": "Zettelkasten ID Marker",
|
||||
"description": "The in-text marker denoting that a Zettel ID is following. Make sure to use something which is not ambiguous, and does not appear in any other way than to actually denote the Zettel ID. Multiple characters are fine (as in the default '§§')",
|
||||
"name": "Zettelkasten anchor marker",
|
||||
"description": "The in-text marker denoting that a Zettel ID is following.\nMake sure to use something which is not ambiguous, and does not appear in any other way than to actually denote the Zettel ID.\nMultiple characters are fine (as in the default '§§')\nIf 'In-Title Anchors' are selected above this option has no effect.",
|
||||
"type": "string",
|
||||
"default": "§§",
|
||||
},
|
||||
{
|
||||
"identifier": "wikiLinks",
|
||||
"name": "Default to [[WikiLinks]]",
|
||||
"description": "By default, links will take the form of standard markdown links. This will make automatically created links between Zettel take the form of wiki-links instead. The go to link function understands both types, regardless of this choice.",
|
||||
"description": "By default, links will take the form of standard markdown links.\nThis will make automatically created links between Zettel take the form of wiki-links instead.\nThe 'go to link' function understands both types, regardless of this choice.",
|
||||
"type": "boolean",
|
||||
"default": "false",
|
||||
},
|
||||
|
@ -49,7 +57,7 @@ QtObject {
|
|||
|
||||
function onZettelCreateClicked() {
|
||||
let uid = exactDate();
|
||||
let selected = script.noteTextEditSelectedText();
|
||||
let selected = script.noteTextEditSelectedText().trim();
|
||||
|
||||
// Link the from the old Zettel to the new one if anything was selected
|
||||
if(selected !== "") {
|
||||
|
@ -111,12 +119,16 @@ QtObject {
|
|||
function zettelSelectorDialog(editableTextBox, zettelArray) {
|
||||
if (zettelArray == null) {
|
||||
zettelArray = [];
|
||||
script.fetchNoteIdsByNoteTextPart(idMarker).forEach(function (noteId){
|
||||
fetchZettelIDs().forEach(function (noteId){
|
||||
let note = script.fetchNoteById(noteId);
|
||||
zettelArray.push(note.name + " --id:"+note.id);
|
||||
});
|
||||
}
|
||||
|
||||
if (zettelArray.length == 0) {
|
||||
script.informationMessageBox("No valid Zettel found.");
|
||||
}
|
||||
|
||||
let selected = script.inputDialogGetItem("Zettel", "Select a Zettel", zettelArray, 0, editableTextBox);
|
||||
// FIXME dont display id in names - rather, go getNotebyName(name) -> (get its id) -> set note to it
|
||||
return script.fetchNoteById(selected.substring(selected.search(/--id:/)+5));
|
||||
|
@ -146,8 +158,41 @@ QtObject {
|
|||
}
|
||||
}
|
||||
|
||||
// Returns List of Zettel ids with the specified uID.
|
||||
// If no uID provided returns all Zettel found in the current directory.
|
||||
function fetchZettelIDs(uid) {
|
||||
let uid = uid ? uid : "";
|
||||
let noteIds = anchorInFilename ? _getAllZettelFromTitle(uid) : _getAllZettelFromAnchor(uid);
|
||||
return noteIds;
|
||||
}
|
||||
|
||||
// Looks for the combination of idMarker and uID (optionally) in all note texts.
|
||||
function _getAllZettelFromAnchor(optionaluId) {
|
||||
return script.fetchNoteIdsByNoteTextPart(idMarker + optionaluId);
|
||||
}
|
||||
|
||||
// Looks for the uID (optionally) in all note texts.
|
||||
// If no uID passed in, simply return all notes which conform to the Zettel-Title template.
|
||||
function _getAllZettelFromTitle(optionaluID) {
|
||||
let allnotes = script.fetchNoteIdsByNoteTextPart("");
|
||||
let noteIds = [];
|
||||
|
||||
if (optionaluID != "") {
|
||||
allnotes.forEach(function(noteId) {
|
||||
if (script.fetchNoteById(noteId).name.startsWith(optionaluID)) noteIds.push(noteId);
|
||||
});
|
||||
return noteIds;
|
||||
}
|
||||
|
||||
allnotes.forEach(function(noteId) {
|
||||
if (script.fetchNoteById(noteId).name.search(/^\d{14}/) != -1) noteIds.push(noteId);
|
||||
});
|
||||
|
||||
return noteIds;
|
||||
}
|
||||
|
||||
function getNoteByZettelId(uid) {
|
||||
let noteId = script.fetchNoteIdsByNoteTextPart(idMarker + uid);
|
||||
let noteId = fetchZettelIDs(uid);
|
||||
if (noteId.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -172,13 +217,17 @@ QtObject {
|
|||
if (headline == "") {
|
||||
headline = "Zettel"
|
||||
}
|
||||
let text = headline.toString() + "\n";
|
||||
let text = "";
|
||||
|
||||
if (anchorInFilename) text += uid.toString() + " ";
|
||||
|
||||
text += headline.toString() + "\n";
|
||||
|
||||
// Create Headline Separator
|
||||
text += "===============\n";
|
||||
|
||||
// Create uid tag
|
||||
text += idMarker + uid.toString() + "\n\n";
|
||||
if (!anchorInFilename) text += idMarker + uid.toString() + "\n\n";
|
||||
|
||||
// Create content unit (i.e. space)
|
||||
text += "\n\n\n\n\n";
|
||||
|
|
Loading…
Reference in a new issue