1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2026-04-29 02:01:29 +00:00

Add provisional version of new tagger manager

For discussion
This commit is contained in:
Jermolene
2016-11-26 12:48:47 +00:00
parent 3bceb98119
commit e98d324e66
21 changed files with 448 additions and 105 deletions

View File

@@ -12,6 +12,23 @@ Filter operators for manipulating the current selection list
/*global $tw: false */
"use strict";
/*
Order a list
*/
exports.order = function(source,operator,options) {
var results = [];
if(operator.operand.toLowerCase() === "reverse") {
source(function(tiddler,title) {
results.unshift(title);
});
} else {
source(function(tiddler,title) {
results.push(title);
});
}
return results;
};
/*
Reverse list
*/

View File

@@ -17,19 +17,30 @@ Export our filter function
*/
exports.tag = function(source,operator,options) {
var results = [];
if(operator.prefix === "!") {
if((operator.suffix || "").toLowerCase() === "strict" && !operator.operand) {
// New semantics:
// Always return copy of input if operator.operand is missing
source(function(tiddler,title) {
if(tiddler && !tiddler.hasTag(operator.operand)) {
results.push(title);
}
results.push(title);
});
} else {
source(function(tiddler,title) {
if(tiddler && tiddler.hasTag(operator.operand)) {
results.push(title);
}
});
results = options.wiki.sortByList(results,operator.operand);
// Old semantics:
if(operator.prefix === "!") {
// Returns a copy of the input if operator.operand is missing
source(function(tiddler,title) {
if(tiddler && !tiddler.hasTag(operator.operand)) {
results.push(title);
}
});
} else {
// Returns empty results if operator.operand is missing
source(function(tiddler,title) {
if(tiddler && tiddler.hasTag(operator.operand)) {
results.push(title);
}
});
results = options.wiki.sortByList(results,operator.operand);
}
}
return results;
};

View File

@@ -16,16 +16,22 @@ Filter operator returning all the selected tiddlers that are untagged
Export our filter function
*/
exports.untagged = function(source,operator,options) {
var results = [];
var results = [],
isTagged = (operator.operand || operator.suffix || "").toLowerCase() === "no" ?
function(tiddler) {
return false;
} : function(tiddler) {
return tiddler && $tw.utils.isArray(tiddler.fields.tags) && tiddler.fields.tags.length > 0;
};
if(operator.prefix === "!") {
source(function(tiddler,title) {
if(tiddler && $tw.utils.isArray(tiddler.fields.tags) && tiddler.fields.tags.length > 0) {
if(isTagged(tiddler)) {
$tw.utils.pushTop(results,title);
}
});
} else {
source(function(tiddler,title) {
if(!tiddler || !tiddler.hasField("tags") || ($tw.utils.isArray(tiddler.fields.tags) && tiddler.fields.tags.length === 0)) {
if(!isTagged(tiddler)) {
$tw.utils.pushTop(results,title);
}
});

View File

@@ -202,32 +202,42 @@ DropZoneWidget.prototype.importDataTypes = [
];
DropZoneWidget.prototype.handlePasteEvent = function(event) {
var self = this,
createTiddlerFromString = function(text,type) {
var tiddlerFields = {
title: self.wiki.generateNewTitle("Untitled"),
text: text,
type: type
};
if($tw.log.IMPORT) {
console.log("Importing string '" + text + "', type: '" + type + "'");
}
self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify([tiddlerFields])});
};
// Let the browser handle it if we're in a textarea or input box
if(["TEXTAREA","INPUT"].indexOf(event.target.tagName) == -1) {
var self = this,
items = event.clipboardData.items;
var items = event.clipboardData.items;
// Enumerate the clipboard items
for(var t = 0; t<items.length; t++) {
var item = items[t];
if(item.kind === "file") {
// Import any files
this.wiki.readFile(item.getAsFile(),function(tiddlerFieldsArray) {
self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(tiddlerFieldsArray)});
});
} else if(item.kind === "string") {
// Create tiddlers from string items
var type = item.type;
item.getAsString(function(str) {
var tiddlerFields = {
title: self.wiki.generateNewTitle("Untitled"),
text: str,
type: type
};
if($tw.log.IMPORT) {
console.log("Importing string '" + str + "', type: '" + type + "'");
}
self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify([tiddlerFields])});
});
if(items) {
for(var t = 0; t<items.length; t++) {
var item = items[t];
if(item.kind === "file") {
// Import any files
this.wiki.readFile(item.getAsFile(),function(tiddlerFieldsArray) {
self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(tiddlerFieldsArray)});
});
} else if(item.kind === "string") {
// Create tiddlers from string items
item.getAsString(function(str) {
createTiddlerFromString(str,item.type);
});
}
}
} else {
// Enumerate the clipboard types
var type = event.clipboardData.types[0];
if(type) {
createTiddlerFromString(event.clipboardData.getData(type),type);
}
}
// Tell the browser that we've handled the paste