Merge r1036, r1037, r1039, r1040, r1041, r1042 back to the branch

This commit is contained in:
Dan Stillman 2007-01-05 08:17:01 +00:00
parent 80354effc6
commit 1bfa4425bd
7 changed files with 189 additions and 73 deletions

View File

@ -151,6 +151,7 @@
} }
Zotero.debug('Refreshing tags selector'); Zotero.debug('Refreshing tags selector');
var empty = true;
var tagsToggleBox = this.id('tags-toggle'); var tagsToggleBox = this.id('tags-toggle');
if (fetch || this._dirty) { if (fetch || this._dirty) {
@ -201,6 +202,7 @@
//Zotero.debug(2); //Zotero.debug(2);
labels[i].setAttribute('inScope', true); labels[i].setAttribute('inScope', true);
labels[i].setAttribute('hidden', false); labels[i].setAttribute('hidden', false);
empty = false;
} }
else { else {
//Zotero.debug(3); //Zotero.debug(3);
@ -220,8 +222,38 @@
} }
labels[i].setAttribute('hidden', false); labels[i].setAttribute('hidden', false);
empty = false;
} }
} }
this.updateNumSelected();
this.id('tags-toggle').setAttribute('collapsed', empty);
this.id('no-tags-box').setAttribute('collapsed', !empty);
]]>
</body>
</method>
<method name="updateNumSelected">
<body>
<![CDATA[
var count = 0;
for (var i in this.selection) {
count++;
}
switch (count) {
case 0:
var mod = 'none';
break;
case 1:
var mod = 'singular';
break;
default:
var mod = 'plural';
}
this.id('num-selected').value = Zotero.getString('pane.tagSelector.numSelected.' + mod, [count]);
]]> ]]>
</body> </body>
</method> </method>
@ -233,25 +265,20 @@
<parameter name="ids"/> <parameter name="ids"/>
<body> <body>
<![CDATA[ <![CDATA[
if (type == 'item') { // This could be more optimized to insert new/changed tags at the appropriate
// spot if we cared, but we probably don't
if (type == 'collection-item' || type == 'item-tag' || type == 'tag') {
var t = this.id('tags-search').inputField; var t = this.id('tags-search').inputField;
this.setFilterTags(Zotero.Tags.search(t.value), true); this.setFilterTags(Zotero.Tags.search(t.value), true);
this._dirty = true; this._dirty = true;
this.doCommand(); this.doCommand();
} }
// TODO: optimize for tag notifications?
// Would need separate additional Notifier events
// to distinguish between item adds and item collection adds
// and for tag changes on items separate from item-modify,
// plus code to insert new/changed tags at the appropriate spot
return;
]]> ]]>
</body> </body>
</method> </method>
<!-- Not currently used -->
<method name="selectVisible"> <method name="selectVisible">
<body> <body>
<![CDATA[ <![CDATA[
@ -270,6 +297,7 @@
</method> </method>
<!-- Not currently used -->
<method name="clearVisible"> <method name="clearVisible">
<body> <body>
<![CDATA[ <![CDATA[
@ -278,7 +306,7 @@
var labels = tagsToggleBox.getElementsByTagName('label'); var labels = tagsToggleBox.getElementsByTagName('label');
for (var i=0; i<labels.length; i++){ for (var i=0; i<labels.length; i++){
labels[i].setAttribute('selected', 'false'); labels[i].setAttribute('selected', 'false');
this.selection[labels[i].value] = false; delete this.selection[labels[i].value];
} }
// Bubbles up to command // Bubbles up to command
@ -335,7 +363,7 @@
// Deselect // Deselect
if (label.getAttribute('selected')=='true'){ if (label.getAttribute('selected')=='true'){
this.selection[label.value] = false; delete this.selection[label.value];
label.setAttribute('selected', 'false'); label.setAttribute('selected', 'false');
} }
// Select // Select
@ -345,6 +373,8 @@
} }
this.doCommand(); this.doCommand();
this.updateNumSelected();
]]> ]]>
</body> </body>
</method> </method>
@ -462,10 +492,29 @@
<xul:menuitem label="&zotero.tagSelector.deleteTag;" class="menuitem-non-iconic" oncommand="this.parentNode.parentNode.parentNode.delete(document.popupNode.getAttribute('tagID')); event.stopPropagation()"/> <xul:menuitem label="&zotero.tagSelector.deleteTag;" class="menuitem-non-iconic" oncommand="this.parentNode.parentNode.parentNode.delete(document.popupNode.getAttribute('tagID')); event.stopPropagation()"/>
</xul:menupopup> </xul:menupopup>
<xul:vbox id="no-tags-box" align="center" pack="center" flex="1">
<xul:label value="&zotero.tagSelector.noTagsToDisplay;"/>
</xul:vbox>
<xul:vbox id="tags-toggle" flex="1"/> <xul:vbox id="tags-toggle" flex="1"/>
<xul:hbox>
<xul:hbox pack="start">
<xul:checkbox label="&zotero.tagSelector.displayAll;" <xul:checkbox label="&zotero.tagSelector.displayAll;"
oncommand="this.parentNode.parentNode.filterToScope = !this.checked; event.stopPropagation();"> oncommand="this.parentNode.parentNode.parentNode.parentNode.filterToScope = !this.checked; event.stopPropagation();">
</xul:checkbox> </xul:checkbox>
</xul:hbox>
<!--
<xul:hbox>
<xul:radiogroup orient="horizontal">
<xul:radio label="any"/>
<xul:radio label="all"/>
</xul:radiogroup>
</xul:hbox>
-->
</xul:hbox>
<xul:hbox> <xul:hbox>
<xul:label value="&zotero.tagSelector.filter;"/> <xul:label value="&zotero.tagSelector.filter;"/>
<xul:textbox id="tags-search" flex="1" type="timed" timeout="250" dir="reverse" <xul:textbox id="tags-search" flex="1" type="timed" timeout="250" dir="reverse"
@ -475,15 +524,23 @@
oncommand="this.parentNode.focus(); this.parentNode.parentNode.parentNode.parentNode.handleKeyPress(true)" hidden="true"/> oncommand="this.parentNode.focus(); this.parentNode.parentNode.parentNode.parentNode.handleKeyPress(true)" hidden="true"/>
</xul:textbox> </xul:textbox>
</xul:hbox> </xul:hbox>
<xul:hbox> <xul:hbox>
<xul:hbox pack="center">
<xul:label id="num-selected"/>
</xul:hbox>
<!-- <!--
Disabled until there's an ANY search mode Disabled (at least) until there's an ANY search mode
<xul:toolbarbutton label="&zotero.tagSelector.selectVisible;" class="zotero-clicky" <xul:toolbarbutton label="&zotero.tagSelector.selectVisible;"
oncommand="this.parentNode.parentNode.parentNode.selectVisible()"/>--> oncommand="this.parentNode.parentNode.parentNode.parentNode.selectVisible()"/>
<xul:toolbarbutton label="&zotero.tagSelector.clearVisible;" class="zotero-clicky" <xul:button label="&zotero.tagSelector.clearVisible;"
oncommand="this.parentNode.parentNode.parentNode.clearVisible()"/> oncommand="this.parentNode.parentNode.parentNode.parentNode.clearVisible()"/> -->
<xul:toolbarbutton label="&zotero.tagSelector.clearAll;" class="zotero-clicky" <xul:toolbarseparator/>
oncommand="this.parentNode.parentNode.parentNode.clearAll();"/> <xul:hbox pack="center">
<xul:button label="&zotero.tagSelector.clearAll;"
oncommand="this.parentNode.parentNode.parentNode.parentNode.clearAll();"/>
</xul:hbox>
</xul:hbox> </xul:hbox>
</xul:groupbox> </xul:groupbox>
</content> </content>

View File

@ -1188,12 +1188,8 @@ Zotero.Item.prototype.getNotes = function(){
* Return true if a note item is an abstract, false otherwise * Return true if a note item is an abstract, false otherwise
*/ */
Zotero.Item.prototype.isAbstract = function() { Zotero.Item.prototype.isAbstract = function() {
if (this.isAttachment()) {
return false;
}
if (!this.isNote()) { if (!this.isNote()) {
throw ("isAbstract() can only be called on note items"); return false;
} }
if (!this.getID()) { if (!this.getID()) {
@ -1640,6 +1636,7 @@ Zotero.Item.prototype.addTagByID = function(tagID) {
Zotero.DB.commitTransaction(); Zotero.DB.commitTransaction();
Zotero.Notifier.trigger('modify', 'item', this.getID()); Zotero.Notifier.trigger('modify', 'item', this.getID());
Zotero.Notifier.trigger('add', 'item-tag', this.getID() + '-' + tagID);
return true; return true;
} }
@ -1683,6 +1680,8 @@ Zotero.Item.prototype.replaceTag = function(oldTagID, newTag){
var id = this.addTag(newTag); var id = this.addTag(newTag);
Zotero.DB.commitTransaction(); Zotero.DB.commitTransaction();
Zotero.Notifier.trigger('modify', 'item', this.getID()); Zotero.Notifier.trigger('modify', 'item', this.getID());
Zotero.Notifier.trigger('remove', 'item-tag', this.getID() + '-' + oldTagID);
Zotero.Notifier.trigger('add', 'item-tag', this.getID() + '-' + id);
return id; return id;
} }
@ -1697,6 +1696,7 @@ Zotero.Item.prototype.removeTag = function(tagID){
Zotero.Tags.purge(); Zotero.Tags.purge();
Zotero.DB.commitTransaction(); Zotero.DB.commitTransaction();
Zotero.Notifier.trigger('modify', 'item', this.getID()); Zotero.Notifier.trigger('modify', 'item', this.getID());
Zotero.Notifier.trigger('remove', 'item-tag', this.getID() + '-' + tagID);
} }
Zotero.Item.prototype.removeAllTags = function(){ Zotero.Item.prototype.removeAllTags = function(){
@ -1705,10 +1705,18 @@ Zotero.Item.prototype.removeAllTags = function(){
} }
Zotero.DB.beginTransaction(); Zotero.DB.beginTransaction();
var tagIDs = this.getTagIDs();
Zotero.DB.query("DELETE FROM itemTags WHERE itemID=?", this.getID()); Zotero.DB.query("DELETE FROM itemTags WHERE itemID=?", this.getID());
Zotero.Tags.purge(); Zotero.Tags.purge();
Zotero.DB.commitTransaction(); Zotero.DB.commitTransaction();
Zotero.Notifier.trigger('modify', 'item', this.getID()); Zotero.Notifier.trigger('modify', 'item', this.getID());
if (tagIDs) {
for (var i in tagIDs) {
tagIDs[i] = this.getID() + '-' + tagIDs[i];
}
Zotero.Notifier.trigger('remove', 'item-tag', tagIDs);
}
} }
@ -2647,7 +2655,7 @@ Zotero.Collection.prototype.addItem = function(itemID){
Zotero.Notifier.trigger('modify', 'collection', this.getID()); Zotero.Notifier.trigger('modify', 'collection', this.getID());
} }
Zotero.Notifier.trigger('add', 'item', itemID); Zotero.Notifier.trigger('add', 'collection-item', this.getID() + '-' + itemID);
} }
@ -2688,7 +2696,7 @@ Zotero.Collection.prototype.removeItem = function(itemID){
Zotero.Notifier.trigger('modify', 'collection', this.getID()); Zotero.Notifier.trigger('modify', 'collection', this.getID());
} }
Zotero.Notifier.trigger('remove', 'item', itemID); Zotero.Notifier.trigger('remove', 'collection-item', this.getID() + '-' + itemID);
} }
@ -3251,6 +3259,47 @@ Zotero.Tags = new function(){
Zotero.debug('Renaming tag', 4); Zotero.debug('Renaming tag', 4);
Zotero.DB.beginTransaction(); Zotero.DB.beginTransaction();
// Check if the new tag already exists
var sql = "SELECT tagID FROM tags WHERE tag=?";
var existingTagID = Zotero.DB.valueQuery(sql, tag);
if (existingTagID) {
var itemIDs = this.getTagItems(tagID);
var existingItemIDs = this.getTagItems(existingTagID);
// Would be easier to just call removeTag(tagID) and addTag(existingID)
// here, but this is considerably more efficient
var sql = "UPDATE OR REPLACE itemTags SET tagID=? WHERE tagID=?";
Zotero.DB.query(sql, [existingTagID, tagID]);
// Manual purge of old tag
var sql = "DELETE FROM tags WHERE tagID=?";
Zotero.DB.query(sql, tagID);
delete _tags[_tagsByID[tagID]];
delete _tagsByID[tagID];
Zotero.Notifier.trigger('delete', 'tag', tagID);
// Simulate tag removal on items that used old tag
var itemTags = [];
for (var i in itemIDs) {
itemTags.push(itemIDs[i] + '-' + tagID);
}
Zotero.Notifier.trigger('remove', 'item-tag', itemTags);
// And send tag add for new tag (except for those that already had it)
var itemTags = [];
for (var i in itemIDs) {
if (existingItemIDs.indexOf(itemIDs[i]) == -1) {
itemTags.push(itemIDs[i] + '-' + existingTagID);
}
}
Zotero.Notifier.trigger('add', 'item-tag', itemTags);
Zotero.Notifier.trigger('modify', 'item', itemIDs);
Zotero.DB.commitTransaction();
return;
}
var sql = "UPDATE tags SET tag=? WHERE tagID=?"; var sql = "UPDATE tags SET tag=? WHERE tagID=?";
Zotero.DB.query(sql, [{string: tag}, {int: tagID}]); Zotero.DB.query(sql, [{string: tag}, {int: tagID}]);
@ -3270,15 +3319,21 @@ Zotero.Tags = new function(){
Zotero.DB.beginTransaction(); Zotero.DB.beginTransaction();
var sql = "SELECT itemID FROM itemTags WHERE tagID=?"; var sql = "SELECT itemID FROM itemTags WHERE tagID=?";
var items = Zotero.DB.columnQuery(sql, tagID); var itemIDs = Zotero.DB.columnQuery(sql, tagID);
if (!items) { if (!itemIDs) {
return; return;
} }
var sql = "DELETE FROM itemTags WHERE tagID=?"; var sql = "DELETE FROM itemTags WHERE tagID=?";
Zotero.DB.query(sql, tagID); Zotero.DB.query(sql, tagID);
Zotero.Notifier.trigger('modify', 'item', items)
Zotero.Notifier.trigger('modify', 'item', itemIDs)
var itemTags = [];
for (var i in itemIDs) {
itemTags.push(itemIDs[i] + '-' + tagID);
}
Zotero.Notifier.trigger('remove', 'item-tag', itemTags);
this.purge(); this.purge();
Zotero.DB.commitTransaction(); Zotero.DB.commitTransaction();

View File

@ -110,7 +110,7 @@ Zotero.ItemTreeView.prototype.refresh = function()
*/ */
Zotero.ItemTreeView.prototype.notify = function(action, type, ids) Zotero.ItemTreeView.prototype.notify = function(action, type, ids)
{ {
if (type != 'item'){ if (type != 'item' && type != 'collection-item'){
return; return;
} }
@ -136,12 +136,13 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids)
var rows = new Array(); var rows = new Array();
for(var i=0, len=ids.length; i<len; i++) for(var i=0, len=ids.length; i<len; i++)
{ {
if(action == 'delete' || !this._itemGroup.ref.hasItem(ids[i])) var removeID = (action == 'remove') ? ids[i].split('-')[1] : ids[i];
{
if (action == 'delete' || !this._itemGroup.ref.hasItem(removeID)) {
// Row might already be gone (e.g. if this is a child and // Row might already be gone (e.g. if this is a child and
// 'modify' was sent to parent) // 'modify' was sent to parent)
if (this._itemRowMap[ids[i]] != undefined) { if (this._itemRowMap[removeID] != undefined) {
rows.push(this._itemRowMap[ids[i]]); rows.push(this._itemRowMap[removeID]);
} }
} }
} }
@ -239,7 +240,6 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids)
else if (quicksearch.value == '') else if (quicksearch.value == '')
{ {
var items = Zotero.Items.get(ids); var items = Zotero.Items.get(ids);
for (var i in items) for (var i in items)
{ {
// if the item belongs in this collection // if the item belongs in this collection
@ -284,9 +284,7 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids)
if(action == 'add' && ids.length===1 && activeWindow) if(action == 'add' && ids.length===1 && activeWindow)
{ {
// Reset to Info tab // Reset to Info tab
this._treebox.treeBody.ownerDocument. this._treebox.treeBody.ownerDocument.getElementById('zotero-view-tabs').selectedIndex = 0;
getElementById('zotero-view-tabs').selectedIndex = 0;
this.selectItem(ids[0]); this.selectItem(ids[0]);
} }
// If single item is selected and was modified // If single item is selected and was modified
@ -307,9 +305,7 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids)
} }
} }
// Reselect item (in case the sort order changed and the item this.rememberSelection(savedSelection);
// went off-screen)
this.selectItem(ids[0]);
} }
else else
{ {
@ -759,7 +755,6 @@ Zotero.ItemTreeView.prototype.saveSelection = function()
savedSelection.push(this._getItemAtRow(j).ref.getID()); savedSelection.push(this._getItemAtRow(j).ref.getID());
} }
} }
return savedSelection; return savedSelection;
} }

