Is there a way to implement "tm-close-tiddler" globally?

I would like to implement tm-close-tiddler so when I open one tiddler, the current tiddler closes. Essentially, I am trying to implement my own version of Single Tiddler Mode.

So far this is the code I am using:

<$button>
<$action-sendmessage $message="tm-close-tiddler"/>
<$action-navigate $to="tiddler-title"/>
[[tiddler-title]]
</$button>

While I am able to implement them on all my links, I still have the problem with links opening from searches or from the sidebar.

This?

https://tiddlywiki.com/#WidgetMessage%3A%20tm-close-all-tiddlers

Unfortunately, that doesn’t work the way I need it to work. I need something that can be invoked from searches and sidebar.

@RedAsset this requirement of your sounds a lot like ;

Contol Panel > Appearance > Story View > Zoomin

However you could use close all, or close other tiddlers rather than close tiddler.

WidgetMessage: tm-close-other-tiddlers

WidgetMessage: tm-close-all-tiddlers

Zoomin may display a single tiddler at a time, but it doesn’t close them. My project requires that when I return to the tiddler it returns to the original unopen state. I have been playing around with tm-close-other-tiddlers and tm-close-all-tiddlers, but so far no luck.

I have tried something like this in the $:/core/ui/AdvancedSearch/Standard tiddler:

\define close(msg)
<$action-sendmessage $message="tm-close-tiddler"/>
or
<$action-sendmessage $message="tm-close-all-tiddlers"/>
or
<$action-sendmessage $message="tm-close-other-tiddlers"/>
\end

<$messagecatcher actions=<<close>>>

...

</$messagecatcher>

At this point, I am wondering if there there is a way to trigger an action when clicking on a link.

@RedAsset I am confident what you want is possible. There may be an issue about where the action is listed eg in button widget params “message=tm-message” within a macro in actions=<<your-actions>> or in the body of the button <$action-sendmessage message=..

This is already occurring in the core where links generate the <$action-navigate $to="tiddlername"/> or as is often the case as within the list widget story and history mechanism. This means the message catcher can catch tm-navigate from regular links.

It is also possible to wrap the listing of links with the MessageCatcherWidget and trap tm-navigate and add the additional action.

I am aware of all this, but my time is limited so I am providing hints and references, perhaps others will give full solutions.

I am trying to wrap the MessageCatcherWidget around all the links generated in the search results ($:/core/ui/AdvancedSearch/Standard). Additionally, I would do the same for all the links generated in the tabs in the sidebar. I figure once I figure out how to do one, the rest will fall into place. I realize that your time is limited, but I do appreciate all the help I can get.

I just did a quick proof of concept, using a https://tiddlywiki.com/#Alternative%20page%20layouts

In side a custom clone of $:/core/ui/PageTemplate I wrapped it in a message catcher widget, this example puts a message into the developer console, unfortunately it did not work.

I then did a minimal example that wraps the content of the contents tab, This works, on tiddlywiki.com, but I wont share it as below has better;

You can alter what occurs in the caught-actions and current tiddler is available but you may need to pass other variables if needed, however the console suggests most are available.

We then need to find where to wrap any list of links to capture navigation from them and wrap that. This package edits $:/core/ui/PageTemplate/sidebar and seems to capture any link in the sidebar.

sidebar-message-capture.json (1.1 KB)

So back to your @RedAsset problem. Here you may need to close all and then navigate.

With my attempt I could no longer open any tiddler, except I had this installed edit-recent.json (1.9 KB) which allowed me to click to edit directly.

Other combinations I am getting Internal JavaScript Error on navigate;

  • The following actions seem to cause the problem.
<$action-sendmessage $message="tm-close-tiddler"/>
<$action-sendmessage $message="tm-close-all-tiddlers"/>
<$action-sendmessage $message="tm-close-other-tiddlers"/>

Testing suggests it is not working from the search drop down yet.

I think I found something that might work.
I have modified tiddler $:/core/ui/ListItemTemplate from this:

<div class="tc-menu-list-item">
<$link />
</div>

To this:

\define link()
<$link />
\end

<div class="tc-menu-list-item">
<$button>
<$action-sendmessage $message="tm-close-all-tiddlers"/>
<$action-navigate $to=<<link>>/>
/* needs link text */
</$button>
</div>

This will navigate to a missing tiddler called: <$link />, but this does close all tiddlers. I just need to find away to convert that <$link /> into text.

Ah, $:/core/ui/ListItemTemplate may be what you want but many areas of tiddlywiki use that so be prepared to “brick” your wiki.

Perhaps <$action-navigate $to=<<currentTiddler>>/> will work, so no need for the macro link.

That worked. I just had to add <<currentTiddler>> after <$action-navigate $to=<<currentTiddler>>/>. Now looks like this:

