EditSectionPlugin does not create sections, where there aren't any already?!

26 views
Skip to first unread message

Måns

unread,
Aug 30, 2010, 5:23:34 AM8/30/10
to TiddlyWiki
Hi TwWizards (Eric in particular)

I'm trying to setup EditSectionsPlugin macros so I can create sections
in tiddlers.
The Plugininfo says:
"If the indicated tiddler and/or section does not yet exist, it will
be created when you press 'save'."
However I've tried this in empty tiddlers and in tiddlers where text
already exists - and it doesn't seem to work..
If I create sections with an empty line, corresponding to the
macrocalls i.e.
<<editSection TiddlerName##sectionname label tooltip>> it works -
!sectionname

!end

If I omit the empty line it doesn't...

If it isn't possible - I need a way to enter a template of sections
into multiple tiddlers textfield at once (200 tids)
I tried to figure it out with the CreateTiddlersFromCSV transclusion,
however I could not figure out how to create textfields with sections
and linebreaks...
http://www.tiddlytools.com/#EditSectionPlugin

Regards Måns Mårtensson

Måns

unread,
Aug 30, 2010, 10:51:14 AM8/30/10
to TiddlyWiki
Hi again

Can anyone explain how to paste multiline text into a lot of tiddlers
at once (it doesn't matter if it overwrites existing text)?

Regards Måns Mårtensson

Anthony Muscio

unread,
Aug 30, 2010, 7:58:38 PM8/30/10
to tiddl...@googlegroups.com
Re your first question;
I use comment plugin to paste sections into the tiddler body and then append to these with additional comments and provide an edit section if I want to edit it.

<<editSection "To Do"  "To Do">>

where
!To Do
/%todo%/

Has been placed in the tiddler using;

With  <div class='viewer' macro='tiddler CreateTaskSections'></div> used to display CreateTaskSections

!Create sections for this task
+++^40em^[Simple Task]...
<<moveablePanel>>Create a Simple Task
<<comment here  "simpleTask" "/%top%/\n!Task Details/%comment%/\n/%bottom%/">>
===
+++^40em^[Standard Task]...
<<moveablePanel>>Create Standard Task Sections To Do, Activity and Result, also - Create Top/Bottom and Center (Hidden comment) Sections
<<comment here  "standardTask" "/%top%/\n!To Do\n/%todo%/\n!Activity\n/%activity%/\n!Result/%result%/\n/%comment%/\n/%bottom%/">>
===
+++^40em^[Big Task]...
<<moveablePanel>>Create Standard Task Sections and include Background and Research
<<comment here  "bigTask" "/%top%/\n!To Do\n/%todo%/\n!Background\n/%background%/\n!Research\n/%research%/\n!Activity\n/%activity%/\n!Result/%result%/\n/%comment%/\n/%bottom%/">>
===
+++^40em^[Initialise for FreeForm]...
<<moveablePanel>>Create Top/Bottom and Center (Hidden comment) Sections
<<comment here  "FreeFormSections" "/%top%/\n/%comment%/\n/%bottom%/\n">>
===

These buttons will disappear once one of the above are selected. You can use Transform ''clearContent and sections'' to erase content

I need to think more about your second question but it suggests to me there is a better way to do it. I abandoned using source tiddlers for new tiddler templates and keep my tiddler content to a minimum, using the comment plugin to insert only when needed.

Anthony Muscio
LaSourceProjects.org Open Source Sustainability Projects
LaSource.com.au Sustainable Products and Business
SerendipityIdeas.com IT hints and Tips and Website hosting
Like personal Web 2.0 ? see www.tiddlywiki.com




--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To post to this group, send email to tiddl...@googlegroups.com.
To unsubscribe from this group, send email to tiddlywiki+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/tiddlywiki?hl=en.


Tobias Beer

unread,
Aug 31, 2010, 2:52:49 PM8/31/10
to TiddlyWiki
Hi Mans,

To replace the text of certain tiddlers with multiline content, you
could use the following InlineScript...

<script label="Replace Text Now!">
var t,
tids=store.getTaggedTiddlers('UPDATE'),
txt=store.getTiddlerText('NEWTEXT')||'';
if(!confirm("Really replace the contents of:\n"+
tids.map(function(t){return t.title;})))return;
for(t=0;t<tids.length;t++)
store.saveTiddler(tids[t].title,tids[t].title,txt);
</script>

..whereas TAG would be a tag these tiddlers have and TEMPLATE would be
a tiddler with multiline content.

Good luck, Tobias.

Tobias Beer

unread,
Aug 31, 2010, 2:56:24 PM8/31/10
to TiddlyWiki
You could also append text, instead of merely overwriting it by
changing...
store.saveTiddler(tids[t].title,tids[t].title,txt);

to...
store.saveTiddler(tids[t].title,tids[t].title,
store.getTiddlerText(tids[t].title)+'\n'+txt);


Tobias.

Måns

unread,
Aug 31, 2010, 3:59:20 PM8/31/10
to TiddlyWiki
Hi Tobias

This is great and effective code!! - but also *very* dangerous :-)

