commit 8303028a8526ea6dd416a0bca5cd4d2836a708bf
parent fc2be8668101c092431f16f089b508ad31f13c2d
Author: Dan Stillman <dstillman@zotero.org>
Date: Fri, 22 Sep 2006 23:53:16 +0000
Closes #228, Use a unique default "Untitled" name for new saved searches
Collections too
- Also fixed JS strict warning in Item.erase()
Diffstat:
3 files changed, 48 insertions(+), 6 deletions(-)
diff --git a/chrome/chromeFiles/content/scholar/overlay.js b/chrome/chromeFiles/content/scholar/overlay.js
@@ -155,7 +155,11 @@ var ScholarPane = new function()
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
- var newName = { value: Scholar.getString('pane.collections.untitled') };
+ var untitled = Scholar.getString('pane.collections.untitled');
+ untitled = Scholar.DB.getNextName('collections', 'collectionName',
+ Scholar.getString('pane.collections.untitled'));
+
+ var newName = { value: untitled };
var result = promptService.prompt(window, "",
Scholar.getString('pane.collections.name'), newName, "", {});
@@ -166,7 +170,7 @@ var ScholarPane = new function()
if (!newName.value)
{
- newName.value = Scholar.getString('pane.collections.untitled');
+ newName.value = untitled;
}
Scholar.Collections.add(newName.value);
@@ -177,8 +181,10 @@ var ScholarPane = new function()
var s = new Scholar.Search();
s.addCondition('title','contains','');
- // TODO: add integer to 'Untitled' if more than one
- var io = {dataIn: {search: s, name: 'Untitled'}, dataOut: null};
+ var untitled = Scholar.getString('pane.collections.untitled');
+ untitled = Scholar.DB.getNextName('savedSearches', 'savedSearchName',
+ Scholar.getString('pane.collections.untitled'));
+ var io = {dataIn: {search: s, name: untitled}, dataOut: null};
window.openDialog('chrome://scholar/content/searchDialog.xul','','chrome,modal',io);
}
diff --git a/chrome/chromeFiles/content/scholar/xpcom/data_access.js b/chrome/chromeFiles/content/scholar/xpcom/data_access.js
@@ -1374,8 +1374,10 @@ Scholar.Item.prototype.erase = function(deleteChildren){
// Remove item from parent collections
var parentCollectionIDs = this.getCollections();
- for (var i=0; i<parentCollectionIDs.length; i++){
- Scholar.Collections.get(parentCollectionIDs[i]).removeItem(this.getID());
+ if (parentCollectionIDs){
+ for (var i=0; i<parentCollectionIDs.length; i++){
+ Scholar.Collections.get(parentCollectionIDs[i]).removeItem(this.getID());
+ }
}
// Note
diff --git a/chrome/chromeFiles/content/scholar/xpcom/db.js b/chrome/chromeFiles/content/scholar/xpcom/db.js
@@ -15,6 +15,7 @@ Scholar.DB = new function(){
this.getColumns = getColumns;
this.getColumnHash = getColumnHash;
this.getNextID = getNextID;
+ this.getNextName = getNextName;
this.beginTransaction = beginTransaction;
this.commitTransaction = commitTransaction;
this.rollbackTransaction = rollbackTransaction;
@@ -374,6 +375,39 @@ Scholar.DB = new function(){
}
+ /**
+ * Find the next lowest numeric suffix for a value in table column
+ *
+ * For example, if "Untitled" and "Untitled 2" and "Untitled 4",
+ * returns "Untitled 3"
+ *
+ * If _name_ alone is available, returns that
+ **/
+ function getNextName(table, field, name)
+ {
+ var sql = "SELECT " + field + " FROM " + table + " WHERE " + field
+ + " LIKE ? ORDER BY " + field;
+ var untitleds = Scholar.DB.columnQuery(sql, name + '%');
+
+ if (!untitleds || untitleds[0]!=name){
+ return name;
+ }
+
+ var i = 1;
+ var num = 2;
+ while (untitleds[i] && untitleds[i]==(name + ' ' + num)){
+ while (untitleds[i+1] && untitleds[i]==untitleds[i+1]){
+ Scholar.debug('Next ' + i + ' is ' + untitleds[i]);
+ i++;
+ }
+
+ i++;
+ num++;
+ }
+
+ return name + ' ' + num;
+ }
+
/////////////////////////////////////////////////////////////////