Is it possible to only tag a tiddler if a specific palette is active?

So I’m making a blackout palette that pairs with an edit of the tag macro tiddler, and I was planning to use the reveal widget to only show the changes to the tag macro when the specific palette was used, forgetting that if a definition isn’t on the first line, it won’t really work…

Here’s what I tried, for better reference:

title: $:/core/macros/tag/oled
tags: $:/tags/Macro
text:

<$reveal state="$:/palette" type="match" text="$:/palettes/Dark" default="$:/palettes/Dark">
\define tag-pill-styles()
background-color:$(foregroundColor)$;
fill:$(backgroundColor)$;
color:$(backgroundColor)$;
\end

\define tag-pill-inner(tag,icon,colour,fallbackTarget,colourA,colourB,element-tag,element-attributes,actions)
\whitespace trim
<$vars
	foregroundColor=<<contrastcolour target:"""$colour$""" fallbackTarget:"""$fallbackTarget$""" colourA:"""$colourA$""" colourB:"""$colourB$""">>
	backgroundColor=<<__colour__>>
>
<$element-tag$
	$element-attributes$
	class="tc-tag-label tc-btn-invisible"
	style=<<tag-pill-styles>>
>
	<<__actions__>>
	<$transclude tiddler=<<__icon__>>/>
	<$view tiddler=<<__tag__>> field="title" format="text" />
</$element-tag$>
\end

