- add Frank's citation re-ordering patch, with a few changes

- fix error when canceling citation add after editing
This commit is contained in:
Simon Kornblith 2010-06-06 00:01:11 +00:00
parent 41f39aa4e8
commit 75374af5af
8 changed files with 88 additions and 13 deletions

View File

@ -50,6 +50,8 @@ var Zotero_Citation_Dialog = new function () {
this.toggleEditor = toggleEditor; this.toggleEditor = toggleEditor;
this.treeItemSelected = treeItemSelected; this.treeItemSelected = treeItemSelected;
this.listItemSelected = listItemSelected; this.listItemSelected = listItemSelected;
this.up = up;
this.down = down;
this.add = add; this.add = add;
this.remove = remove; this.remove = remove;
this.sortCitation = sortCitation; this.sortCitation = sortCitation;
@ -215,19 +217,63 @@ var Zotero_Citation_Dialog = new function () {
_updateAccept(); _updateAccept();
_updatePreview(); _updatePreview();
} }
_configListPosition(document.getElementById("citation-list"), true);
} }
/* /*
* called when an item in the selected items list is clicked * called when an item in the selected items list is clicked
*/ */
function listItemSelected() { 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); var itemID = (selectedListItem ? selectedListItem.value : false);
_itemSelected(itemID); _itemSelected(itemID);
_configListPosition(itemList, !itemID);
document.getElementById("remove").disabled = !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 * Adds a citation to the multipleSources list
*/ */
@ -514,11 +560,15 @@ var Zotero_Citation_Dialog = new function () {
*/ */
function _addItem(item) { function _addItem(item) {
var itemNode = document.createElement("listitem"); var itemNode = document.createElement("listitem");
var itemList = document.getElementById("citation-list");
itemNode.setAttribute("value", item.getID()); itemNode.setAttribute("value", item.getID());
itemNode.setAttribute("label", item.getField("title")); itemNode.setAttribute("label", item.getField("title"));
itemNode.setAttribute("class", "listitem-iconic"); itemNode.setAttribute("class", "listitem-iconic");
itemNode.setAttribute("image", item.getImageSrc()); 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);
} }
/* /*

View File

@ -159,15 +159,17 @@
</hbox> </hbox>
</vbox> </vbox>
<hbox hidden="true" id="multiple-sources"> <hbox hidden="true" id="multiple-sources" align="stretch">
<vbox align="center" pack="center"> <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="add" oncommand="Zotero_Citation_Dialog.add()" disabled="true"/>
<toolbarbutton id="remove" oncommand="Zotero_Citation_Dialog.remove()" 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> <vbox align="left">
<checkbox id="keepSorted" hidden="true" checked="false" oncommand="Zotero_Citation_Dialog.sortCitation()" label="&zotero.citation.keepSorted.label;"/> <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" <listbox id="citation-list" flex="1" align="stretch" seltype="single"
onselect="Zotero_Citation_Dialog.listItemSelected();"></listbox> onselect="Zotero_Citation_Dialog.listItemSelected();"/>
</vbox> </vbox>
</hbox> </hbox>
</hbox> </hbox>

View File

@ -616,10 +616,11 @@ Zotero.Integration.Document.prototype._updateSession = function(newField, editFi
Zotero.Integration.Document.prototype._updateDocument = function(forceCitations, forceBibliography) { Zotero.Integration.Document.prototype._updateDocument = function(forceCitations, forceBibliography) {
// update citations // update citations
this._session.updateUpdateIndices(forceCitations); this._session.updateUpdateIndices(forceCitations);
this._deleteFields = this._deleteFields.concat(this._session.updateCitations()); var deleteCitations = this._session.updateCitations();
for(var i in this._session.citationText) { this._deleteFields = this._deleteFields.concat([i for(i in deleteCitations)]);
for(var i in this._session.updateIndices) {
citation = this._session.citationsByIndex[i]; citation = this._session.citationsByIndex[i];
if(!citation) continue; if(!citation || deleteCitations[i]) continue;
var fieldCode = this._session.getCitationField(citation); var fieldCode = this._session.getCitationField(citation);
if(fieldCode != citation.properties.field) { 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("Zotero.Integration: indices of updated citations");
Zotero.debug([key for(key in this.updateIndices)]); Zotero.debug([key for(key in this.updateIndices)]);
var deleteCitations = []; var deleteCitations = {};
for each(var indexList in [this.newIndices, this.updateIndices]) { for each(var indexList in [this.newIndices, this.updateIndices]) {
for(var index in indexList) { for(var index in indexList) {
index = parseInt(index); index = parseInt(index);
var citation = this.citationsByIndex[index]; var citation = this.citationsByIndex[index];
if(citation.properties.delete) { if(citation.properties.delete) {
if(deleteCitations.indexOf(index) == -1) deleteCitations.push(index); deleteCitations[index] = true;
continue; continue;
} }
if(this.formatCitation(index, citation)) { if(this.formatCitation(index, citation)) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 1010 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 397 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1009 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 407 B

View File

@ -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 { #add {
list-style-image: url('chrome://zotero/skin/citation-add.png'); list-style-image: url('chrome://zotero/skin/citation-add.png');
} }
@ -14,13 +31,18 @@
list-style-image: url('chrome://zotero/skin/citation-delete-gray.png'); list-style-image: url('chrome://zotero/skin/citation-delete-gray.png');
} }
#add .toolbarbutton-text, #remove .toolbarbutton-text #citation-buttons > toolbarbutton
{
margin: 2px 0 2px 4px !important;
padding: 0 !important;
}
#citation-buttons > toolbarbutton > .toolbarbutton-text
{ {
margin: 0 !important; margin: 0 !important;
padding: 0 !important; padding: 0 !important;
} }
#prefix, #suffix { #prefix, #suffix {
width: 200px; width: 200px;
} }