commit 75374af5afc4c01dce49c8a39038d2808014020f
parent 41f39aa4e87948731bd2df30bcacded1cf9ce8bc
Author: Simon Kornblith <simon@simonster.com>
Date: Sun, 6 Jun 2010 00:01:11 +0000
- add Frank's citation re-ordering patch, with a few changes
- fix error when canceling citation add after editing
Diffstat:
8 files changed, 88 insertions(+), 13 deletions(-)
diff --git a/chrome/content/zotero/integration/addCitationDialog.js b/chrome/content/zotero/integration/addCitationDialog.js
@@ -50,6 +50,8 @@ var Zotero_Citation_Dialog = new function () {
this.toggleEditor = toggleEditor;
this.treeItemSelected = treeItemSelected;
this.listItemSelected = listItemSelected;
+ this.up = up;
+ this.down = down;
this.add = add;
this.remove = remove;
this.sortCitation = sortCitation;
@@ -215,19 +217,63 @@ var Zotero_Citation_Dialog = new function () {
_updateAccept();
_updatePreview();
}
+ _configListPosition(document.getElementById("citation-list"), true);
}
/*
* called when an item in the selected items list is clicked
*/
function listItemSelected() {
- var selectedListItem = document.getElementById("citation-list").getSelectedItem(0);
+ var itemList = document.getElementById("citation-list");
+ var selectedListItem = itemList.getSelectedItem(0);
var itemID = (selectedListItem ? selectedListItem.value : false);
_itemSelected(itemID);
+ _configListPosition(itemList, !itemID);
document.getElementById("remove").disabled = !itemID;
}
+ function _configListPosition(itemList,flag) {
+ var selectedIndex = itemList.selectedIndex;
+ if (selectedIndex > 0) {
+ document.getElementById("up").disabled = flag;
+ } else {
+ document.getElementById("up").disabled = true;
+ }
+ if (selectedIndex < (itemList.getRowCount() - 1)) {
+ document.getElementById("down").disabled = flag;
+ } else {
+ document.getElementById("down").disabled = true;
+ }
+ }
+
+ function _move(direction) {
+ var insertBeforeItem;
+ var itemList = document.getElementById("citation-list");
+ var selectedListItem = itemList.getSelectedItem(0);
+ var itemID = selectedListItem.value;
+ var selectedListIndex = itemList.selectedIndex;
+ if (direction === -1) {
+ insertBeforeItem = selectedListItem.previousSibling;
+ } else {
+ insertBeforeItem = selectedListItem.nextSibling.nextSibling;
+ }
+ var listItem = itemList.removeChild(selectedListItem);
+ itemList.insertBefore(listItem, insertBeforeItem);
+ itemList.selectedIndex = (selectedListIndex + direction);
+ _itemSelected(itemID);
+ _updatePreview();
+ _configListPosition(itemList, false);
+ }
+
+ function up() {
+ _move(-1);
+ }
+
+ function down() {
+ _move(1);
+ }
+
/*
* Adds a citation to the multipleSources list
*/
@@ -514,11 +560,15 @@ var Zotero_Citation_Dialog = new function () {
*/
function _addItem(item) {
var itemNode = document.createElement("listitem");
+ var itemList = document.getElementById("citation-list");
itemNode.setAttribute("value", item.getID());
itemNode.setAttribute("label", item.getField("title"));
itemNode.setAttribute("class", "listitem-iconic");
itemNode.setAttribute("image", item.getImageSrc());
- document.getElementById("citation-list").appendChild(itemNode);
+ itemList.appendChild(itemNode);
+ itemList.focus();
+ itemList.selectedIndex = itemList.childNodes.length-1;
+ _configListPosition(itemList, false);
}
/*
diff --git a/chrome/content/zotero/integration/addCitationDialog.xul b/chrome/content/zotero/integration/addCitationDialog.xul
@@ -159,15 +159,17 @@
</hbox>
</vbox>
- <hbox hidden="true" id="multiple-sources">
- <vbox align="center" pack="center">
+ <hbox hidden="true" id="multiple-sources" align="stretch">
+ <vbox align="center" pack="center" id="citation-buttons">
+ <toolbarbutton id="up" oncommand="Zotero_Citation_Dialog.up()" disabled="true"/>
<toolbarbutton id="add" oncommand="Zotero_Citation_Dialog.add()" disabled="true"/>
<toolbarbutton id="remove" oncommand="Zotero_Citation_Dialog.remove()" disabled="true"/>
+ <toolbarbutton id="down" oncommand="Zotero_Citation_Dialog.down()" disabled="true"/>
</vbox>
- <vbox>
+ <vbox align="left">
<checkbox id="keepSorted" hidden="true" checked="false" oncommand="Zotero_Citation_Dialog.sortCitation()" label="&zotero.citation.keepSorted.label;"/>
<listbox id="citation-list" flex="1" align="stretch" seltype="single"
- onselect="Zotero_Citation_Dialog.listItemSelected();"></listbox>
+ onselect="Zotero_Citation_Dialog.listItemSelected();"/>
</vbox>
</hbox>
</hbox>
diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js
@@ -616,10 +616,11 @@ Zotero.Integration.Document.prototype._updateSession = function(newField, editFi
Zotero.Integration.Document.prototype._updateDocument = function(forceCitations, forceBibliography) {
// update citations
this._session.updateUpdateIndices(forceCitations);
- this._deleteFields = this._deleteFields.concat(this._session.updateCitations());
- for(var i in this._session.citationText) {
+ var deleteCitations = this._session.updateCitations();
+ this._deleteFields = this._deleteFields.concat([i for(i in deleteCitations)]);
+ for(var i in this._session.updateIndices) {
citation = this._session.citationsByIndex[i];
- if(!citation) continue;
+ if(!citation || deleteCitations[i]) continue;
var fieldCode = this._session.getCitationField(citation);
if(fieldCode != citation.properties.field) {
@@ -1370,14 +1371,14 @@ Zotero.Integration.Session.prototype.updateCitations = function() {
Zotero.debug("Zotero.Integration: indices of updated citations");
Zotero.debug([key for(key in this.updateIndices)]);
- var deleteCitations = [];
+ var deleteCitations = {};
for each(var indexList in [this.newIndices, this.updateIndices]) {
for(var index in indexList) {
index = parseInt(index);
var citation = this.citationsByIndex[index];
if(citation.properties.delete) {
- if(deleteCitations.indexOf(index) == -1) deleteCitations.push(index);
+ deleteCitations[index] = true;
continue;
}
if(this.formatCitation(index, citation)) {
diff --git a/chrome/skin/default/zotero/citation-down-gray.png b/chrome/skin/default/zotero/citation-down-gray.png
Binary files differ.
diff --git a/chrome/skin/default/zotero/citation-down.png b/chrome/skin/default/zotero/citation-down.png
Binary files differ.
diff --git a/chrome/skin/default/zotero/citation-up-gray.png b/chrome/skin/default/zotero/citation-up-gray.png
Binary files differ.
diff --git a/chrome/skin/default/zotero/citation-up.png b/chrome/skin/default/zotero/citation-up.png
Binary files differ.
diff --git a/chrome/skin/default/zotero/integration.css b/chrome/skin/default/zotero/integration.css
@@ -1,3 +1,20 @@
+#up {
+ list-style-image: url('chrome://zotero/skin/citation-up.png');
+}
+
+#up[disabled="true"] {
+ list-style-image: url('chrome://zotero/skin/citation-up-gray.png');
+}
+
+#down {
+ list-style-image: url('chrome://zotero/skin/citation-down.png');
+}
+
+#down[disabled="true"] {
+ list-style-image: url('chrome://zotero/skin/citation-down-gray.png');
+}
+
+
#add {
list-style-image: url('chrome://zotero/skin/citation-add.png');
}
@@ -14,12 +31,17 @@
list-style-image: url('chrome://zotero/skin/citation-delete-gray.png');
}
-#add .toolbarbutton-text, #remove .toolbarbutton-text
+#citation-buttons > toolbarbutton
{
- margin: 0 !important;
+ margin: 2px 0 2px 4px !important;
padding: 0 !important;
}
+#citation-buttons > toolbarbutton > .toolbarbutton-text
+{
+ margin: 0 !important;
+ padding: 0 !important;
+}
#prefix, #suffix {
width: 200px;