Replace the save button with export tiddler function

Hello TW-friends,

here a question only due to the fact that I am a lazy guy in want to have some comfortability.

Is there a chance to replace the function behind the save button with the function export tiddler as tid text file?

I am fine with ctrl-s to save the complete wiki :grinning:

Stefan

.tid can only export 1 tiddler. Do you mean tiddler → More → export tiddler → TID text file?

1 Like

Hi @pmario ,

right! This it is :slight_smile: I want.

Stefan

Hi @pmario,

is it right to change the $:/core/ui/Buttons/save-wiki tiddler?
I am not sure what I need to change there or is it better to find another solution?

Thx in advance

Nope. Do not mess with that one. If you need to experiment with it, then clone it and use the clone.

But I’m still not sure, what you really want.

  • Do you want to save 1 tiddler into a .tid file - or
  • Do you want to save all tiddlers into many .tid files – Because that’s not possible out of the box
  • Would it help to save all tiddlers into a single JSON-file?

If you want to save many .tid files you will need to use the core JSZip-plugin

Hi @pmario,

sorry not to be cristal clear from beginning on.
I want to save only the one tiddler what is the current one. The same function you marked in your screen shot.

Stefan

To create a button in the right sidebar that knows about the active tiddler is not so easy out of the box.

But you can show the export button in the tiddler edit toolbar – for fast access

  1. open the “more” chevron
  2. select “info”
  3. select the “Tools” tab
  4. check teh “export tiddler” checkbox
  5. the “export” button there gives you fast access and the exact tiddler

Hi @pmario,

thank you for the workaround.

The task to have the current tiddler information was solved a few weeks ago and
[<tv-history-list>get[current-tiddler]] is a good working solution to get the information.

With some test in the $:/core/ui/Buttons/save-wiki tiddler I was able to integrate some special functions for my use case, but I cannot find the information how to call the export tiddler | TID text file function. :roll_eyes:

Stefan

OK. It’s tricky to find a solution with maximum code reuse and minimum effort, to do the right things.

Generic page control buttons need several mandatory elements.

  • caption … which is shown under rigth sidebar → Tools tab
  • description … which is also shown in the Tools tab

In the text area there needs to be a button, with an icon. I did use $:/core/images/spiral in my explanation


The tiddler toolbar exporters are tagged: $:/tags/Exporter
The one which creates the single .tid file is: $:/core/templates/exporters/TidFileSo we should reuse it.

\import [subfilter{$:/core/config/GlobalImportFilter}]
\define renderContent()
{{{ $(exportFilter)$ +[limit[1]] ||$:/core/templates/tid-tiddler}}}
\end
<<renderContent>>

It is able to create the “rendered text”, that needs to be written into the exported file.

It needs some variables

  • exportFilter … which in our case is: [<tv-history-list>get[current-tiddler]]