View File

@ -23,7 +23,7 @@
Zotero.Notifier = new function(){ Zotero.Notifier = new function(){
var _observers = new Zotero.Hash(); var _observers = new Zotero.Hash();
var _disabled = false; var _disabled = false;
var _types = ['collection', 'search', 'item', 'tag']; var _types = ['collection', 'search', 'item', 'collection-item', 'item-tag', 'tag'];
var _inTransaction; var _inTransaction;
var _locked = false; var _locked = false;
var _queue = []; var _queue = [];
@ -114,7 +114,7 @@ Zotero.Notifier = new function(){
* type - 'collection', 'search', 'item' * type - 'collection', 'search', 'item'
* ids - single id or array of ids * ids - single id or array of ids
* *
* c = collection, s = search, i = item, t = tag * c = collection, s = search, i = item, t = tag, it = item-tag
* *
* *
* Notes: * Notes:
@ -215,7 +215,7 @@ Zotero.Notifier = new function(){
function sorter(a, b) { function sorter(a, b) {
return order.indexOf(a) - order.indexOf(b); return order.indexOf(a) - order.indexOf(b);
} }
var order = ['collection', 'search', 'items', 'tags']; var order = ['collection', 'search', 'item', 'collection-item', 'item-tag', 'tag'];
_queue.sort(); _queue.sort();
var order = ['add', 'modify', 'remove', 'move', 'delete']; var order = ['add', 'modify', 'remove', 'move', 'delete'];

View File

@ -55,11 +55,12 @@
<!ENTITY zotero.toolbar.attachment.weblink "Save Link to Current Page"> <!ENTITY zotero.toolbar.attachment.weblink "Save Link to Current Page">
<!ENTITY zotero.toolbar.attachment.snapshot "Take Snapshot of Current Page"> <!ENTITY zotero.toolbar.attachment.snapshot "Take Snapshot of Current Page">
<!ENTITY zotero.tagSelector.noTagsToDisplay "No tags to display">
<!ENTITY zotero.tagSelector.filter "Filter:"> <!ENTITY zotero.tagSelector.filter "Filter:">
<!ENTITY zotero.tagSelector.displayAll "Display All"> <!ENTITY zotero.tagSelector.displayAll "Display all tags">
<!ENTITY zotero.tagSelector.selectVisible "Select Visible"> <!ENTITY zotero.tagSelector.selectVisible "Select visible">
<!ENTITY zotero.tagSelector.clearVisible "Deselect Visible"> <!ENTITY zotero.tagSelector.clearVisible "Deselect visible">
<!ENTITY zotero.tagSelector.clearAll "Deselect All"> <!ENTITY zotero.tagSelector.clearAll "Deselect all">
<!ENTITY zotero.tagSelector.renameTag "Rename Tag..."> <!ENTITY zotero.tagSelector.renameTag "Rename Tag...">
<!ENTITY zotero.tagSelector.deleteTag "Delete Tag..."> <!ENTITY zotero.tagSelector.deleteTag "Delete Tag...">

View File

@ -21,6 +21,9 @@ pane.tagSelector.rename.title = Please enter a new name for this tag.
pane.tagSelector.rename.message = The tag will be changed in all associated items. pane.tagSelector.rename.message = The tag will be changed in all associated items.
pane.tagSelector.delete.title = Are you sure you want to delete this tag? pane.tagSelector.delete.title = Are you sure you want to delete this tag?
pane.tagSelector.delete.message = The tag will be removed from all items. pane.tagSelector.delete.message = The tag will be removed from all items.
pane.tagSelector.numSelected.none = 0 tags selected
pane.tagSelector.numSelected.singular = %S tag selected
pane.tagSelector.numSelected.plural = %S tags selected
pane.items.delete = Are you sure you want to delete the selected item? pane.items.delete = Are you sure you want to delete the selected item?
pane.items.delete.multiple = Are you sure you want to delete the selected items? pane.items.delete.multiple = Are you sure you want to delete the selected items?

View File

@ -1,9 +1,3 @@
/* Don't focus filter textbox if pane isn't open */
zoterotagselector[collapsed=true] tags-search
{
-moz-user-focus: ignore;
}
groupbox groupbox
{ {
overflow: auto; overflow: auto;
@ -21,20 +15,20 @@ checkbox
margin: .75em 0 .4em; margin: .75em 0 .4em;
} }
label #tags-toggle label
{ {
margin-right: .2em; margin-right: .2em;
padding: .15em .25em; padding: .15em .25em;
-moz-user-focus: ignore; -moz-user-focus: ignore;
} }
label[selected="true"] #tags-toggle label[selected="true"]
{ {
background: #a9c6f0 !important; background: #a9c6f0 !important;
} }
/* Visible out-of-scope tags should be grey */ /* Visible out-of-scope tags should be grey */
label[inScope="false"] #tags-toggle label[inScope="false"]
{ {
color: #666 !important; color: #666 !important;
} }
@ -46,15 +40,15 @@ label.zotero-clicky[inScope="false"]:active
background: inherit !important; background: inherit !important;
} }
label[draggedOver="true"] #tags-toggle label[draggedOver="true"]
{ {
color: white !important; color: white !important;
background: #666; background: #666;
} }
hbox groupbox > hbox
{ {
-moz-box-align: baseline; -moz-box-align: center;
-moz-box-pack: center; -moz-box-pack: center;
} }
@ -66,6 +60,12 @@ hbox
list-style-image: url('chrome://zotero/skin/search-cancel.png'); list-style-image: url('chrome://zotero/skin/search-cancel.png');
} }
groupbox > hbox > hbox
{
-moz-box-flex: 1;
-moz-box-align: center;
}
/* Bottom buttons */ /* Bottom buttons */
toolbarbutton.zotero-clicky toolbarbutton.zotero-clicky
{ {
@ -73,3 +73,8 @@ toolbarbutton.zotero-clicky
padding:1px; padding:1px;
height:1em; height:1em;
} }
textbox
{
margin: 3px 0 1px;
}