Bug 352667 After deleting calendar the last calendar in list is not displayed r=mvl

This commit is contained in:
thomas.benisch%sun.com 2007-03-14 09:42:29 +00:00
parent f0bd391d0e
commit 2289d8bc14

View File

@ -48,9 +48,12 @@
// calendar-management.js
//
var gCalendars = [];
var gCachedStyleSheet;
function addCalendarToTree(aCalendar)
{
gCalendars.push(aCalendar);
if (!gCachedStyleSheet) {
gCachedStyleSheet = getStyleSheet("chrome://calendar/content/calendar-view-bindings.css");
}
@ -58,20 +61,24 @@ function addCalendarToTree(aCalendar)
updateLtnStyleSheet(aCalendar);
var boxobj = document.getElementById("calendarTree").treeBoxObject;
boxobj.rowCountChanged(getIndexForCalendar(aCalendar), 1);
boxobj.rowCountChanged(gCalendars.length-1, 1);
}
function removeCalendarFromTree(aCalendar)
{
var calTree = document.getElementById("calendarTree")
var index = getIndexForCalendar(aCalendar);
if (index == -1) {
return;
}
gCalendars.splice(index, 1);
var calTree = document.getElementById("calendarTree");
calTree.boxObject.rowCountChanged(index, -1);
// Just select the new last row, if we removed the last listed calendar
if (index == calTree.view.rowCount-1) {
if (index == calTree.view.rowCount) {
index--;
}
calTree.view.selection.select(index);
}
@ -186,19 +193,17 @@ function getCalendarManager()
return activeCalendarManager;
}
/**
* Provides the gCalendars list for callers outside of this file.
*/
function getCalendars()
{
try {
return getCalendarManager().getCalendars({});
} catch (e) {
dump("Error getting calendars: " + e + "\n");
return [];
}
return gCalendars;
}
function ltnNewCalendar()
{
openCalendarWizard(ltnSetTreeView);
openCalendarWizard();
}
function ltnRemoveCalendar(cal)
@ -218,7 +223,7 @@ var ltnCalendarTreeView = {
get rowCount()
{
try {
return getCalendars().length;
return gCalendars.length;
} catch (e) {
return 0;
}
@ -226,7 +231,7 @@ var ltnCalendarTreeView = {
getCellProperties: function (row, col, properties)
{
var cal = getCalendars()[row];
var cal = gCalendars[row];
if (col.id == "col-calendar-Checkbox") {
// We key off this to set the images for the checkboxes
if (getCompositeCalendar().getCalendar(cal.uri)) {
@ -243,7 +248,7 @@ var ltnCalendarTreeView = {
cycleCell: function (row, col)
{
var cal = getCalendars()[row];
var cal = gCalendars[row];
if (getCompositeCalendar().getCalendar(cal.uri)) {
// need to remove it
getCompositeCalendar().removeCalendar(cal.uri);
@ -257,7 +262,7 @@ var ltnCalendarTreeView = {
getCellValue: function (row, col)
{
if (col.id == "col-calendar-Checkbox") {
var cal = getCalendars()[row];
var cal = gCalendars[row];
if (getCompositeCalendar().getCalendar(cal.uri))
return "true";
return "false";
@ -291,7 +296,7 @@ var ltnCalendarTreeView = {
if (col.id == "col-calendar-Calendar") {
try {
return getCalendars()[row].name;
return gCalendars[row].name;
} catch (e) {
return "<Unknown " + row + ">";
}
@ -322,7 +327,7 @@ var ltnCalendarTreeView = {
var row = tree.treeBoxObject.getRowAt(event.clientX, event.clientY);
// If we clicked on a calendar, edit it, otherwise create a new one
var cal = getCalendars()[row];
var cal = gCalendars[row];
if (!cal) {
ltnNewCalendar();
} else {
@ -333,6 +338,7 @@ var ltnCalendarTreeView = {
function ltnSetTreeView()
{
gCalendars = getCalendarManager().getCalendars({});
document.getElementById("calendarTree").view = ltnCalendarTreeView;
// Ensure that a calendar is selected in calendar tree after startup.
@ -344,13 +350,12 @@ function ltnSetTreeView()
}
function getIndexForCalendar(aCalendar) {
// Special trick to compare interface pointers, since normal, ==
// comparison can fail due to javascript wrapping.
var sip = Components.classes["@mozilla.org/supports-interface-pointer;1"]
.createInstance(Components.interfaces.nsISupportsInterfacePointer);
sip.data = aCalendar;
sip.dataIID = Components.interfaces.calICalendar;
return getCalendars().indexOf(sip.data);
for (var i = 0; i < gCalendars.length; ++i) {
if (gCalendars[i].id == aCalendar.id) {
return i;
}
}
return -1;
}
function getColorPropertyName(color) {