From 05f56aa4898f0756344b5a1cd4eae3801ffef764 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Tue, 5 Sep 2006 02:03:59 +0000 Subject: [PATCH] closes #273, no location asked for in bibliography export (i think) - improved bibliography (especially Chicago Manual of Style) - improved error handling for import/export/bibliography - bibliographic export now ignores notes and standalone attachment (before, they made export silently fail). an error appears if you try to generate a bibliography from only notes or standalone attachments. --- .../content/scholar/fileInterface.js | 33 ++++++++++++++++--- .../chromeFiles/content/scholar/xpcom/cite.js | 7 ++-- .../locale/en-US/scholar/scholar.properties | 5 ++- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/chrome/chromeFiles/content/scholar/fileInterface.js b/chrome/chromeFiles/content/scholar/fileInterface.js index f8846e809c..c1c04680ba 100644 --- a/chrome/chromeFiles/content/scholar/fileInterface.js +++ b/chrome/chromeFiles/content/scholar/fileInterface.js @@ -91,6 +91,10 @@ var Scholar_File_Interface = new function() { function _exportDone(obj, worked) { Scholar_File_Interface.Progress.close(); _restoreUnresponsive(); + + if(!worked) { + window.alert(Scholar.getString("fileInterface.exportError")); + } } /* @@ -156,7 +160,7 @@ var Scholar_File_Interface = new function() { /* * closes items imported indicator */ - function _importDone(obj) { + function _importDone(obj, worked) { // add items to import collection for each(var itemID in obj.newItems) { _importCollection.addItem(itemID); @@ -234,6 +238,20 @@ var Scholar_File_Interface = new function() { * Shows bibliography options and creates a bibliography */ function _doBibliographyOptions(name, items) { + // make sure at least one item is not a standalone note or attachment + var haveNonNote = false; + for(var i in items) { + var type = Scholar.ItemTypes.getName(items[i].getType()); + if(type != "note" && type != "attachment") { + haveNonNote = true; + break; + } + } + if(!haveNonNote) { + window.alert(Scholar.getString("fileInterface.noReferencesError")); + return; + } + var io = new Object(); var newDialog = window.openDialog("chrome://scholar/content/bibliography.xul", "_blank","chrome,modal,centerscreen", io); @@ -245,9 +263,15 @@ var Scholar_File_Interface = new function() { } // generate bibliography - var csl = Scholar.Cite.getStyle(io.style); - csl.preprocessItems(items); - var bibliography = csl.createBibliography(items, format); + try { + var csl = Scholar.Cite.getStyle(io.style); + csl.preprocessItems(items); + var bibliography = csl.createBibliography(items, format); + } catch(e) { + window.alert(Scholar.getString("fileInterface.bibliographyGenerationError")); + throw(e); + return; + } if(io.output == "print") { // printable bibliography, using a hidden browser @@ -278,7 +302,6 @@ var Scholar_File_Interface = new function() { } Scholar.Browser.deleteHiddenBrowser(browser); - bibliographyStream.close(); } else if(io.output == "save-as-html") { var fStream = _saveBibliography(name, "HTML"); diff --git a/chrome/chromeFiles/content/scholar/xpcom/cite.js b/chrome/chromeFiles/content/scholar/xpcom/cite.js index 0db476ecf8..feebab15b4 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/cite.js +++ b/chrome/chromeFiles/content/scholar/xpcom/cite.js @@ -246,7 +246,10 @@ CSL.prototype.createBibliography = function(items, format) { var item = items[i]; var string = this._getCitation(item, "first", format, this._bib); - + if(!string) { + continue; + } + // add format if(this._bib.format) { // add citation prefix or suffix @@ -1207,7 +1210,7 @@ CSL.prototype._getCitation = function(item, position, format, bibCitElement) { } if(!type) { - throw("CSL: ERROR: no type found for item"); + return false; } Scholar.debug("CSL: using CSL type "+typeName); diff --git a/chrome/chromeFiles/locale/en-US/scholar/scholar.properties b/chrome/chromeFiles/locale/en-US/scholar/scholar.properties index 72cfb17838..47533bc0fe 100644 --- a/chrome/chromeFiles/locale/en-US/scholar/scholar.properties +++ b/chrome/chromeFiles/locale/en-US/scholar/scholar.properties @@ -103,9 +103,12 @@ fileInterface.export = Export fileInterface.exportedItems = Exported Items fileInterface.imported = Imported fileInterface.fileFormatUnsupported = No translator could be found for the given file. -fileInterface.importError = An error occurred while trying to import the selected file. Please ensure that the file is valid and try again. fileInterface.untitledBibliography = Untitled Bibliography fileInterface.bibliographyHTMLTitle = Bibliography +fileInterface.importError = An error occurred while trying to import the selected file. Please ensure that the file is valid and try again. +fileInterface.noReferencesError = The items you have selected contain no references. Please select one or more references and try again. +fileInterface.bibliographyGenerationError = An error occurred generating your bibliography. Please try again. +fileInterface.exportError = An error occurred while trying to export the selected file. searchOperator.is = is searchOperator.isNot = is not