Hi,
I made some progress.
I wrote a macro that creates a tiddler from a skeleton (code borrowed from
Stephan Hradek) :
exports.name = "testMacro2";
exports.params = [
{ name: "title" }
];
/*
Run the macro
*/
exports.run = function(title) {
var skeleton = $tw.wiki.getTiddlerAsJson(title);
// return "skeleton : "+skeleton;
var skeletonClone =
JSON.parse(this.substituteVariableReferences(skeleton));
var basetitle = skeletonClone.title;
var title = basetitle;
for(var t=1; this.wiki.tiddlerExists(title); t++) {
title = basetitle + " " + t;
}
skeletonClone.title = title;
var created = this.wiki.getCreationFields();
for(var creationField in created) {
skeletonClone[creationField] = created[creationField];
}
var modified = this.wiki.getModificationFields();
for(var modificationField in modified) {
skeletonClone[modificationField] = modified[modificationField];
}
this.wiki.addTiddler(skeletonClone);
return "fin";
};
It works fine.
Then when I try to modify navigator.js :
First I create a new message :
...
{type: "tw-new-tiddler", handler: "handleNewTiddlerEvent"},
{type: "tw-new-tiddler-from-skeleton", handler:
"handleNewTiddlerFromSkeletonEvent"},
{type: "tw-import-tiddlers", handler: "handleImportTiddlersEvent"}
...
Then I write the handler with the same code as the macro except :
- the first line :
var skeleton = this.wiki.getTiddlerAsJson(event.param);
- and the end :
return false;
It works as it creates a new tiddler with the right name and the text, but
it doesn't substitute the variables.
I use it as :
<$set name="a" value="tag1">
<$set name="b" value="World !">
<$set name="c" value="fieldvalue">
<$button message="tw-new-tiddler-from-skeleton"
param="skel">bouton</$button>
</$set></$set></$set>
Where "skel" is a skeleton tiddler with $(a)$ as tag, $(b)$ in the text,
and $(c)$ as a field value.
What am I missing ?
Thanks
FrD
Le samedi 19 avril 2014 16:48:36 UTC+2, FrD a écrit :
>
> Hi,
>
> In a project of mine, I'd like to use the NewtiddlerWidget from Stephan
> Hradek (http://tiddlystuff.tiddlyspot.com/) but I'd prefer to have it
> integrated in the ButtonWidget. It would give me the ability to use the
> other attributes of the ButtonWidget.
>
> So I tried to extend the NavigatorWidget with a new message handler.
> The message could be "tw-new-tiddler-from-skeleton". I tried to write the
> handler for this message from the code of
> "NavigatorWidget.prototype.handleNewTiddlerEvent" and the code from in
> Stephan's widget.
> But to no avail ; it's above my skills for now !
>
> So I was wondering whether someone (Stephan ?) could give me a hand on
> that case.
>
> The idea is the same as Stephan's :
> having variables defined by the <$set> widget
> and inside calling <$button message="tw-new-tiddler-from-skeleton"
> param="NameOfTheSkeletonTiddler"/>
>
> Thanks in advance.
>
> FrD
>
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.