How do I make a clone button which creates tiddlers silently?

243 views
Skip to first unread message

Måns

unread,
May 5, 2015, 4:08:33 AM5/5/15
to tiddl...@googlegroups.com
Hi TwWizards

How do I make a clone button which creates tiddlers silently?

As I understand I have to use the action-setfield widget and not the tm-new-tiddler widget message to be able to generate/edit tiddlers without having to open them....
I'd like to be able to do both:

1) Silently create tiddlers with new titles based on the first (current) tiddler's title (not a clone)
2) Silently create multiple clones of the current tiddler with new titles based on the first (current) tiddler's title.

Is this already possible?

Cheers Måns Mårtensson

Mat

unread,
May 5, 2015, 10:23:46 AM5/5/15
to tiddl...@googlegroups.com
Just a chime in that I'd like to know too (for the FastNewTiddler project)

<:-)

c pa

unread,
May 5, 2015, 12:56:56 PM5/5/15
to tiddl...@googlegroups.com
This works:

\define setfield(tiddlerName,templateName,fieldName)
    <$set name="fieldValue" value={{$templateName$!!$fieldName$}} >
        <$action-setfield $tiddler="$tiddlerName$" $field="$fieldName$" $value=<<fieldValue>> />
    </$set>
\end
\define createSilentTarget(tiddlerName,templateName,buttonName)
    <!-- This macro displays a button that clones a template
           All fields and content are copied from the template silently
    -->
   <$button> $buttonName$
        <$action-setfield $tiddler="$tiddlerName$" $field="title" $value="$tiddlerName$" />
        <$list filter="[[$templateName$]fields[]] -created -modified -title" >
            <<currentTiddler>><br/>
            <$macrocall $name="setfield"
                tiddlerName="$tiddlerName$"
                templateName="$templateName$"
                fieldName=<<currentTiddler>>
            />
        </$list>
    </$button>
\end

<$macrocall $name="createSilentTarget"
    tiddlerName="MyNewTiddler"
    templateName="testTemplate"
    buttonName="testButton" />
[[MyNewTiddler]]

Måns

unread,
May 6, 2015, 1:13:27 PM5/6/15
to tiddl...@googlegroups.com
Hi c pa

Thank you very much - however I can't see how your code will let me create a new tiddler title every time I click the testButton?

>1) Silently create tiddlers with new titles based on the first (current) tiddler's title (not a clone)
>2) Silently create multiple clones of the current tiddler with new titles based on the first (current) tiddler's title.

I'm aware of (some of) the capabilities of the action-setfield widget > I do not know how to make it create a new title eg: [[MyNewTiddler 1]] if [[MyNewTiddler]] already exists.

This happens automagically with the clone tiddler button - it uses a tm-newtidder widget message, not the action-setfield widget....
Is there some (hidden magic) scripting in the tm-newtiddler widget that can't be used with the action-setfield widget?


Cheers Måns Mårtensson

Danielo Rodríguez

unread,
May 6, 2015, 2:51:29 PM5/6/15
to tiddl...@googlegroups.com
I made the same question some time ago. I ended up creating a small javascript macro for it and a pull request to the core. The pull request was to allow prefixes like zeroes and spaces. I can share that macro if you are interested

Danielo Rodríguez

unread,
May 6, 2015, 2:52:19 PM5/6/15
to tiddl...@googlegroups.com
Just to be clear, the only thing the macro does is returning a new unique name, if I remember well my own ideas...

Måns

unread,
May 6, 2015, 3:29:28 PM5/6/15
to tiddl...@googlegroups.com
Hi Danielo

Yes please :-)

Do you think I can combine it with  an action-setfield widget message to silently create a new tiddler with a unique title based on the current tiddler title every time I click the button? eg. New tiddler 1, New tiddler 2 etc ...

Cheers Måns Mårtensson

Matabele

unread,
May 6, 2015, 10:46:51 PM5/6/15
to tiddl...@googlegroups.com
Hi Mans

Perhaps this meets your needs?

regards

Måns

unread,
May 7, 2015, 2:44:13 AM5/7/15
to tiddl...@googlegroups.com
Hi Matabele

Great :-) Thank you very much!!

 EDIT: Sorry... I was to quick ... It didn't suppress opening the clone for editing anyway....

I simply pasted the code from the clone button into your maketid widget - and it just works :-)

