Hey guys,
Was trying to kill some time again and came across this ticket regarding extending excludeLists to exclude tags from the tag listing:
http://trac.tiddlywiki.org/tiddlywiki/ticket/90
I've taken a slightly different approach to this than what might have been intended, but this is what I propose:
1) we modify TiddlyWiki.prototype.getTags to allow exclusion of tags tagged with a specified value.
So that store.getTags("excludeLists") will return an array of tags that doesnt contain any tags tagged with excludeLists
2) we then modify config.macros.allTags to allow specification of an optional tag to exclude through a parameter.
Eg: <<allTags excludeLists>> would display all tags not tagged with excludeLists
The reason I propose the change to the getTags function, and not just the macro is since the ability to exclude tags can come in handy elsewhere as well. Unless I've missed something, it should be perfectly backwards compatible too.
Also, we could 'hard-code' the allTags macro to exclude based on the tag excludeLists rather than accepting a parameter, but I feel greater flexibility is always nice for the end user.
The code:
// Return an array of all the tags in use. Each member of the array is another array where [0] is the name of the tag and [1] is the number of occurances
TiddlyWiki.prototype.getTags = function(exclude)
{
var results = [];
this.forEachTiddler(function(title,tiddler) {
for(var g=0; g<tiddler.tags.length
; g++)
{
var tag = tiddler.tags[g];
if (exclude!=undefined && store.tiddlerExists(tag) && (store.getTiddler(tag)).isTagged(exclude))
{return false;}
var f = false;
for(var c=0; c<results.length; c++)
if(results[c][0] == tag )
{
f = true;
results[c][1]++;
}
if(!f)
results.push([tag,1]);
}
});
results.sort(function (a,b) {if(a[0].toLowerCase() == b[0].toLowerCase()) return(0); else return (a[0].toLowerCase() < b[0].toLowerCase()) ? -1 : +1; });
return results;
}
config.macros.allTags.handler = function(place,macroName,params)
{
var exclude = params[0]? params[0]: undefined;
var tags = store.getTags(exclude);
var theDateList = createTiddlyElement(place,"ul",null,null,null);
if(tags.length == 0)
createTiddlyElement(theDateList,"li",null,"listTitle",
this.noTags);
for(var t=0; t<tags.length; t++)
{
var theListItem =createTiddlyElement(theDateList,"li",null,null,null);
var theTag = createTiddlyButton(theListItem,tags[t][0] + " (" + tags[t][1] + ")",
this.tooltip.format([tags[t][0]]),onClickTag);
theTag.setAttribute("tag",tags[t][0]);
}
}
Cheers,
Saq
PS: the modifications to store.getTags might be a little 'expensive'... perhaps we could optimize it some more?