And indirectly it also needs: (more info down below)

  • tv-history-list … because it is used in the exportFilter (this one did cost me more than an hour :frowning:

The message to save the tiddler is tm-download-file

  • It needs param … Title of a tiddler to use as a template for the new tiddler
    • used with action-sendmessage it will change to $param
  • In our case that’s … $:/core/templates/exporters/TidFile

To activate the message we need a button-widget and the action-sendmessage widget

I did use the Home-button as a template for the “boilerplate” needed for sidebar buttons. I stripped it down and then implemented the stuff we need. The new code is.

title: $:/_custom/ui/Buttons/save-current-tiddler
tags: $:/tags/PageControls
caption: {{$:/core/images/spiral}} Save current-tiddler
description: Save HistoryList!!current-tiddler

\whitespace trim
\procedure actions()
<$action-sendmessage $message="tm-download-file" 
	$param="$:/core/templates/exporters/TidFile"
	exportFilter="[<tv-history-list>get[current-tiddler]]"
	tv-history-list=<<tv-history-list>>
	filename={{{ [<tv-history-list>get[current-tiddler]] ".tid" +[join[]] }}}
/>
\end
<$button actions=<<actions>> tooltip="Save current-tiddler" class=<<tv-config-toolbar-class>> >
	<$list filter="[<tv-config-toolbar-icons>match[yes]]">
		{{$:/core/images/spiral}}
	</$list>
	<$list filter="[<tv-config-toolbar-text>match[yes]]">
		<span class="tc-btn-text">
			<$text text="Save current-tiddler"/>
		</span>
	</$list>
</$button>

The button-widget

  • The <$list filter="tv-config-*"> lists are there to be able to configure the toolbar button
  • For best practice I use actions=<<actions>> for button activated actions.

Procedure actions()

It uses the

  • <$action-sendmessage $message="tm-download-file" … see info above.
  • $param="$:/core/templates/exporters/TidFile" … template to create the .tid file text
  • exportFilter="[<tv-history-list>get[current-tiddler]]" … exportFilter variable needed in template / $param
  • tv-history-list=<<tv-history-list>> … also variable needed in template
  • filename={{{ [<tv-history-list>get[current-tiddler]] ".tid" +[join[]] }}} … defines the filename needed by tm-download-file

For your convenience here is the button, that is well integrated into the right sidebar.

$___custom_ui_Buttons_save-current-tiddler.json (976 Bytes)

hope that helps
-mario

PS some screenshots

PPS: Please test carefully, if it really exports everything!

Hi @pmario,

thank you for all the effort.
Maybe you already know it, but all the functions I implement are aimed at creating a wiki where authors cannot publish their contributions directly. The workflow provides that the contributions must first be sent to an editorial office and after review are then integrated into the wiki and published. For technical reasons I have to use the “all in one file” TiddlyWiki version.

I have implemented your solution as follows and the enthusiasm of the authors is great.
I used the “Save Wiki” button (the original function is only commented) and only the fact that the button does not change is a problem that has not yet been solved.
I thought if I added this

<$set name="tv-config-toolbar-icons" value="no"/>
<$set name="tv-config-toolbar-text" value="no"/>

to the button it would work but unfortunately the save button always stays red and doesn’t change. Do you have an idea how I can change this so that the save button changes to green even if only one tiddler has been exported? Or maybe another idea how to solve it?

Thank you very much so far.
Here is the new “Save Wiki” button

caption: {{$:/core/images/save-button-dynamic}} {{$:/language/Buttons/ExportTiddler/Caption}}
created: 20240823084111508
creator: Redaktionsteam
description: {{$:/language/Buttons/ExportTiddler/Hint}}
modified: 20240823095821066
modifier: cISMS Team
tags: $:/tags/PageControls
title: $:/core/ui/Buttons/save-wiki

\whitespace trim
<$button tooltip={{$:/language/Buttons/ExportTiddler/Hint}} aria-label={{$:/language/Buttons/ExportTiddler/Caption}} class=<<tv-config-toolbar-class>>>

<$action-sendmessage $message="tm-download-file" 
	$param="$:/core/templates/exporters/TidFile"
	exportFilter="[<tv-history-list>get[current-tiddler]]"
	tv-history-list=<<tv-history-list>>
	filename={{{ [<tv-history-list>get[current-tiddler]] ".tid" +[join[]] }}}
/>

<!--
<$wikify name="site-title" text={{$:/config/SaveWikiButton/Filename}}>
<$action-sendmessage $message="tm-save-wiki" $param={{$:/config/SaveWikiButton/Template}} filename=<<site-title>>/>
</$wikify>
-->

<span class="tc-dirty-indicator">
<$list filter="[<tv-config-toolbar-icons>match[yes]]">
{{$:/core/images/save-button-dynamic}}
</$list>
<$list filter="[<tv-config-toolbar-text>match[yes]]">
<span class="tc-btn-text">
<$text text={{$:/language/Buttons/ExportTiddler/Caption}}/>
</span>
</$list>
</span>
</$button>

The <span class="tc-dirty-indicator"> is responsible for the colour change of the original TW save button. This class will be automatically set or reset by the core, after the whole wiki will be saved.

There is no other way to reset the “dirty” state.

You could save both – The .tid file and the .html file. So users will get 2 dialogues. In this case it is guaranteed, that the changed tiddler actually is saved as a “backup” if you will.

So if a user happens to “select” the wrong tiddler for export, they may be able to save the “right” one by loading the “backup”

If the whole wiki is saved the “dirty” status goes away

$__core_ui_Buttons_save-wiki.tid (1.2 KB)

have fun!
mario


These variables are not responsible for the colour change. They are only there to show the icon or / and the button text. That’s a setting in the ControlPanel → Settings tab. You do not need them for your usecase.

Hi @pmario,

excellent!!!
I will open a new question how to get a dynamic button implemented.

Thank you so much
Stefan