Proposed changes to TiddlyWiki.prototype.getTags & config.macros.allTags

4 views
Skip to first unread message

Saq Imtiaz

unread,
Jul 7, 2006, 7:41:56 PM7/7/06
to TiddlyWikiDev
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?

Ken Girard

unread,
Jul 9, 2006, 3:16:52 AM7/9/06
to TiddlyWikiDev
Mind you I am a little tippsy at this point having come back from a
party but rather then 'allTags' how about 'notTag' since you looking
for thing not tagged with... whatever? 'allTags' sounds more like
something looking for all tiddlers tagged with...whatever.

Ken Girard

Saq Imtiaz

unread,
Jul 10, 2006, 4:22:50 AM7/10/06
to Tiddly...@googlegroups.com

Actually the ticket in questions was about being able to exclude  tags from the TabTags tiddler, which uses the allTags macro.

Saq

Ken Girard



Saq Imtiaz

unread,
Jul 15, 2006, 6:21:31 AM7/15/06
to TiddlyWikiDev
On 7/8/06, Saq Imtiaz <lew...@gmail.com> wrote:
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

While we are it, would it be worthwhile perhaps to  make it easy to distinguish tags that are tiddlers from those that arent, in the tag listing? Perhaps by making them bold? I know that I have times would have found this useful.

Saq


Reply all
Reply to author
Forward
0 new messages