- update rich text interface to support subscript, superscript, and RTF indents

- cancel button works in edit citation dialog, and has been removed from edit bibliography dialog
This commit is contained in:
Simon Kornblith 2007-09-19 07:01:43 +00:00
parent 9a40d041b3
commit 7fef8f9a3c
5 changed files with 93 additions and 7 deletions

View File

@ -38,21 +38,32 @@
this._buttons = { this._buttons = {
'italic':document.getAnonymousElementByAttribute(this, "anonid", "rt-italic"), 'italic':document.getAnonymousElementByAttribute(this, "anonid", "rt-italic"),
'bold':document.getAnonymousElementByAttribute(this, "anonid", "rt-bold"), 'bold':document.getAnonymousElementByAttribute(this, "anonid", "rt-bold"),
'underline':document.getAnonymousElementByAttribute(this, "anonid", "rt-underline") 'underline':document.getAnonymousElementByAttribute(this, "anonid", "rt-underline"),
'superscript':document.getAnonymousElementByAttribute(this, "anonid", "rt-superscript"),
'subscript':document.getAnonymousElementByAttribute(this, "anonid", "rt-subscript")
}; };
// globals // globals
this._formatMap = { this._formatMap = {
"Integration":{ "Integration":{
"\\":"\\\\", "\\":"\\\\",
"&":"&",
"&lt;":"<",
"&gt;":">",
"<i>":"\\i ", "<i>":"\\i ",
"</i>":"\\i0 ", "</i>":"\\i0 ",
"<b>":"\\b ", "<b>":"\\b ",
"</b>":"\\b0 ", "</b>":"\\b0 ",
"<u>":"\\ul ", "<u>":"\\ul ",
"</u>":"\\ul0 ", "</u>":"\\ul0 ",
"<br>":"\n", "<br>":"\x0B",
"&amp;":"&" "<sup>":"\\super ",
"</sup>":"\\super0 ",
"<sub>":"\\sub ",
"</sub>":"\\sub0 ",
// there's no way to mimic a tab stop in CSS without
// tables, which wouldn't work here.
'<span class="tab">&nbsp;</span>':"\t"
} }
}; };
@ -114,7 +125,7 @@
<!-- Updates the status of text toggle buttons --> <!-- Updates the status of text toggle buttons -->
<method name="_updateButtons"> <method name="_updateButtons">
<body><![CDATA[ <body><![CDATA[
for each(var command in ["bold", "italic", "underline"]) { for each(var command in ["bold", "italic", "underline", "superscript", "subscript"]) {
try { try {
var enabled = this._browser.contentDocument.queryCommandState(command); var enabled = this._browser.contentDocument.queryCommandState(command);
@ -193,7 +204,38 @@
<setter><![CDATA[ <setter><![CDATA[
if(this._isLoaded) { if(this._isLoaded) {
var html = val; var html = val;
bodyStyle = "";
if(this._format != "HTML") { if(this._format != "HTML") {
if(this._format == "Integration") {
if(html.substr(0, 3) == "\\li") {
// try to show paragraph formatting
var returnIndex = html.indexOf("\r\n");
var tags = html.substr(1, returnIndex).split("\\");
html = html.substr(returnIndex+2);
for(var i=0; i<tags.length; i++) {
var tagName = tags[i].substr(0, 2);
var tagValue = tags[i].substring(2, tags[i].length-1);
if(tagName == "li") {
var li = parseInt(tagValue, 10);
} else if(tagName == "fi") {
var fi = parseInt(tagValue, 10);
}
}
// don't negatively indent
Zotero.debug(li);
Zotero.debug(fi);
if(fi < 0 && li == 0) {
li = -fi;
}
bodyStyle = "margin-left:"+(li/20+6)+"pt;text-indent:"+(fi/20)+"pt;";
Zotero.debug(bodyStyle);
}
}
// do appropriate replacement operations for non-HTML // do appropriate replacement operations for non-HTML
// formats // formats
var replacements = this._formatMap[this._format]; var replacements = this._formatMap[this._format];
@ -203,7 +245,7 @@
} }
// write // write
this._browser.contentDocument.write("<body>"+html+"</body>"); this._browser.contentDocument.write('<body style="'+bodyStyle+'">'+html+"</body>");
this._browser.contentDocument.close(); this._browser.contentDocument.close();
this._browser.contentDocument.designMode = (this._readonly ? "off" : "on"); this._browser.contentDocument.designMode = (this._readonly ? "off" : "on");
try { try {
@ -235,6 +277,12 @@
<xul:toolbarbutton anonid="rt-underline" class="rt-underline rt-text-control" <xul:toolbarbutton anonid="rt-underline" class="rt-underline rt-text-control"
tooltiptext="&zotero.richText.underline.label;" tooltiptext="&zotero.richText.underline.label;"
oncommand="parentNode.parentNode.parentNode.toggle('underline');"/> oncommand="parentNode.parentNode.parentNode.toggle('underline');"/>
<xul:toolbarbutton anonid="rt-superscript" class="rt-superscript rt-text-control"
tooltiptext="&zotero.richText.superscript.label;"
oncommand="parentNode.parentNode.parentNode.toggle('superscript');"/>
<xul:toolbarbutton anonid="rt-subscript" class="rt-subscript rt-text-control"
tooltiptext="&zotero.richText.subscript.label;"
oncommand="parentNode.parentNode.parentNode.toggle('subscript');"/>
</xul:toolbar> </xul:toolbar>
<xul:browser flex="1" anonid="rt-view" class="rt-view" <xul:browser flex="1" anonid="rt-view" class="rt-view"

View File

@ -1418,6 +1418,30 @@ Zotero.CSL.Citation.prototype.remove = function(citationItems) {
} }
} }
/*
* copies a citation
*/
Zotero.CSL.Citation.prototype.clone = function() {
var clone = new Zotero.CSL.Citation();
// copy items
for(var i=0; i<this.citationItems.length; i++) {
var oldCitationItem = this.citationItems[i];
var newCitationItem = new Zotero.CSL.CitationItem();
for(var key in oldCitationItem) {
newCitationItem[key] = oldCitationItem[key];
}
clone.citationItems.push(newCitationItem);
}
// copy properties
for(var key in this.properties) {
clone.properties[key] = this.properties[key];
}
return clone;
}
/* /*
* This is an item wrapper class for Zotero items. If converting this code to * This is an item wrapper class for Zotero items. If converting this code to
* work with another application, this is what needs changing. Potentially, this * work with another application, this is what needs changing. Potentially, this

View File

@ -773,7 +773,7 @@ Zotero.Integration.Session.prototype.editCitation = function(index, citation) {
var io = new function() { this.wrappedJSObject = this; } var io = new function() { this.wrappedJSObject = this; }
// create object to hold citation // create object to hold citation
io.citation = (citation ? citation : this.style.createCitation()); io.citation = (citation ? citation.clone() : this.style.createCitation());
io.citation.properties.index = index; io.citation.properties.index = index;
// assign preview function // assign preview function
io.previewFunction = function() { io.previewFunction = function() {
@ -784,7 +784,11 @@ Zotero.Integration.Session.prototype.editCitation = function(index, citation) {
.getService(Components.interfaces.nsIWindowWatcher) .getService(Components.interfaces.nsIWindowWatcher)
.openWindow(null, 'chrome://zotero/content/addCitationDialog.xul', '', .openWindow(null, 'chrome://zotero/content/addCitationDialog.xul', '',
'chrome,modal'+(Zotero.isWin ? ',popup' : ''), io); 'chrome,modal'+(Zotero.isWin ? ',popup' : ''), io);
if(citation && !io.citation.citationItems.length) {
io.citation = citation;
}
if(io.citation.citationItems.length) { // we have an item if(io.citation.citationItems.length) { // we have an item
this.addCitation(index, io.citation); this.addCitation(index, io.citation);
this.updateIndices[index] = true; this.updateIndices[index] = true;

View File

@ -130,6 +130,8 @@
<!ENTITY zotero.richText.italic.label "Italic"> <!ENTITY zotero.richText.italic.label "Italic">
<!ENTITY zotero.richText.bold.label "Bold"> <!ENTITY zotero.richText.bold.label "Bold">
<!ENTITY zotero.richText.underline.label "Underline"> <!ENTITY zotero.richText.underline.label "Underline">
<!ENTITY zotero.richText.superscript.label "Superscript">
<!ENTITY zotero.richText.subscript.label "Subscript">
<!ENTITY zotero.annotate.toolbar.add.label "Add Annotation"> <!ENTITY zotero.annotate.toolbar.add.label "Add Annotation">
<!ENTITY zotero.annotate.toolbar.collapse.label "Collapse All Annotations"> <!ENTITY zotero.annotate.toolbar.collapse.label "Collapse All Annotations">

View File

@ -10,6 +10,14 @@
list-style-image: url('chrome://zotero/skin/text_underline.png'); list-style-image: url('chrome://zotero/skin/text_underline.png');
} }
.rt-superscript {
list-style-image: url('chrome://zotero/skin/text_superscript.png');
}
.rt-subscript {
list-style-image: url('chrome://zotero/skin/text_subscript.png');
}
.rt-toolbar { .rt-toolbar {
padding: 2px; padding: 2px;
} }