Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

How to add a new "Custom Column" with DYNAMIC CODE (v4.0)

Mic edited this page Jan 24, 2015 · 1 revision

FOR ADDON VERSION 4.0

From version 5.0 new columns will be added directly from the addons settings panel.

The word COLNAME is a placeholder for the new custom column internal name.

To add a new custom column these files must be modified:

  • mzcw-settings.xul to add the new option in the addon settings.
  • prefs.js to add the new default setting.
  • mzcw-overlay.js to add the new column definition.
  • mzcw-customcolumns.js to add the new handler functions.

Under the en-US locale folder:

  • overlay.properties to add the needed text strings.
  • settings.dtd to add the needed text strings.

mzcw-settings.xul

Under

<prefpane id="ColumnsWizard_PrefPane">
  <preferences>

Add a code snippet like this

<preference id="ColumnsWizard.CustCols.AddCOLNAME"
    name="extensions.ColumnsWizard.CustCols.AddCOLNAME"
    type="bool" />

Then, under

<tabpanel id="custcols" orient="vertical">

just before the closing tag

</tabpanel>

Add a code snippet like this

<checkbox id="ColumnsWizard.AddCOLNAME_checkbox" label="&ColumnsWizard.AddCOLNAME.label;"
    preference="ColumnsWizard.CustCols.AddCOLNAME"/>

prefs.js

Add a line like this one:

pref("extensions.ColumnsWizard.CustCols.AddCOLNAME", false);

mzcw-overlay.js

Inside the loadCustCols function definition, add these four lines:

loadedCustColPref["COLNAME"] = {};
loadedCustColPref["COLNAME"].Pref = prefs.getBoolPref("AddCOLNAME");
loadedCustColPref["COLNAME"].Def = "AddCOLNAME";
loadedCustColPref["COLNAME"].customDBHeader = false;

If you need to make Thunderbird save a custom header, replace the last line by this one:

loadedCustColPref["COLNAME"].customDBHeader = "header_field_name";

mzcw-customcolumns.js

Add to the miczColumnsWizard.CustCols object the following methods, after the object literal.

miczColumnsWizard.CustCols["columnHandler_COLNAME"]={
    getCellText:      function(row, col) {
        return <This method must return the field value>;
    },
    getSortStringForRow: function(hdr) {return <This method must return the field value used for sorting>;},
    isString:            function() {return true;},
    getCellProperties:   function(row, col, props){},
    getRowProperties:    function(row, props){},
    getImageSrc:         function(row, col) {return null;},
    getSortLongForRow:   function(hdr) {return 0;}
};

overlay.properties

Append those lines at the end of the file

ColumnsWizardAddCOLNAME.label=<Write here the column header display name>
ColumnsWizardAddCOLNAMEDesc.label=<Write here the column header tooltip>

settings.dtd

Append this line at the end of the file

<!ENTITY ColumnsWizard.AddCOLNAME.label "<Column name>">

Utility

Thunderbird source browser: http://lxr.mozilla.org/comm-central/

https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMsgDBHdr

https://developer.mozilla.org/en-US/Add-ons/Thunderbird/HowTos/Common_Thunderbird_Extension_Techniques/Filter_Incoming_Mail