\define tag-pill-body(tag,icon,colour,palette,element-tag,element-attributes,actions)
\whitespace trim
<$macrocall $name="tag-pill-inner"
	tag=<<__tag__>>
	icon=<<__icon__>>
	colour=<<__colour__>>
	fallbackTarget={{$palette$##page-background}}
	colourA={{$palette$##page-background}}
	colourB={{$palette$##foreground}}
	element-tag=<<__element-tag__>>
	element-attributes=<<__element-attributes__>>
	actions=<<__actions__>>
/>
\end
</$reveal>

I’d like to either hide the text or remove the $:/tags/Macro if $:/palettes/Dark isn’t the selected palette, and not needing a button.
Does anyone have any suggestions? :sweat_smile:

Could you interfear with the pallet selection process to add this tag for your named pallet and remove it for the others?

@TW_Tones I’m not quite sure what you mean, would you be able to elaborate? :thinking:

1 Like

It would need more research, but in the core code where you select the pallet, you could add some additional actions, if matches $:/palettes/Dark then add the tag $:/tags/Macro to your desired tiddler, if not remove it.

  • Then this macro tag will be set for your desired pallet and remove for all others.
  • This occurs in $:/core/ui/ControlPanel/Palette then $:/snippets/paletteswitcher
  • In $:/snippets/paletteswitcher it uses a link catcher rather than buttons, and the link catcher widget has an actions parameter.

Ask if you want more

That might be above my skill level, as I don’t really know how to use the linkcatcher to do what I aim to, and not entirely sure how $:/snippets/paletteswitcher is doing what it does.

This might be above my skill level as of right now, I might need to revisit this after tinkering with the link catcher widget

I will provide the full instreuctions shortly if no one else does.

In the tiddler change the link catcher line to; <$linkcatcher to="$:/palette" actions=<<on-pallet-switch>> >

Create a tiddler tagged $:/tags/Macro containing

\define on-pallet-switch()
<$list filter="[all[current]match[$:/palettes/Blanca]]" variable=~ emptyMessage=<<off-pallet-switch>> >
   <$fieldmangler tiddler=tiddlername>
      <$action-sendmessage $message="tm-add-tag" $param="$:/tags/Macro"/>
   </$fieldmangler>
</$list>
\end
\define off-pallet-switch()
   <$fieldmangler tiddler=tiddlername>
      <$action-sendmessage $message="tm-remove-tag" $param="$:/tags/Macro"/>
   </$fieldmangler>
\end
  • Change tiddler name to the one you want to toggle $:/tags/Macro on.
    • here we set the target tiddler using the fieldmangler widget which is needed any way for tm-remove-tag and tm-add-tag

Testing it, its not working yet. updated above macro

  • Currently I can get it to add but not remove the tag or remove not add the tag, but I need to comeback later

Instead: Enclose the macro code in a listwidget that checks if the selected palette is the Dark one.

You should never use $:/core/ prefix for your own tiddlers.

It’s extremely confusing and error prone for everyone, who does not know that it is a custom tiddler. It looks like a core tiddler.

If there is a bug users may think there is a bug in the core, which is not the case.

1 Like

Tony had a good idea.

  • Change the linkcatcher line from $:/snippets/paletteswitcher to
  • <$linkcatcher to="$:/palette" actions=<<onPalleteSwitch>> >
  • create a tiddler eg: custom-palette-actions with a
    • field code-body: yes
    • tag: $:/tags/Macro
    • and the following content
title: custom-palette-actions
tags: $:/tags/Macro
code-body: yes

\define paletteTitle() $:/palettes/SpartanNight
\define macrosTitle() your macro tiddler not core

\procedure onPalleteSwitch()
<$list filter="[{$:/palette}match<paletteTitle>]">
	<$action-listops $tiddler=<<macrosTitle>> $field="tags" $subfilter="[[$:/tags/Macro]]"/>
</$list>
<$list filter="[{$:/palette}!match<paletteTitle>]">
	<$action-listops $tiddler=<<macrosTitle>> $field="tags" $subfilter="-[[$:/tags/Macro]]"/>
</$list>
\end
  • rename your macro tiddler without a “core” in it
  • Adjust the \define macrosTitle() in the example above to your new name
  • Adjust the \define paletteTitle() to your palette name

That should do the trick. The following JSON file contains 3 tiddlers

custom-palette-actions … The macros to add and remove the $:/tags/Macro tag
your macro tiddler not core … Your macors with a new name
$:/snippets/paletteswitcher … The modified core snippet

custom-palette-switcher-actions.json (2.6 KB)

have fun!
mario

Just to be sure

The first <$reveal ... line in the macros tiddler of your OP code is error prone.
Global macros are not intended to be used that way.

The core \import mechanism may fail if global macros start with arbitrary wikitext code instead of \procedure, \function or \define at the beginning

-m

Ah oops ok, I just suffixed it with oled for temporary titling, ive been using $:/wiki/… for most of my tweaks, I’ll make sure to change it when I get back to my computer, as of right now I’m phone bound while waiting for triple A :sweat_smile:

It may be awhile before I’m able to try this code snippet, i knew that the reveal widget wouldnt likely work, but wasn’t quite sure of any other methods for dynamically showing and removing tiddlers without* manual use, like buttons using actions, so that one’s on me, but I’m glad this is indeed possible without the use of something like custom javascript or anything like that.

Edit:

OK, so that works perfectly! Sadly I made a bit of a hiccup with my changes to the tag macro change, but otherwise this is perfect, thank you everybody :grinning_face_with_smiling_eyes:

Small note, I did find out the tag being applied was $:/tag/Macro, which should be $:/tags/Macro, for anyone trying this and having trouble, I forgot to point that out, I just fixed it when I saw it :sweat_smile:

That was intentional to test your participation :wink: – Just joking.
I did update the code and the JSON attachment accordingly. So it should work with the right tags now

I try to when I can, I still have plenty to learn though, mind if I ask how the linkcatcher widget functions? Is it like a button where if any link that matches is clicked on it activates?

I noticed it works both for the palette switcher sidebar button and the palette selector in the control panel

If you click a link in TW the core emits a tm-navigate message with a “navigate to tiddler” information. This and only this message is “intercepted” by the linkcatcher widget.

The linkcatcher has an actions parameter, which can be used to do something user specific, instead sending the message to the navigator widget. That’s the version we use here.

There are several other possibilities. Eg: the to parameter writes the “navigate to tiddler” title into a tiddler specified with the to-parameter. That’s the default action that can be seen in the $:/snippets/paletteswitcher

So if actions and to are defined it will do both. That’s what we did with our code as described in my first post.

That’s because the 2 sections of the UI use the same code snippet. In the UI we try to re-use the code for the same actions.

hope that helps
-mario