1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

Create the new "tree" global macro (#2925)

* Create the "tree" global macro file (tree.tid)

* Added styles for the new "tree" global macro

* Update Explorer tab

* Cleaning the macro of unneeded code

I have chosen to keep the slash suffix in the branch node titles to go along with the rest (e.g. root node), so the "clean-chunk" macro isn't needed anymore.

* Minor fix
This commit is contained in:
Adrian Morosanu 2017-06-28 19:44:15 +03:00 committed by Jeremy Ruston
parent d5b50e0854
commit f75e97f308
3 changed files with 90 additions and 52 deletions

View File

@ -2,55 +2,4 @@ title: $:/core/ui/MoreSideBar/Explorer
tags: $:/tags/MoreSideBar
caption: {{$:/language/SideBar/Explorer/Caption}}
\define cleanChunk()
<$list filter="[[$(chunk)$]] +[removesuffix[/]]" variable="cleanChunk">
<$text text=<<cleanChunk>>/>
</$list>
\end
\define leafnode(prefix)
<li>
<$list filter="""[[$prefix$$(chunk)$]is[shadow]] [[$prefix$$(chunk)$]is[tiddler]] +[removeprefix[$prefix$]] +[limit[1]]"""
emptyMessage="""<$text text="$prefix$$(chunk)$"/>""">
<button class="tc-btn-invisible" disabled>{{$:/core/images/blank}}</button> <$link to="""$prefix$$(chunk)$""">
<$view field="title"/>
</$link>
</$list>
</li>
\end
\define branchnode(prefix)
<$reveal type="nomatch" text="" default="""$(chunk)$""">
<li>
<$list filter="""[all[shadows+tiddlers]prefix[$prefix$$(chunk)$]] -[[$prefix$$(chunk)$]] +[limit[1]]""">
<$reveal type="nomatch" state="""$:/state/tree/$prefix$$(chunk)$""" text="show">
<$button set="""$:/state/tree/$prefix$$(chunk)$""" setTo="show" class="tc-btn-invisible">{{$:/core/images/right-arrow}}</$button>
</$reveal>
<$reveal type="match" state="""$:/state/tree/$prefix$$(chunk)$""" text="show">
<$button set="""$:/state/tree/$prefix$$(chunk)$""" setTo="hide" class="tc-btn-invisible">{{$:/core/images/down-arrow}}</$button>
</$reveal>
</$list>
<<cleanChunk>>
<$list filter="""[all[shadows+tiddlers]prefix[$prefix$$(chunk)$]] -[[$prefix$$(chunk)$]] +[limit[1]]""">(<$count filter="""[all[shadows+tiddlers]prefix[$prefix$$(chunk)$]] -[[$prefix$$(chunk)$]]"""/>)
<$reveal type="match" state="""$:/state/tree/$prefix$$(chunk)$""" text="show">
<$macrocall $name="tree" prefix="""$prefix$$(chunk)$"""/>
</$reveal>
</$list>
</li>
</$reveal>
\end
\define tree(prefix)
<ol>
<$list filter="[all[shadows+tiddlers]removeprefix[$prefix$]splitbefore[/]sort[title]] +[!suffix[/]]" variable="chunk">
<<leafnode """$prefix$""">>
</$list>
<$list filter="[all[shadows+tiddlers]removeprefix[$prefix$]splitbefore[/]sort[title]] +[suffix[/]]" variable="chunk">
<<branchnode """$prefix$""">>
</$list>
</ol>
\end
<div class="tc-table-of-contents">
<<tree "$:/">>
</div>

53
core/wiki/macros/tree.tid Normal file
View File

@ -0,0 +1,53 @@
title: $:/core/macros/tree
tags: $:/tags/Macro
\define leaf-node(prefix)
<li>
<$list filter="""[[$prefix$$(chunk)$]is[shadow]] [[$prefix$$(chunk)$]is[tiddler]] +[removeprefix[$prefix$]] +[limit[1]]"""
emptyMessage="""<$text text="$prefix$$(chunk)$"/>""">
<span>{{$:/core/images/file}}</span> <$link to="""$prefix$$(chunk)$""">
<$view field="title"/>
</$link>
</$list>
</li>
\end
\define branch-node(prefix)
<$reveal type="nomatch" text="" default="""$(chunk)$""">
<li>
<$list filter="""[all[shadows+tiddlers]prefix[$prefix$$(chunk)$]] -[[$prefix$$(chunk)$]] +[limit[1]]""">
<$reveal type="nomatch" state="""$:/state/tree/$prefix$$(chunk)$""" text="show">
<$button set="""$:/state/tree/$prefix$$(chunk)$""" setTo="show" class="tc-btn-invisible">{{$:/core/images/folder}} """$(chunk)$"""</$button>
</$reveal>
<$reveal type="match" state="""$:/state/tree/$prefix$$(chunk)$""" text="show">
<$button set="""$:/state/tree/$prefix$$(chunk)$""" setTo="hide" class="tc-btn-invisible">{{$:/core/images/folder}} """$(chunk)$"""</$button>
</$reveal>
</$list>
<$list filter="""[all[shadows+tiddlers]prefix[$prefix$$(chunk)$]] -[[$prefix$$(chunk)$]] +[limit[1]]"""><span>(<$count filter="""[all[shadows+tiddlers]prefix[$prefix$$(chunk)$]] -[[$prefix$$(chunk)$]]"""/>)</span>
<$reveal type="match" state="""$:/state/tree/$prefix$$(chunk)$""" text="show">
<$macrocall $name="tree-node" prefix="""$prefix$$(chunk)$"""/>
</$reveal>
</$list>
</li>
</$reveal>
\end
\define tree-node(prefix)
<ol>
<$list filter="[all[shadows+tiddlers]removeprefix[$prefix$]splitbefore[/]sort[title]] +[!suffix[/]]" variable="chunk">
<<leaf-node """$prefix$""">>
</$list>
<$list filter="[all[shadows+tiddlers]removeprefix[$prefix$]splitbefore[/]sort[title]] +[suffix[/]]" variable="chunk">
<<branch-node """$prefix$""">>
</$list>
</ol>
\end
\define tree(prefix)
<div class="tc-tree">
<span><$text text="""$prefix$"""/></span>
<div>
<$macrocall $name="tree-node" prefix="""$prefix$"""/>
</div>
</div>
\end

View File

@ -2381,4 +2381,40 @@ body.tc-dirty span.tc-dirty-indicator, body.tc-dirty span.tc-dirty-indicator svg
.tc-error {
background: #f00;
color: #fff;
}
}
/*
** Tree macro
*/
.tc-tree div {
padding-left: 14px;
}
.tc-tree ol {
list-style-type: none;
padding-left: 0;
margin-top: 0;
}
.tc-tree ol ol {
padding-left: 1em;
}
.tc-tree button {
color: #acacac;
}
.tc-tree svg {
fill: #acacac;
}
.tc-tree span svg {
width: 1em;
height: 1em;
vertical-align: baseline;
}
.tc-tree li span {
color: lightgray;
}