How to add a default name/prefix for image drag and dropped into a tiddler in edit mode?

Hi everyone ! I’m in the process to learn a software and to that end, I’m taking a lot of screenshots that I copy/paste into my tiddlers while I’m editing. The photos are then automatically sent to github with the file upload plugin.

I dont want these screenshot to clutter the search so I prefix them with $:/screenshot/. How can I make this the default file name or prefix for new picture, instead of image.png ? I did an advanced search ([all[tiddlers+shadows]search:*[image.png]]) to see if it was defined somewhere in the core but I couldn’t find anything.

If memory serves (I remember it did once !) that name is actually coming from the browser. So you’d have to find the part of the import logic that renames incoming items and tweak/override that.

4 Likes

Mh I tried to modify $:/core/ui/EditorToolbar/file-import because it looks like this part could allow me to change the name of the image tiddler after the fact, but it didn’t work. Here’s what I did:

...

\define replacement-text-image() [img[$:/screenshot/$title$]]

\define replacement-text-file() [[$title$]]

\define add-prefix-img()
<$action-sendmessage $message="tm-rename-tiddler" from="$title$" to="$:/screenshot/$(title)$" />
\end

\define postImportActions()
\whitespace trim
<$list filter="[<importTitle>links[]] :reduce[get[type]prefix[image]then<replacement-text-image>else<replacement-text-file>search-replace[$title$],<currentTiddler>addprefix<accumulator>]" variable="imageTitle">
<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="insert-text"
	text=<<imageTitle>>
/>
</$list>
<<add-prefix-img>>
<<closePopupActions>>
\end

...

The link that is inserted get prefixed, but the image tiddler doesnt get renamed, and I dont understand why …

1 Like

Glad you were able to find where the action happens! The following changes will quietly add the $:/screen prefix to the name. The question is whether you also want them to change the entire name at the same time. The main thing to note is that imageTitle after the reduce contains a string that represents a mix and match of titles or wikitext image references.

\define replacement-text-image() [img[$:/screenshot/$title$]]

\define replacement-text-file() [[$title$]]

\define postImportActions()
\whitespace trim

<$list filter="[<importTitle>links[]] :filter[get[type]prefix[image]]" variable="imageTitle">
<$let 
newTitle={{{[<imageTitle>addprefix[$:/screenshot/]]}}} 
>
<$action-sendmessage $message="tm-rename-tiddler" from=<<imageTitle>> to=<<newTitle>> />
</$let>

</$list>

<$list filter="[<importTitle>links[]] :reduce[get[type]prefix[image]then<replacement-text-image>else<replacement-text-file>search-replace[$title$],<currentTiddler>addprefix<accumulator>]" variable="imageTitle">

<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="insert-text"
	text=<<imageTitle>>
/>
</$list>
<<closePopupActions>>
\end

I think my bundle-plugin can help here. It has a possibility to rename incoming screenshot tiddlers.

The ControlPanel setting looks like this.

So if an “image.png” is copy pasted, it will be automatically renamed using the import template. … So it should be possible to do what you want.

BUT

I didn’t test it in combination with the “file upload plugin” … So that’s for you to find out.

2 Likes

This worked perfectly, thanks a lot ! I added a text input to the dialog to be able to specify a prefix + toggle it on and off :

Result:

image

$ _core_ui_EditorToolbar_file-import.json (2.2 KB)

Very nice, if it wasn’t for @Mark_S answer’s I would have chosen this as the solution ! I need to try this out. Thanks for your help ! :smiley:

1 Like

Since there doesn’t seem to be a bundler topic thread, I’ll mention here a thought. It would be useful if there was a way to open all tiddlers in a bundle. In this way the bundle becomes a story list manager as well as managing groups of exports.

I made a template that allows opening tiddlers by bundles, either regular or filtered:

<$list filter="[all[current]has[filter]suffix[.bundle]]"><$button>Make story from filter
<$set filter={{{[{!!filter}]}}} name="output">
<$action-setfield $tiddler="$:/StoryList" $field="list" $value=<<output>> />
</$set>
</$button>
</$list>

<$list filter="[all[current]!has[filter]suffix[.bundle]]"><$button>Make story
<$vars lf="""
"""
>
<$action-setfield $tiddler="$:/StoryList" $field="list" $value={{{[<currentTiddler>get[text]split<lf>]+[join[ ]]}}} />
</$vars>
</$button>
</$list>
1 Like