Index: js/Macros.js
===================================================================
--- js/Macros.js (revision 2135)
+++ js/Macros.js (working copy)
@@ -469,6 +469,24 @@
return btn;
};
+String.prototype.getNextFreeName = function() {
+ var numberRegExp = / \(([0-9]+)\)$/;
+ var match = numberRegExp.exec(this);
+ if (match) {
+ var num = parseInt(match[1]) + 1;
+ return this.replace(numberRegExp," ("+num+")");
+ }
+ else {
+ return this + " (1)";
+ }
+}
+
+config.macros.newTiddler.getName = function(newName) {
+ while (store.getTiddler(newName))
+ newName = newName.getNextFreeName();
+ return newName;
+}
+
config.macros.newTiddler.onClickNewTiddler = function()
{
var title =
this.getAttribute("newTitle");
@@ -476,6 +494,7 @@
var now = new Date();
title = now.formatString(title.trim());
}
+ title = config.macros.newTiddler.getName
(title);
var params = this.getAttribute("params").split("|");
var focus = this.getAttribute("newFocus");
var template = this.getAttribute("newTemplate");
What would happen in this case if you created a new tiddler named
something other than the default 'New Tiddler'? I have a few commands
for creating new tiddlers from user entered names and here is the
scenario I am wondering if would still work in this case:
User creates a new tiddler called say 'test tiddler'. One of my
commands creates a new tiddler and puts a link to it from the tiddler
the command was run from. So, user runs the command, enters name
'test tiddler' in order to create a link to an already existing
tiddler and the current page. In this case would an entirely new
tiddler named 'test tiddler (1)' be created or would the already
existing tiddler be opened as is the case at the moment? I would also
need the current funtionality to continue where say the user does not
realise a tiddler of the chosen name already exists and creates a new
one. I would rather have the already existing tiddler open rather
than new duplicates of that tiddler being created suffixed by (1)
etc. So I guess what I mean is, if this only effects new tiddlers
named the default 'New Tiddler', good plan, otherwise perhaps it needs
a bit of conditional coding built into it to cover these types of
scenarios. But still good plan :)
Cheers
Jon
What would happen in this case if you created a new tiddler named
something other than the default 'New Tiddler'? I have a few commands
for creating new tiddlers from user entered names and here is the
scenario I am wondering if would still work in this case:
User creates a new tiddler called say 'test tiddler'. One of my
commands creates a new tiddler and puts a link to it from the tiddler
the command was run from. So, user runs the command, enters name
'test tiddler' in order to create a link to an already existing
tiddler and the current page. In this case would an entirely new
tiddler named 'test tiddler (1)' be created or would the already
existing tiddler be opened as is the case at the moment? I would also
need the current funtionality to continue where say the user does not
realise a tiddler of the chosen name already exists and creates a new
one. I would rather have the already existing tiddler open rather
than new duplicates of that tiddler being created suffixed by (1)
etc. So I guess what I mean is, if this only effects new tiddlers
named the default 'New Tiddler', good plan, otherwise perhaps it needs
a bit of conditional coding built into it to cover these types of
scenarios. But still good plan :)
On May 5, 7:45 am, "Simon Baird" <simon.ba...@gmail.com> wrote:
Jon
I've been thinking about a slightly different approach that gives a
bit more flexibility: adding a new parameter to <<newTiddler>> called
something "titleExists" like this:
<<newTiddler title:"Notes" titleExists:"Notes (%c)">>
The idea would be that if the titleExists parameter were specified it
would be used to generate a unique name if the specified title already
exists (by replacing %c with 0,1,2,3... etc. until an unused title is
found). Also, if 'title' were omitted then 'titleExists' would also be
used to generate the initial title.
What do you reckon? In any event, I propose to defer this until after
2.2. In the meantime, I've updated the ticket with a pointer to this
discussion.
Cheers
Jeremy.
--
Jeremy Ruston
mailto:jer...@osmosoft.com
http://www.tiddlywiki.com
Sounds sensible to me, so just defining title would effectively result
in the current behaviour whilst title and titleExists would result in
the behaviour being requested here. With just titleExists, the
initial tiddler name generated would have the superceeding (%c) from
the outset, have I got that right?
Cheers
Jon
On May 9, 3:42 pm, "Jeremy Ruston" <jeremy.rus...@gmail.com> wrote:
> I also think that the current behaviour is counter-intuitive, but
> agree that we have to maintain equivalent functionality for backwards
> compatibility.
>
> I've been thinking about a slightly different approach that gives a
> bit more flexibility: adding a new parameter to <<newTiddler>> called
> something "titleExists" like this:
>
> <<newTiddler title:"Notes" titleExists:"Notes (%c)">>
>
> The idea would be that if the titleExists parameter were specified it
> would be used to generate a unique name if the specified title already
> exists (by replacing %c with 0,1,2,3... etc. until an unused title is
> found). Also, if 'title' were omitted then 'titleExists' would also be
> used to generate the initial title.
>
> What do you reckon? In any event, I propose to defer this until after
> 2.2. In the meantime, I've updated the ticket with a pointer to this
> discussion.
>
> Cheers
>
> Jeremy.
>
That's correct. The design supports the following scenarios:
<<newTiddler title:"Notes">> - generates a single tiddler called "Notes"
<<newTiddler titleExists:"Notes %c">> generates a sequence of tiddler
titles "Notes 1", "Notes 2", "Notes 3" etc...
<<newTiddler title:"Notes" titleExists:"Notes %c">> generates a
sequence of tiddler titles starting with "Notes", and then "Notes 1",
"Notes 2", "Notes 3" etc...
Cheers
Jeremy
> > mailto:jer...@osmosoft .comhttp://www.tiddlywiki.com
Cheers
Jeremy.