<$maketid edit="no"><$button message="tm-new-tiddler" param=<<currentTiddler>> tooltip={{$:/language/Buttons/Clone/Hint}} aria-label={{$:/language/Buttons/Clone/Caption}} class=<<tv-config-toolbar-class>>>
<$list filter="[<tv-config-toolbar-icons>prefix[yes]]">
{{$:/core/images/clone-button}}
</$list>
<$list filter="[<tv-config-toolbar-text>prefix[yes]]">
<span class="tc-btn-text"><$text text={{$:/language/Buttons/Clone/Caption}}/></span>
</$list></$button></$maketid>

To me it seems that the parameter you've added:
>edit="yes" (default) opens the tiddler for editing – edit="show" navigates to but does not open the tiddler – edit="no" suppresses navigation

should be implemented as an option for the tm-new-tiddler widget @Jeremy?

Cheers Måns Mårtensson

EDIT: Sorry... I was to quick ... It didn't suppress opening the clone for editing anyway....

Måns

unread,
May 7, 2015, 3:31:27 AM5/7/15
to tiddl...@googlegroups.com
 EDIT: Sorry... I was to quick ... It didn't suppress opening the clone for editing anyway....

Danielo Rodríguez

unread,
May 7, 2015, 3:32:38 AM5/7/15
to tiddl...@googlegroups.com
Hello Mans,

If you have adopted Matabelle's solution I think you should stick to it. My macro is just a "patch"


El jueves, 7 de mayo de 2015, 8:44:13 (UTC+2), Måns escribió:
Hi Matabele

Great :-) Thank you very much!!

I simply pasted the code from the clone button into your maketid widget - and it just works :-)

<$maketid edit="no"><$button message="tm-new-tiddler" param=<<currentTiddler>> tooltip={{$:/language/Buttons/Clone/Hint}} aria-label={{$:/language/Buttons/Clone/Caption}} class=<<tv-config-toolbar-class>>>
<$list filter="[<tv-config-toolbar-icons>prefix[yes]]">
{{$:/core/images/clone-button}}
</$list>
<$list filter="[<tv-config-toolbar-text>prefix[yes]]">
<span class="tc-btn-text"><$text text={{$:/language/Buttons/Clone/Caption}}/></span>
</$list></$button></$maketid>

To me it seems that the parameter you've added:
>edit="yes" (default) opens the tiddler for editing – edit="show" navigates to but does not open the tiddler – edit="no" suppresses navigation

should be implemented as an option for the tm-new-tiddler widget @Jeremy?

Cheers Måns Mårtensson


Måns

unread,
May 7, 2015, 3:42:14 AM5/7/15
to tiddl...@googlegroups.com
Hi Matabele

I edited your MakeTid widget:
Changed all "tw-" labels to "tm-labels" .... Now it seems to almost work as I hoped....
I still have some problems with new titles (it creates tiddlers titled "NewTiddler" (not current tiddler title) and adds 1, 2, 3 to it...


Cheers Måns Mårtensson

Måns

unread,
May 7, 2015, 4:03:04 AM5/7/15
to tiddl...@googlegroups.com
Hi again

Now I made it work :-)


The trick was to "inject" the current tiddler title - and tags into the
maketid widget's attribute values and set the current tiddler as the template...

Cheers Måns Mårtensson

Edit: It's quite a mess to look at atm - sorry - I will clean it up when I get a little more time...

Måns

unread,
May 7, 2015, 4:49:46 AM5/7/15
to tiddl...@googlegroups.com
Tip: Scroll to the top of the story river to see it in action... ("skjul" means "hide", "vis" means "show" - "ny" means "new"...

Måns

unread,
May 7, 2015, 4:53:11 AM5/7/15
to tiddl...@googlegroups.com
Thanks Danielo :-)

Matabele

unread,
May 7, 2015, 8:13:05 AM5/7/15
to tiddl...@googlegroups.com
Hi Mans

I will get around to updating my widgets for the more recent versions of TW sometime soon -- they were built for the old version and will need various code tweaks. Don't know why the $maketid widget isn't picking up the title specified in the parameters -- it was designed to do so.

regards

Måns

unread,
May 7, 2015, 9:36:40 AM5/7/15
to tiddl...@googlegroups.com
Hi Matabele

 
Don't know why the $maketid widget isn't picking up the title specified in the parameters -- it was designed to do so.

It did - it was just me. I tried to use your maketid widget with no attributes set and  the core clone button which have: "param=<<currenTiddler>>" and hoped that it would work like that... Of course it didn't :-)

Now that I use maketid's attributes it works exactly how I hoped it would :-)

Thanks a lot!

Here's a cleaner version of what I did: http://kinabog.tiddlyspot.com/

Edit: The macro in which I use the maketid widget is: 

Cheers Måns Mårtensson
Reply all
Reply to author
Forward
0 new messages