It deletes any tag or custom field in tiddlers!
I need those to stay unaffected.

Is it possible to narrow the replacement down *only* to affect the
textfield, leaving all other fields as they are??
That would be awesome..

Cheers Måns Mårtensson

Tobias Beer

unread,
Aug 31, 2010, 4:10:03 PM8/31/10
to TiddlyWiki
Hi again, Måns,

Mhhh... are you sure? I have just tested this on Firefox 3.6.4 and a
TW 2.5.0 ...and tags, fields even modified remained untouched! On the
other hand, modifier and modified really should change, shouldn't
they?

Tobias.

Måns

unread,
Aug 31, 2010, 4:38:33 PM8/31/10
to TiddlyWiki
Hi Tobias
> Mhhh... are you sure? I have just tested this on Firefox 3.6.4 and a
> TW 2.5.0 ...and tags, fields even modified remained untouched!
I have to use Google Chrome (ver 5.0.375.127) as ImagePath plugin
doesn't seem to work in FireFox anymore (not since 2.53 anyway) - and
images are essential for my project.
I lost all tags and custom fields from 150 tiddlers, when I used your
code (I doublecheked...) - however I was lucky it didn't have:
"autoSaveChanges();" as I'm working on a TiddlySpaceTW..
>On the
> other hand, modifier and modified really should change, shouldn't
> they?
Oh yes that would be nice!

Cheers Måns Mårtensson

Eric Shulman

unread,
Aug 31, 2010, 5:55:56 PM8/31/10
to TiddlyWiki
> ...EditSectionsPlugin...

> "If the indicated tiddler and/or section
> does not yet exist, it will be created when you press 'save'."

> However I've tried this in empty tiddlers and in
> tiddlers where text already exists -
> and it doesn't seem to work..

I've made a some significant code changes in the internals of
EditSectionPlugin, so that it correctly handles *creating a new
section*, as well more robust handling for *renaming* a section (it no
longer leaves the old section behind).

Also, the EditSection popup editor now includes a "safety check" that
asks for confirmation if there are unsaved changes and you click away
from the popup (previously, it just dismissed the popup and
*discarded* the changes without warning!)

Get the update (v1.2.1) here:
http://www.TiddlyTools.com/#EditSectionPlugin

enjoy,
-e

Message has been deleted

Tobias Beer

unread,
Aug 31, 2010, 6:21:18 PM8/31/10
to TiddlyWiki
Hi Mans,

Sorry for any inconvenience. Here's the update to the script to batch-
update the text of certain tagged tiddlers to that of some
template ...now hopefully avoiding any of the troubles you've had:

<script label="Replace Text Now!">
var t,i,
tids=store.getTaggedTiddlers('UPDATE'),
txt=store.getTiddlerText('NEWTEXT')||'';
if(!confirm("Really replace the contents of:\n"+
tids.map(function(t){return t.title;})))return;
for(i=0;i<tids.length;i++){
t=tids[i];
store.saveTiddler(
t.title,
t.title,
store.getTiddlerText(t.title)+'\n'+txt,
config.options.txtUserName,
new Date(),
t.tags,
t.fields,
t.created
);
};
</script>

Måns

