1
0
mirror of https://github.com/moparisthebest/FireTray synced 2024-12-22 13:58:48 -05:00

* options: fix Order preference sync

* options: display server types according to Order
* cleaning
This commit is contained in:
foudfou 2011-11-03 02:51:43 +01:00
parent 903f99f006
commit 4646612fae
4 changed files with 51 additions and 20 deletions

View File

@ -39,9 +39,9 @@ firetray.UIOptions = {
function(c) {
LOG("i: "+i+", cell:"+c);
c.removeEventListener(
'DOMAttrModified', that._userChangeValueTreeServerTypes, true);
'DOMAttrModified', that._userChangeValueTreeServerTypes, true); // FIXME
c.removeEventListener(
'DOMAttrModified', that._userChangeValueTreeAccounts, true);
'DOMAttrModified', that._userChangeValueTreeAccounts, true); // FIXME
});
}
},
@ -77,16 +77,22 @@ firetray.UIOptions = {
},
_userChangeValueTreeServerTypes: function(event) {
let checkboxCell = event.originalTarget;
let tree = document.getElementById("ui_tree_mail_accounts");
if (event.attrName === "value") { // checkbox
let checkboxCell = event.originalTarget;
let tree = document.getElementById("ui_tree_mail_accounts");
let rows = firetray.Utils.XPath(
checkboxCell,
'ancestor::xul:treeitem[1]/descendant::xul:treechildren//xul:treerow');
LOG("rows="+rows);
for (let i=0; i<rows.length; i++)
this._disableTreeRow(rows[i],
(checkboxCell.getAttribute("value") === "false"));
} else if (event.attrName == "label") { // text
// TODO: move row to new rank
}
let rows = firetray.Utils.XPath(
checkboxCell,
'ancestor::xul:treeitem[1]/descendant::xul:treechildren//xul:treerow');
LOG("rows="+rows);
for (let i=0; i<rows.length; i++)
this._disableTreeRow(rows[i],
(checkboxCell.getAttribute("value") === "false"));
this._userChangeValueTreeAccounts(event);
},
@ -107,9 +113,22 @@ firetray.UIOptions = {
let accountsByServerType = firetray.Messaging.accountsByServerType();
LOG(JSON.stringify(accountsByServerType));
// sort serverTypes according to order
let serverTypesSorted = Object.keys(serverTypes);
serverTypesSorted.sort(function(a,b) {
if (serverTypes[a].order
< serverTypes[b].order)
return -1;
if (serverTypes[a].order
> serverTypes[b].order)
return 1;
return 0; // no sorting
});
LOG("serverTypesSorted: "+serverTypesSorted);
let target = document.getElementById("ui_mail_accounts");
for (let serverTypeName in serverTypes) {
let name = serverTypes[serverTypeName];
for (let i=0; i<serverTypesSorted.length; i++) {
let serverTypeName = serverTypesSorted[i];
let item = document.createElement('treeitem');
item.setAttribute("container",true);
@ -138,7 +157,9 @@ firetray.UIOptions = {
let cellOrder = document.createElement('treecell');
cellOrder.setAttribute('label',serverTypes[serverTypeName].order);
cellOrder.addEventListener( // CAUTION: removeEventListener in onQuit()
'DOMAttrModified', that._userChangeValueTreeServerTypes, true);
'DOMAttrModified', function(e) {
that._userChangeValueTreeServerTypes(e);
}, true);
row.appendChild(cellOrder);
target.appendChild(item);
@ -209,7 +230,7 @@ firetray.UIOptions = {
tree.view.getCellText(
i, tree.columns.getNamedColumn("account_or_server_type_order")));
LOG("SUPER: "+accountOrServerTypeName+", "+accountOrServerTypeExcluded);
LOG("account: "+accountOrServerTypeName+", "+accountOrServerTypeExcluded);
if (tree.view.getLevel(i) === 0) { // serverTypes
prefObj["serverTypes"][accountOrServerTypeName] =

View File

@ -62,7 +62,7 @@
<treecol id="account_or_server_type_order" editable="true"
persist="width"
flex="1" hidden= "true" label="&account_or_server_type_order;"
tooltiptext="&account_or_server_type_name.tooltip;"/>
tooltiptext="&account_or_server_type_order.tooltip;"/>
</treecols>
<treechildren id="ui_mail_accounts" flex="1" />
</tree>

View File

@ -12,8 +12,8 @@
<!ENTITY unread_count_account_exceptions.tooltip "Included accounts for unread message count">
<!ENTITY account_or_server_type_name "Account">
<!ENTITY account_or_server_type_name.tooltip "FIXME">
<!ENTITY account_or_server_type_name.tooltip "Account name or type">
<!ENTITY account_or_server_type_excluded "Excluded">
<!ENTITY account_or_server_type_excluded.tooltip "FIXME">
<!ENTITY account_or_server_type_excluded.tooltip "Includes accounts or types into unread messages count">
<!ENTITY account_or_server_type_order "Order">
<!ENTITY account_or_server_type_order.tooltip "FIXME">
<!ENTITY account_or_server_type_order.tooltip "Order in which mail server types are displayed. Double-clic to edit.">

View File

@ -3,7 +3,7 @@
var EXPORTED_SYMBOLS =
[ "firetray", "Cc", "Ci", "Cu", "LOG", "WARN", "ERROR",
"FIREFOX_ID", "THUNDERBIRD_ID", "SEAMONKEY_ID",
"isArray", "XPath" ];
"XPath", "isArray" ];
const Cc = Components.classes;
const Ci = Components.interfaces;
@ -173,3 +173,13 @@ firetray.Utils = {
function isArray(o) {
return Object.prototype.toString.call(o) === '[object Array]';
}
// http://stackoverflow.com/questions/18912/how-to-find-keys-of-a-hash
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/keys
if(!Object.keys) Object.keys = function(o){
if (o !== Object(o))
throw new TypeError('Object.keys called on non-object');
var ret=[],p;
for(p in o) if(Object.prototype.hasOwnProperty.call(o,p)) ret.push(p);
return ret;
};