Ticket #311 (new defect)

Opened 19 months ago

Last modified 12 months ago

When you create a new tiddler and a tiddler called 'New Tiddler' already exists...

Reported by: simon Owned by:
Priority: major Milestone: soon
Component: core Version:
Severity: medium Keywords: usability
Cc:

Description

...it opens the existing tiddler called New Tiddler for edit. This is confusing. Perhaps it should use 'New Tiddler (1)' if 'New Tiddler' already exists. And 'New Tiddler (2)' if that exists and so on. Same for New Journal or actually any new tiddler button, eg this <<newTiddler title:AnyTitle>> should behave the same way it AnyTitle? already exists.

Change History

Changed 17 months ago by simon

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");

Changed 17 months ago by simon

maybe the String.prototype in that position is a bad idea? Could refactor it to a regular function.

Changed 17 months ago by JeremyRuston

Also see the discussion here

Changed 15 months ago by MartinBudden

  • milestone set to 2.3

Changed 12 months ago by MartinBudden

  • milestone changed from 2.3 to soon
Note: See TracTickets for help on using tickets.