1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-12-07 17:28:05 +00:00

Add support for filtering shadow tiddlers

This commit is contained in:
Jeremy Ruston
2013-04-03 14:29:12 +01:00
parent 0d247cb752
commit dc00e584fb
6 changed files with 46 additions and 19 deletions

View File

@@ -106,7 +106,13 @@ exports.operators = {
}
break;
case "system":
return "for(title in source) {if(" + op + "this.getTiddler(title).isSystem()) {$tw.utils.pushTop(subResults,title);}}";
return "for(title in source) {if(" + op + "this.isSystemTiddler(title)) {$tw.utils.pushTop(subResults,title);}}";
case "shadow":
if(operator.prefix === "!") {
return "for(title in source) {if(!this.isShadowTiddler(title)) {$tw.utils.pushTop(subResults,title);}}";
} else {
return "for(title in this.shadowTiddlers) {$tw.utils.pushTop(subResults,title);}";
}
case "missing":
if(operator.prefix === "!") {
return "for(title in source) {$tw.utils.pushTop(subResults,title);}";
@@ -134,7 +140,9 @@ exports.operators = {
}
break;
case "system":
return "for(r=subResults.length-1; r>=0; r--) {if(" + op + "this.getTiddler(subResults[r]).isSystem()) {subResults.splice(r,1);}}";
return "for(r=subResults.length-1; r>=0; r--) {if(" + op + "this.isSystemTiddler(subResults[r])) {subResults.splice(r,1);}}";
case "shadow":
return "for(r=subResults.length-1; r>=0; r--) {if(" + op + "this.isShadowTiddler(subResults[r])) {subResults.splice(r,1);}}";
case "missing":
return "t = this.getMissingTitles(); for(r=subResults.length-1; r>=0; r--) {if(" + op + "!$tw.utils.hop(t,subResults[r])) {subResults.splice(r,1);}}";
case "orphan":

View File

@@ -16,17 +16,6 @@ exports.hasTag = function(tag) {
return this.fields.tags && this.fields.tags.indexOf(tag) !== -1;
};
exports.isSystem = function() {
if(!$tw.utils.hop(this,"systemFlag")) {
this.systemFlag = this.fields.title.indexOf("$:/") === 0;
}
return this.systemFlag;
};
exports.isTemporary = function() {
return this.fields.title.indexOf("$:/temp/") === 0;
};
exports.getFieldString = function(field) {
var value = this.fields[field];
// Check for a missing field

View File

@@ -37,6 +37,7 @@ LinkWidget.prototype.generate = function() {
this.isExternal = isLinkExternal(this.to);
if(!this.isExternal) {
this.isMissing = !this.renderer.renderTree.wiki.tiddlerExists(this.to);
this.isShadow = this.renderer.renderTree.wiki.isShadowTiddler(this.to);
}
// Compose the link
var classes = ["tw-tiddlylink"]
@@ -44,10 +45,15 @@ LinkWidget.prototype.generate = function() {
$tw.utils.pushTop(classes,"tw-tiddlylink-external");
} else {
$tw.utils.pushTop(classes,"tw-tiddlylink-internal");
if(this.isMissing) {
if(this.isShadow) {
$tw.utils.pushTop(classes,"tw-tiddlylink-shadow");
}
if(this.isMissing && !this.isShadow) {
$tw.utils.pushTop(classes,"tw-tiddlylink-missing");
} else {
$tw.utils.pushTop(classes,"tw-tiddlylink-resolves");
if(!this.isMissing) {
$tw.utils.pushTop(classes,"tw-tiddlylink-resolves");
}
}
}
var events = [{name: "click", handlerObject: this, handlerMethod: "handleClickEvent"}];

View File

@@ -98,7 +98,7 @@ TranscludeWidget.prototype.generate = function() {
if(this.renderer.hasAttribute("class")) {
$tw.utils.pushTop(classes,this.renderer.getAttribute("class").split(" "));
}
if(!this.renderer.renderTree.wiki.tiddlerExists(this.targetTitle)) {
if(!this.renderer.renderTree.wiki.tiddlerExists(this.targetTitle) && !this.renderer.renderTree.wiki.isShadowTiddler(this.targetTitle)) {
$tw.utils.pushTop(classes,"tw-tiddler-missing");
}
// Create the renderers for the wrapper and the children

View File

@@ -164,6 +164,18 @@ exports.tiddlerExists = function(title) {
return !!this.tiddlers[title];
};
exports.isSystemTiddler = function(title) {
return title.indexOf("$:/") === 0;
};
exports.isTemporaryTiddler = function(title) {
return title.indexOf("$:/temp/") === 0;
};
exports.isShadowTiddler = function(title) {
return $tw.utils.hop(this.shadowTiddlers,title);
};
exports.addTiddler = function(tiddler) {
// Check if we're passed a fields hashmap instead of a tiddler
if(!(tiddler instanceof $tw.Tiddler)) {
@@ -184,7 +196,7 @@ exports.getTiddlers = function(sortField,excludeTag) {
sortField = sortField || "title";
var tiddlers = [], t, titles = [];
for(t in this.tiddlers) {
if($tw.utils.hop(this.tiddlers,t) && !this.tiddlers[t].isSystem() && (!excludeTag || !this.tiddlers[t].hasTag(excludeTag))) {
if($tw.utils.hop(this.tiddlers,t) && !this.isSystemTiddler(t) && (!excludeTag || !this.tiddlers[t].hasTag(excludeTag))) {
tiddlers.push(this.tiddlers[t]);
}
}
@@ -344,7 +356,7 @@ exports.getOrphanTitles = function() {
exports.getSystemTitles = function() {
var titles = [];
for(var title in this.tiddlers) {
if(this.tiddlers[title].isSystem()) {
if(this.isSystemTiddler(title)) {
titles.push(title);
}
}
@@ -352,6 +364,15 @@ exports.getSystemTitles = function() {
return titles;
};
exports.getShadowTitles = function() {
var titles = [];
for(var title in this.shadowTiddlers) {
titles.push(title);
}
titles.sort();
return titles;
};
/*
Retrieves a list of the tiddler titles that are tagged with a given tag
*/