unread,
Aug 31, 2010, 6:30:56 PM8/31/10
to TiddlyWiki
Hi Eric
> I've made a some significant code changes in the internals of
> EditSectionPlugin, so that it correctly handles *creating a new
> section*, as well more robust handling for *renaming* a section (it no
> longer leaves the old section behind).
>
> Also, the EditSection popup editor now includes a "safety check" that
> asks for confirmation if there are unsaved changes and you click away
> from the popup (previously, it just dismissed the popup and
> *discarded* the changes without warning!)
>
> Get the update (v1.2.1) here:
>    http://www.TiddlyTools.com/#EditSectionPlugin
That's great!! - Thank you very much -
I love this plugin, and use it all the time.

Cheers Måns Mårtensson

Måns

unread,
Sep 5, 2010, 10:18:52 AM9/5/10
to TiddlyWiki
Hi Tobias

Super!!
> Sorry for any inconvenience.
No apologies needed!! - On the contrary, I'm very happy about the fact
that you took the time needed to produce a workable script.
There *should* be some crashtesting before releasing a plugin to the
world - however: I asked for a workable script,- not a polished
plugin- you produced it - I tested it.
If I choose to test a script in an environment where it could break
something - thats my own problem.
>Here's the update to the script to batch-
> update the text of certain tagged tiddlers to that of some template .
This is a *really* great script!!
I'm using it as a transclusion $1=tag $2 for generic use in my TW.
Questions:
> <script label="Replace Text Now!"> ..."Really replace the contents of:\n"
Shouldn't it be: "Add Text Now!" and "Really add to the contents of.."
- as it adds text to text already present in affected tiddlers?
Btw:
What would the script be for replacing content with that of the chosen
template?

Thanks a lot for developing a very usefull script - I've already used
it several times to enter template text into groups of tiddlers
defined by a tag - It works like a charm!!.

Plugin challenge ;-) (wishfull dreaming) :
Vision of a batcheditTiddlerTextPlugin:
I would love to see a plugin similar to Eric's CreateTiddlersFromCsv -
with your script for adding or replacing text in already existing
tiddlers.
CreateTiddlersFromCsv has a textarea where you can write the csv code
directly -It would be nice if you could specify the template text in a
temporary textbox, like that.
CreateTiddlersFromCsv has a dropdown for choosing a sourcetiddler, a
get text button and a "create" button. In this case there should be a
choose tagged tiddlers for destination as well...

Great job Tobias - You're a real TwWizard!!

Cheers Måns Mårtensson

Måns

unread,
Sep 5, 2010, 10:38:47 AM9/5/10
to TiddlyWiki
Hi Eric
> I've made a some significant code changes in the internals ofEditSectionPlugin, so that it correctly handles *creating a new
> section*, as well more robust handling for *renaming* a section (it no
> longer leaves the old section behind).
Works perfectly!! - Thanks a lot.
> Also, the EditSection popup editor now includes a "safety check" that
> asks for confirmation if there are unsaved changes and you click away
> from the popup (previously, it just dismissed the popup and
> *discarded* the changes without warning!)
Nice security feature - shows the high quality of your plugins!!
> Get the update (v1.2.1) here:
>    http://www.TiddlyTools.com/#EditSectionPlugin

I'm having serious problems with the popup feature as it pops up in
seemingly random places all over the page....
I've installed your coretweak nr 1151 "adjust popup placement when
root element is in scrolled DIV" to make popups popup where they are
clicked, however it desn't seem to have any effect on
EditSectionPlugins popups...

Another problem I'm having is that I use EditSectionPlugin in a
TiddlySpaceTW online. The edits don't get saved unless I click edit
and save in the tiddlertoolbar - the idea of EditSectionsPlugin is
suffering from this. Could you add the function "autosave" as an
option to the plugin?? That would be great.

Thanks a lot Eric - Your high quality plugins make TiddlyWiki stand
out.

Regards Måns Mårtensson

Måns

unread,
Sep 12, 2010, 8:22:51 AM9/12/10
to TiddlyWiki
Hi Tobias

