Ticket #1753: recognizePDF.js.diff

File recognizePDF.js.diff, 1.9 KB (added by ajlyon, 6 years ago)

Patch vs. trunk to add something like fallback on PDF recognition

  • chrome/content/zotero/recognizePDF.js

     
    174174 * @param {String} [error] The error name, if recognition was unsuccessful. 
    175175 */ 
    176176Zotero_RecognizePDF.ItemRecognizer.prototype._callback = function(newItem, error) { 
     177        var recognitionSuccess = false; 
    177178        if(this._stopped) { 
    178179                if(newItem) Zotero.Items.erase(newItem.id); 
    179180                return; 
    180181        } 
    181182         
    182183        if(newItem) { 
     184                recognitionSuccess=true; 
     185        } else if (Zotero.Prefs.get('documentOnRecognizeFailureHack')) { 
     186                newItem =  new Zotero.Item('document'); 
     187                newItem.setField('title', this._item.getFile().leafName); 
     188                newItem.save(); 
     189        } 
     190 
     191        if(newItem) {    
    183192                // put new item in same collections as the old one 
    184193                var itemCollections = this._item.getCollections(); 
    185194                for(var j=0; j<itemCollections.length; j++) { 
    186195                        var collection = Zotero.Collections.get(itemCollections[j]); 
    187196                        collection.addItem(newItem.id); 
    188197                } 
    189                  
     198 
    190199                // put old item as a child of the new item 
    191200                this._item.setSource(newItem.id); 
    192                 this._item.save();       
     201                this._item.save(); 
    193202        } 
    194203                 
    195204        // add name 
    196205        this._progressWindow.document.getElementById("item-"+this._item.id+"-title"). 
    197                 setAttribute("label", (newItem ? newItem.getField("title") : Zotero.getString(error))); 
     206                setAttribute("label", (recognitionSuccess ? newItem.getField("title") : Zotero.getString(error))); 
    198207        // update icon 
    199208        this._progressWindow.document.getElementById("item-"+this._item.id+"-icon"). 
    200                 setAttribute("src", (newItem ? Zotero_RecognizePDF_SUCCESS_IMAGE : Zotero_RecognizePDF_FAILURE_IMAGE)); 
     209                setAttribute("src", (recognitionSuccess ? Zotero_RecognizePDF_SUCCESS_IMAGE : Zotero_RecognizePDF_FAILURE_IMAGE)); 
    201210         
    202211        if(error == "recognizePDF.limit") { 
    203212                // now done, since we hit the query limit 
     
    455464                obj[i] = items; 
    456465                return obj; 
    457466        } 
    458 } 
    459  No newline at end of file 
     467}