Re: add new column to Zotero Pane?

277 views
Skip to first unread message

dev4pp

unread,
Jun 1, 2013, 5:34:55 AM6/1/13
to zoter...@googlegroups.com
The specific error message that is thrown is

[JavaScript Error: "Invalid field 'extraInfo' in ItemFields.isBaseField()"]



On Friday, May 31, 2013 5:01:42 PM UTC+1, dev4pp wrote:
Hi,


I'm working on an extension that I envision would add a column to the Zotero pane which will display some extra info about each library item.

At present, I'm trying to add a treecol element to the corresponding tree defined in zoteroPane.xul.

In the code I currently do the following:

    var item = window.document.createElementNS(XUL_NS, "treecol"); // create a new XUL treecol
    item.setAttribute("id", "zotero-items-column-extraInfo");
    item.setAttribute("label", "Extra Info");
    item.setAttribute("hidden", "false");
    item.setAttribute("flex", "1");
    item.setAttribute("zotero-persist", "width ordinal hidden sortActive sortDirection");
    
    var headers = window.document.getElementById("zotero-items-columns-header");
    var titleColumn = window.document.getElementById("zotero-items-column-title");
    headers.insertBefore(item, titleColumn.nextSibling);

My intention with this snippet of code was to add an extra column, titled "Extra Info", to the Zotero pane right after the title column.

Now, when I start Firefox I get an error reading that "zotero-items-column-extraInfo" failed on a isBaseField() test.

Does this mean I need to add a corresponding "column" or data field to the underlying SQL database?


Thank you!

dev4pp

unread,
Jun 1, 2013, 5:48:40 AM6/1/13
to zoter...@googlegroups.com
In this commit from about a year ago a couple of columns were added:


If I understand correctly, the code I posted previously should do the essential bits for adding this extra column.

Maybe there is something in the way that Zotero starts up and loads extensions that makes adding extra columns from an extension impossible?

Will S

unread,
Jun 1, 2013, 12:03:25 PM6/1/13
to zoter...@googlegroups.com
Modifying a tree can be a little bit tricky.  You should look at this page for information on how trees work:


The data displayed in the items pane tree is set by the getCellText() method of the tree view in itemTreeView.js.  That function handles some columns specially, but otherwise it just pulls out the item field associated with the column id (the part of the id that comes after "zotero-items-column-").  So in your case, it is trying to find the item field 'extraInfo' which does not exist.

It might still be possible to do what you want without creating a new item field, but it might be a little more involved (maybe monkey patching getCellText() and adding your column dynamically after Zotero starts, rather than through an overlay?  I am not familiar enough with the items tree to say offhand what all would be necessary).  The commit you reference did not have to modify the tree view because it only added support for existing item fields.

dev4pp

unread,
Jun 6, 2013, 6:54:54 AM6/6/13
to zoter...@googlegroups.com
Thank you Will!

As far as I understand, what you suggested doesn't necessarily solve my problem of not being able to add a new column to the pane -- although I need to look invest more time looking into this.

So for now I followed your advice patching getCellText() to do what I need and simply hijack the Extra column for my extension-specific output.

What I'm doing now is:

var getCellTextOld = Zotero.ItemTreeView.prototype.getCellText;
Zotero.ItemTreeView.prototype.getCellText = function(row,column){
    if (column.id != "zotero-items-column-extra")
    {
        return getCellTextOld.apply(getCellTextOld, [row, column]);
    }
    else
    {
        return -99;
    }
}

This works to the extend that my extension now fills in the Extra column with "-99" for all items in my library (very useful, I know).

However, calls to the original getCellText() fail with this error message -- leaving the corresponding columns blank:

Error: TypeError: this._getItemAtRow is not a function
Source File: chrome://zotero/content/xpcom/itemTreeView.js
Line: 919

As far as I understand, getCellText() is called on objects of the Tree View type, i.e. something of the sort of "tree.view.getCellText(...)" where "tree" has the appropriate type.

So I am guessing that when overriding getCellText() as I do above I am messing something up about the "this" reference.

Anyone have an idea of how to fix this?

Aurimas Vinckevicius

unread,
Jun 6, 2013, 7:33:43 AM6/6/13
to zoter...@googlegroups.com
Shouldn't that be

return getCellTextOld.apply(this, [row, column]);

?

--
You received this message because you are subscribed to the Google Groups "zotero-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zotero-dev+...@googlegroups.com.
To post to this group, send email to zoter...@googlegroups.com.
Visit this group at http://groups.google.com/group/zotero-dev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

dev4pp

unread,
Jun 9, 2013, 6:17:32 AM6/9/13
to zoter...@googlegroups.com, aurim...@gmail.com
You're absolutely right -- this works!

Thinking about it, this also makes perfect sense once you read the manual:




Thank you!
Reply all
Reply to author
Forward
0 new messages