How do i make this script actually *replace* text (and *not* fields)
For now I'm using it to add text - which is fine - however I have made
a lot of entries that I would like to replace, either with a blank
textarea or with a new modified template.
I tried to remove the +txt bit after store.getTiddlerText(t.title)
+'\n' and not the rest - to keep fields etc... That didn't work...
> <script label="Replace Text Now!">
> var t,i,
>         tids=store.getTaggedTiddlers('UPDATE'),
>         txt=store.getTiddlerText('NEWTEXT')||'';
> if(!confirm("Really replace the contents of:\n"+
>         tids.map(function(t){return t.title;})))return;
> for(i=0;i<tids.length;i++){
>         t=tids[i];
>         store.saveTiddler(
>                 t.title,
>                 t.title,
>                 store.getTiddlerText(t.title)+'\n'+txt,
>                 config.options.txtUserName,
>                 new Date(),
>                 t.tags,
>                 t.fields,
>                 t.created
>         );};
>
> </script>

Cheers Måns Mårtensson

Måns

unread,
Sep 12, 2010, 8:24:35 AM9/12/10
to TiddlyWiki

Tobias Beer

unread,
Sep 12, 2010, 8:57:50 AM9/12/10
to TiddlyWiki
Hi Måns,

Forgot about this thread. When you say "replace text" do you mean
replace a placeholder like %somePlaceholder% with some content or do
you mean take a section and replace it's content or do you mean take
any (multiline?) text and replace it with some other. What exactly is
the workflow or usecase you have in mind?

Tobias.

On 12 Sep., 14:22, Måns <humam...@gmail.com> wrote:

Måns

unread,
Sep 12, 2010, 9:38:43 AM9/12/10
to TiddlyWiki
Hi Tobias
> Forgot about this thread. When you say "replace text" do you mean
> replace a placeholder like %somePlaceholder% with some content or do
> you mean take a section and replace it's content or do you mean take
> any (multiline?) text and replace it with some other. What exactly is
> the workflow or usecase you have in mind?
The last one - simply replace all text in the textfield with my new
template - disregarding any previous entries in sections or whatever.
What I need however, is the custom fields and tags to stay...

I've added you as a member to my sandbox - feel free to test, modify
or make any commentaries there: http://sandboxmm.tiddlyspace.com/#BatchText

Cheers Måns Mårtensson

Tobias Beer

unread,
Sep 13, 2010, 9:08:24 AM9/13/10
to TiddlyWiki
Hi

With respect to the last code posted here [1], you simply have to
change...

store.getTiddlerText(t.title)+'\n'+txt,

...to...

txt,

...which sets the tiddler's content to what was retrieved as a
template via...

txt=store.getTiddlerText('NEWTEXT')||'';

Cheers, Tobias.

[1] http://groups.google.com/group/tiddlywiki/msg/707dfd2e5c80f2cc

Måns

unread,
Sep 13, 2010, 11:47:50 AM9/13/10
to TiddlyWiki
Hi Tobias
> With respect to the last code posted here [1], you simply have to
> change... store.getTiddlerText(t.title)+'\n'+txt, ...to... txt,
Great - Thank you :-)

Now I'll need to specify autosave to make all touched tiddlers save on
a TiddlySpace, unless I want to open every tiddler and click save...
I have tried inputting "autoSaveChanges();" at the end of the script,
however it didn't work..
I don't know if this is a TiddlySpace specific problem?..

Where do I put: autoSaveChanges(); ? - If that the way to go...?

I also wondered if I could create a prompt for tag (maybe even
multiple tags space or commasepareted) and yet another prompt for
template tiddler title?
Then I would be able to run the script without the fuzz of needing to
create a transclusion (tiddlermacro using substitutionmarkes in the
script) for each individual case.

Cheers Måns Mårtensson

Tobias Beer

unread,
Sep 13, 2010, 2:20:12 PM9/13/10
to TiddlyWiki
Hi Måns,

1) As for saving changes on tiddlyspace, I believe you have to
properly initialize certain server fields like this...

replace:
t.fields,

with:
merge(t.fields, config.defaultCustomFields),

That will read the default fields required for tiddlyspace from the
config and merge it with any existing fields, thus allowing for the
tiddler to save correctly.

2) Would your prompts be for each tiddler or one for all tiddlers?
Depending on that you simply have to put a prompt inside or outside
the for loop and assign its return value to the corresponding
variable, e.g.

var tgs=prompt("Please enter any tags.", "").readBracketedList();

With readBracketedList you can specify any of...

tagA "tag B" [[tag cdef]]

...in the prompt and all will be added correctly. You might want to
merge any tags entered into the prompt with the existing ones,
therefore replace:

