Fixes for Calendar widget

Miscellaneous fixes from review:

- Distribute calendar.js and the interactive test
- Make the pointless protection against leap seconds actually work
  by starting in the middle of the day so that forward/back always
  move a day.
- Use a variable instead of an inline '8' to know where to start
  when removing old day actors.
- Remove a stray comment from the test

https://bugzilla.gnome.org/show_bug.cgi?id=596432
This commit is contained in:
Owen W. Taylor 2009-10-01 16:14:50 -04:00
parent 061a2cfbfb
commit afb3b1e718
5 changed files with 15 additions and 6 deletions

View File

@ -5,6 +5,7 @@ dist_jsui_DATA = \
appDisplay.js \
appIcon.js \
button.js \
calendar.js \
chrome.js \
dash.js \
dnd.js \

View File

@ -79,6 +79,7 @@ Calendar.prototype = {
// them in the right cell in the table. It doesn't matter if we add them in order
let iter = new Date(this.date);
iter.setSeconds(0); // Leap second protection. Hah!
iter.setHours(12);
for (let i = 0; i < 7; i++) {
this.actor.add(new St.Label({ text: iter.toLocaleFormat("%a") }),
{ row: 1,
@ -87,6 +88,9 @@ Calendar.prototype = {
iter.setTime(iter.getTime() + MSECS_IN_DAY);
}
// All the children after this are days, and get removed when we update the calendar
this._firstDayIndex = this.actor.get_children().length;
this._update();
},
@ -132,17 +136,18 @@ Calendar.prototype = {
},
_update: function() {
this._dateLabel.text = this.date.toLocaleFormat("%B %Y");
this._dateLabel.text = this.date.toLocaleFormat(this._headerFormat);
// Remove everything but the topBox and the weekday labels
let children = this.actor.get_children();
for (let i = 8; i < children.length; i++)
for (let i = this._firstDayIndex; i < children.length; i++)
children[i].destroy();
// Start at the beginning of the week before the start of the month
let iter = new Date(this.date);
iter.setDate(1);
iter.setSeconds(0);
iter.setHours(12);
iter.setTime(iter.getTime() - (iter.getDay() - this._weekStart) * MSECS_IN_DAY);
let now = new Date();

View File

@ -518,6 +518,10 @@ CalendarPopup.prototype = {
this.calendar = new Calendar.Calendar();
this.actor.add(this.calendar.actor);
// Directly adding the actor to Main.chrome.actor is a hack to
// work around the fact that there is no way to add an actor that
// affects the input region but not the shape.
// See: https://bugzilla.gnome.org/show_bug.cgi?id=597044
Main.chrome.actor.add_actor(this.actor);
Main.chrome.addInputRegionActor(this.actor);
this.actor.y = (panelActor.y + panelActor.height - this.actor.height);

View File

@ -3,7 +3,8 @@ EXTRA_DIST = run-test.sh.in
TEST_JS = \
testcommon/ui.js \
interactive/box-layout.js
interactive/box-layout.js \
interactive/calendar.js
EXTRA_DIST += $(TEST_JS)
TEST_MISC = \

View File

@ -4,11 +4,9 @@ const Clutter = imports.gi.Clutter;
const Lang = imports.lang;
const St = imports.gi.St;
const Calendar =imports.ui.calendar;
const Calendar = imports.ui.calendar;
const UI = imports.testcommon.ui;
const Gettext_gtk20 = imports.gettext.domain('gtk20');
UI.init();
let stage = Clutter.Stage.get_default();
stage.width = stage.height = 400;