From beba35b44ae9f3f55a62b97445311e77b3e6c01f Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 17 Apr 2007 05:00:27 +0000 Subject: [PATCH] - Updated ItemTreeView.selectItem() to clear tag selector and quicksearch and try again if item not initially found - Fix phrase search in quick search and other brokenness --- chrome/content/zotero/overlay.js | 16 ++++++++-- .../zotero/xpcom/collectionTreeView.js | 17 ++++++++--- chrome/content/zotero/xpcom/itemTreeView.js | 15 +++++++--- chrome/content/zotero/xpcom/search.js | 30 +++++++------------ 4 files changed, 49 insertions(+), 29 deletions(-) diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index ab23d3a3b..f9f5fbaff 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -46,6 +46,7 @@ var ZoteroPane = new function() this.toggleTagSelector = toggleTagSelector; this.updateTagSelectorSize = updateTagSelectorSize; this.getTagSelection = getTagSelection; + this.clearTagSelection = clearTagSelection; this.updateTagFilter = updateTagFilter; this.onCollectionSelected = onCollectionSelected; this.itemSelected = itemSelected; @@ -637,6 +638,14 @@ var ZoteroPane = new function() } + function clearTagSelection() { + if (Zotero.hasValues(this.getTagSelection())) { + var tagSelector = document.getElementById('zotero-tag-selector'); + tagSelector.clearAll(); + } + } + + /* * Sets the tag filter on the items view */ @@ -1004,8 +1013,11 @@ var ZoteroPane = new function() function clearQuicksearch() { - document.getElementById('zotero-tb-search').value = ""; - document.getElementById('zotero-tb-search').doCommand('cmd_zotero_search'); + var search = document.getElementById('zotero-tb-search'); + if (search.value != '') { + search.value = ''; + search.doCommand('cmd_zotero_search'); + } } diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index 1c3f2116f..7e581b0a9 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -948,14 +948,23 @@ Zotero.ItemGroup.prototype.setTags = function(tags) } /* - * Returns TRUE if using quicksearch or tag filter + * Returns TRUE if saved search, quicksearch or tag filter */ Zotero.ItemGroup.prototype.isSearchMode = function() { + // Search + if (this.isSearch()) { + return true; + } + + // Quicksearch + if (this.searchText != '') { + return true; + } + + // Tag filter if (this.tags) { for (var i in this.tags) { - var hasTags = true; - break; + return true; } } - return this.searchText != '' || hasTags; } \ No newline at end of file diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index 27a49c844..3fcc4b5b5 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -928,7 +928,7 @@ Zotero.ItemTreeView.prototype.sort = function(itemID) /* * Select an item */ -Zotero.ItemTreeView.prototype.selectItem = function(id, expand) +Zotero.ItemTreeView.prototype.selectItem = function(id, expand, noRecurse) { // If no row map, we're probably in the process of switching collections, // so store the item to select on the item group for later @@ -955,15 +955,22 @@ Zotero.ItemTreeView.prototype.selectItem = function(id, expand) // If row with id not visible, check to see if it's hidden under a parent if(row == undefined) { - if (!parent || parentRow === null) - { + if (!parent || parentRow === null) { // No parent -- it's not here + + // Clear the quicksearch and tag selection and try again (once) + if (!noRecurse) { + this._ownerDocument.defaultView.ZoteroPane.clearQuicksearch(); + this._ownerDocument.defaultView.ZoteroPane.clearTagSelection(); + return this.selectItem(id, expand, true); + } + return false; } this.toggleOpenState(parentRow); //opens the parent of the item row = this._itemRowMap[id]; } - + this.selection.select(row); // If _expand_, open container if (expand && this.isContainer(row) && !this.isContainerOpen(row)) { diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js index a1fc91c78..473be0a29 100644 --- a/chrome/content/zotero/xpcom/search.js +++ b/chrome/content/zotero/xpcom/search.js @@ -353,25 +353,13 @@ Zotero.Search.prototype.search = function(asTempTable){ + " WHERE sourceItemID IN (SELECT itemID FROM " + tmpTable + "))" + ")"; - if (asTempTable) { - var tmpTable2 = "tmpSearchResults_" + Zotero.randomString(8); - sql = "CREATE TEMPORARY TABLE " + tmpTable2 + " AS " + sql; - Zotero.DB.query(sql, this._sqlParams); - return tmpTable2; - } - else { - var ids = Zotero.DB.columnQuery(sql, this._sqlParams); - Zotero.DB.query("DROP TABLE " + tmpTable); - return ids; - } + var ids = Zotero.DB.columnQuery(sql, this._sqlParams); + Zotero.DB.query("DROP TABLE " + tmpTable); } - - if (this._scope) { - throw ("Fulltext content search with custom scope not currently supported in Zotero.Search.search()"); + else { + var ids = Zotero.DB.columnQuery(this._sql, this._sqlParams); } - var ids = Zotero.DB.columnQuery(this._sql, this._sqlParams); - //Zotero.debug('IDs from main search: '); //Zotero.debug(ids); @@ -453,7 +441,12 @@ Zotero.Search.prototype.search = function(asTempTable){ hash[id] = true; } - var scopeIDs = ids.filter(filter); + if (ids) { + var scopeIDs = ids.filter(filter); + } + else { + var scopeIDs = []; + } } // If ANY mode, just use fulltext word index hits for content search, // since the main results will be added in below @@ -495,7 +488,6 @@ Zotero.Search.prototype.search = function(asTempTable){ //Zotero.debug(ids); if (asTempTable) { - var ids = this._scope.search(); if (!ids) { return false; } @@ -537,7 +529,7 @@ Zotero.Search.prototype._idsToTempTable = function (ids) { var sql = "INSERT INTO " + tmpTable + " VALUES (?)"; var insertStatement = Zotero.DB.getStatement(sql); for (var i=0; i