wshanks / Zutilo

Zotero plugin providing some additional editing features
Other
1.49k stars 70 forks source link

FeatureRequest: Overwrite an existing item with bibtex from clipboard #202

Open noppelmax opened 3 years ago

noppelmax commented 3 years ago

Hey,

i often face the problem that I have a couple of papers imported from ArXiv which will later be published at a conference. So I would like to keep all my notes, relations and tags for the paper/the item but replace all the items information with the original published version. Therefore I look up the bibtex stuff in the internet and copy to clipboard. In the next step I would like to overwrite all the fields of the item with the bibtex from the clipboard. Is this complicated to implement? Sadly I did not found any documentation of the Zotero Plugin API nor any nice and clear examples on how to parse BibTex and how to set an item fields.

My current workaround:

So my questions:

Reference:

I asked this question previously in the Better BibTex Repo: Issue 1885 but as I start writing code for Zutilo and I guess it matches Zutilo better I decided to move it here.

Code:

I already managed to get a menuitem in the right-click menu of a bib item. I also managed to get the text of the clipboard. But i failed to get the translator working. That is my current code for the menuitem click action:

pasteBibTex: function() {
        /* Function to parse the BibTex in the clipboard and overwrite all the contained 
        fields in the selected item. */
        var zitems = this.getSelectedItems(['regular']);

        if (!this.checkItemNumber(zitems, 'regularNoteAttachment1')) {
            return false;
        }

        var clipboardText = ZutiloChrome.getFromClipboard().trim()
        if (!clipboardText) {
            return false;
        }

        var translation = new Zotero.Translate.Import();
    translation.setString(str);

        Zotero.log(translation.translate());

        /*for (let zitem of zitems) {
            zitem.setString(clipboardText);
            zitem.saveTx()
        }
        */

        return true;
    }

I am not sure if Zotero.Translate.Import() is the correct Translator because I don't really want to import something. But I didn't found any snippet on how to parse BibTex and how to set fields of a zitem. What ever a zitem is.