t.tags,

with...

merge(t.tags,tgs),



So here's the whole deal...

<script label="Replace Text Now!">
var t,i,
tids=store.getTaggedTiddlers('UPDATE'),
tpl=prompt('Enter template name...',''),
tgs=prompt('Enter tags...','');
tgs=tgs?tgs.readBracketedList():[];

tpl=store.getTiddlerText(tpl)||'',

if(!confirm("Really replace the contents of:\n"+
tids.map(function(t){return t.title;})))return;

for(i=0;i<tids.length;i++){
t=tids[i];
store.saveTiddler(
t.title,
t.title,
tpl,
config.options.txtUserName,
new Date(),
merge(t.tags,tgs),
merge(t.fields, config.defaultCustomFields),
t.created
);
};
</script>

Give it a try...

Cheers, Tobias.

Måns

unread,
Sep 13, 2010, 3:09:36 PM9/13/10
to TiddlyWiki
Hi Tobias
Thanks a lot!
Thats real magic or maybe more rightly put: JS-poetry :-)
I had a syntaxerror - "unknown sth if" When I replace the comma after
"tpl=store.getTiddlerText(tpl)||''," with a ";" it seems to work, with
the prompts, however saving still doesn't occur?!
Saving of all edited tiddlers doesn't occur even if I edit/save one of
the affected tiddlers. Should I input "autoSaveChanges();" somewhere?

See test here: (logged in as you) http://sandboxmm.tiddlyspace.com/#BatchText
> replace: t.fields, with: merge(t.fields, config.defaultCustomFields),
I should have guessed - Fnd gave me a lecture on that subject in the
TiddlyWeb group. Thanks for the reminder - however it doesn't seem to
have any effect on triggering save on affected tiddlers (tagged with
UPDATE)
> 2) Would your prompts be for each tiddler or one for all tiddlers?
One for all tiddlers please..
> Depending on that you simply have to put a prompt inside or outside the for loop and assign its return value to the corresponding variable, e.g. var tgs=prompt("Please enter any tags.", "").readBracketedList(); With readBracketedList you can specify any of... tagA "tag B" [[tag cdef]]
Thanks for adding an option for adding tags - however what I'd like is
a prompt for specifying which tiddlers should be affected by the
script.
I'd like a prompt in the script, where it asks for "
tids=store.getTaggedTiddlers('UPDATE'), ".
I'd like to be able to specify one or more tags instead of "UPDATE" -
Is this possible?

I'm impressed by your scripting skills - Thanks for "taking a hack" on
this challenge.

Cheers Måns Mårtensson

Tobias Beer

unread,
Sep 13, 2010, 9:19:53 PM9/13/10
to TiddlyWiki
Hi again Måns,

Turns out - since you're actually not creating any new tiddlers - you
don't need to merge config.defaultCustomFields with any existing
fields.

I have modified the script in your sandbox for the tagging rule which
you desired and tested...

<script label="Replace Text Now!">
var i,t,
tids=store.getTaggedTiddlers('UPDATE'),
tpl=prompt('Enter template name...',''),
tgs=prompt('Filter by tags...','');
tgs=tgs?tgs.readBracketedList():[];
tpl=store.getTiddlerText(tpl)||'',
i=0;
while(i<tids.length){
t=tids[i];
if(tgs.length>0&&t.tags&&!t.tags.containsAny(tgs)){
tids.splice(i,1);
}else i++;
}
if(!tids.length)alert('Nothing to replace!');
else if(!confirm("Really replace the contents of:\n"+
tids.map(function(t){return t.title;})))return;
for(i=0;i<tids.length;i++){
t=tids[i];
//skip this tiddler if tags were defined yet this one doesn't have
any of them
store.saveTiddler(
t.title,
t.title,
tpl,
config.options.txtUserName,
new Date(),
merge(t.tags,tgs),
t.fields,
t.created
);
};
store.setDirty(true);
autoSaveChanges();
</script>

YET, having added in a store.setDirty(true) did not do the trick
either. However, this works offline! So, I guess we need some
tiddlyweb/tiddlyspace magician on the boat to solve this puzzle.

Cheers, Tobias.
Reply all
Reply to author
Forward
0 new messages