[gnome-shell] Calendar: force all months at the same height
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] Calendar: force all months at the same height
- Date: Mon, 4 Mar 2013 17:59:40 +0000 (UTC)
commit 69cdc5a9b9b107a8c01b5245d4d36f4a3c920483
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Tue Oct 23 18:21:20 2012 +0200
Calendar: force all months at the same height
Add one or two weeks from nearby months to avoid changing the menu height
when navigating it.
https://bugzilla.gnome.org/show_bug.cgi?id=641383
js/ui/calendar.js | 36 +++++++++++++++++++++++++++++-------
1 files changed, 29 insertions(+), 7 deletions(-)
---
diff --git a/js/ui/calendar.js b/js/ui/calendar.js
index 5effe26..050ad8d 100644
--- a/js/ui/calendar.js
+++ b/js/ui/calendar.js
@@ -538,16 +538,40 @@ const Calendar = new Lang.Class({
children[i].destroy();
// Start at the beginning of the week before the start of the month
+ //
+ // We want to show always 6 weeks (to keep the calendar menu at the same
+ // height if there are no events), so we pad it according to the following
+ // policy:
+ //
+ // 1 - If a month has 6 weeks, we place no padding (example: Dec 2012)
+ // 2 - If a month has 5 weeks and it starts on week start, we pad one week
+ // before it (example: Apr 2012)
+ // 3 - If a month has 5 weeks and it starts on any other day, we pad one week
+ // after it (example: Nov 2012)
+ // 4 - If a month has 4 weeks, we pad one week before and one after it
+ // (example: Feb 2010)
+ //
+ // Actually computing the number of weeks is complex, but we know that the
+ // problematic categories (2 and 4) always start on week start, and that
+ // all months at the end have 6 weeks.
+
let beginDate = new Date(this._selectedDate);
beginDate.setDate(1);
beginDate.setSeconds(0);
beginDate.setHours(12);
+ let year = beginDate.getYear();
+
let daysToWeekStart = (7 + beginDate.getDay() - this._weekStart) % 7;
- beginDate.setTime(beginDate.getTime() - daysToWeekStart * MSECS_IN_DAY);
+ let startsOnWeekStart = daysToWeekStart == 0;
+ let weekPadding = startsOnWeekStart ? 7 : 0;
+
+ beginDate.setTime(beginDate.getTime() - (weekPadding + daysToWeekStart) * MSECS_IN_DAY);
let iter = new Date(beginDate);
let row = 2;
- while (true) {
+ // nRows here means 6 weeks + one header + one navbar
+ let nRows = 8;
+ while (row < 8) {
let button = new St.Button({ label: iter.getDate().toString() });
let rtl = button.get_text_direction() == Clutter.TextDirection.RTL;
@@ -562,6 +586,7 @@ const Calendar = new Lang.Class({
let hasEvents = this._eventSource && this._eventSource.hasEvents(iter);
let styleClass = 'calendar-day-base calendar-day';
+
if (_isWorkDay(iter))
styleClass += ' calendar-work-day'
else
@@ -601,12 +626,9 @@ const Calendar = new Lang.Class({
}
iter.setTime(iter.getTime() + MSECS_IN_DAY);
- if (iter.getDay() == this._weekStart) {
- // We stop on the first "first day of the week" after the month we are displaying
- if (iter.getMonth() > this._selectedDate.getMonth() || iter.getYear() >
this._selectedDate.getYear())
- break;
+
+ if (iter.getDay() == this._weekStart)
row++;
- }
}
// Signal to the event source that we are interested in events
// only from this date range
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]