<div class="tc-menu-list-item">
<$button>
<$action-sendmessage $message="tm-close-all-tiddlers"/>
<$action-navigate $to=<<currentTiddler>>/>
<<currentTiddler>>
</$button>
</div>

Thank you so much for helping with this solution. It’s not bricking it.

Although, “bricking” is a new term for me. If means what I think it means, I have bricked and unbricked it by going into Notepad++.

Thanks again!

Your welcome.

Bricked means turn it into a brick. Bricks can’t do anything except sit there.

Just check if there are other consequences of this change. We do try and avoid changing core tiddlers because they may be missed during upgrade, but we do what we need to do.

@RedAsset: Check out this discussion for ways to execute actions on any navigation clicks, either from links, searches, the “Recent” tab or everywhere else:
https://talk.tiddlywiki.org/t/executing-actions-on-navigation-clicks/2530
Here, the goal was to switch to a certain sidebar tab with every navigation event, but it might as well be used to close the previous tiddler, using the code you already have.
This way you’d only need to change your wiki in a single place instead of modifying links, wrapping search results and so forth. This will be helpful when maintaining the code or tweaking the behavior.
Have a nice day
Yaisog

1 Like

I would recommend creating an alternate page layout that has custom handling for the tm-navigate widget message using the $messagecatcher widget, for a more reliable solution with less tweaking of the core code needed.

Every time navigation occurs to a tiddler, you want to replace the storylist instead of updating it.

Example:

\whitespace trim
\define containerClasses()
tc-page-container tc-page-view-$(storyviewTitle)$ tc-language-$(languageTitle)$
\end
\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]
+\define navigate-actions()
+<$action-setfield $tiddler=<<tv-story-list>> list={{{ [<event-navigateTo>format:titlelist[]] }}}/>
+\end

<$vars
	tv-config-toolbar-icons={{$:/config/Toolbar/Icons}}
	tv-config-toolbar-text={{$:/config/Toolbar/Text}}
	tv-config-toolbar-class={{$:/config/Toolbar/ButtonClass}}
	tv-enable-drag-and-drop={{$:/config/DragAndDrop/Enable}}
	tv-show-missing-links={{$:/config/MissingLinks}}
	storyviewTitle={{$:/view}}
	languageTitle={{{ [{$:/language}get[name]] }}}>

<div class=<<containerClasses>>>

<$navigator story="$:/StoryList" history="$:/HistoryList" openLinkFromInsideRiver={{$:/config/Navigation/openLinkFromInsideRiver}} openLinkFromOutsideRiver={{$:/config/Navigation/openLinkFromOutsideRiver}} relinkOnRename={{$:/config/RelinkOnRename}}>
+<$messagecatcher $tm-navigate=<<navigate-actions>> >

<$dropzone enable=<<tv-enable-drag-and-drop>>>

<$list filter="[all[shadows+tiddlers]tag[$:/tags/PageTemplate]!has[draft.of]]" variable="listItem">

<$transclude tiddler=<<listItem>>/>

</$list>

</$dropzone>

+</$messagecatcher>
</$navigator>

</div>

</$vars>

This worked on a fresh empty.html, but bricked my version. Probably because of all the custom CSS I put into it.

The concept should be transferrable to your customized wiki. If you implement this as an alternative layout instead of tweaking the default Page Template, you can use the layout switcher to resort to the default page template if the customisations go awry, thus avoiding the possibility of bricking the wiki.

Note that you can also wrap custom CSS in wikitext such that it is only active when a particular layout is active.

1 Like

I had to add some code for anything that created a new tiddler because it would just overlay the new tiddler over the current tiddler.

\define get-tags() $(textFieldTags)$ $(tagsFieldTags)$
<$vars textFieldTags={{$:/config/NewTiddler/Tags}} tagsFieldTags={{$:/config/NewTiddler/Tags!!tags}}>
+<$action-sendmessage $message="tm-close-all-tiddlers"/>
<$action-sendmessage $message="tm-new-tiddler" tags=<<get-tags>>/>
</$vars>

Here is a different quick take on single tiddler mode that also repurposes the Open tab in the sidebar: TiddlyWiki — a non-linear personal web notebook

The new layout consists of the following tiddlers:

  • $:/sq/ui/SingleTiddler/PageTemplate
  • $:/sq/ui/SingleTiddler/PageTemplate/story
  • $:/core/ui/SideBar/Open

I imported those. Works great. It’s not navigating to a new tiddler when I create one.

1 Like

a button to create a new tiddler, additionally containing

successfully opens the new draft tiddler, which is great for my usage, thanks @RedAsset and @saqimtiaz !

the page toolbar + button (control panel|appearances|toolbars|page toolbar) creates the draft (you can see it in history) but does not swap to it, possibly because it doesn’t close existing tiddlers first? maybe there is a solution without changing the core – e.g. adding a new toolbar button? https://tiddlywiki.com/#Creating%20new%20toolbar%20buttons