Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the option in Apperance > Menu Bar to show the days until the new year #221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Itsycal/Itsycal.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extern NSString * const kHighlightedDOWs;
extern NSString * const kKeyboardShortcut;
extern NSString * const kUseOutlineIcon;
extern NSString * const kShowMonthInIcon;
extern NSString * const kShowDaysUntilNewYear;
extern NSString * const kShowDayOfWeekInIcon;
extern NSString * const kShowMeetingIndicator;
extern NSString * const kAllowOutsideApplicationsFolder;
Expand Down
1 change: 1 addition & 0 deletions Itsycal/Itsycal.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
NSString * const kKeyboardShortcut = @"GlobalShortcut";
NSString * const kUseOutlineIcon = @"UseOutlineIcon";
NSString * const kShowMonthInIcon = @"ShowMonthInIcon";
NSString * const kShowDaysUntilNewYear = @"ShowDaysUntilNewYear";
NSString * const kShowDayOfWeekInIcon = @"ShowDayOfWeekInIcon";
NSString * const kShowMeetingIndicator = @"ShowMeetingIndicator";
NSString * const kAllowOutsideApplicationsFolder = @"AllowOutsideApplicationsFolder";
Expand Down
7 changes: 5 additions & 2 deletions Itsycal/PrefsAppearanceVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ - (void)loadView

// Checkboxes
NSButton *useOutlineIcon = chkbx(NSLocalizedString(@"Use outline icon", @""));
NSButton *showDaysUntilNewYear = chkbx(NSLocalizedString(@"Show how days until new year", @""));
NSButton *showMonth = chkbx(NSLocalizedString(@"Show month in icon", @""));
NSButton *showDayOfWeek = chkbx(NSLocalizedString(@"Show day of week in icon", @""));
NSButton *showEventDots = chkbx(NSLocalizedString(@"Show event dots", @""));
Expand Down Expand Up @@ -108,11 +109,12 @@ - (void)loadView
sizeSlider.maxValue = SizePreferenceLarge; // = 2
[v addSubview:sizeSlider];

MoVFLHelper *vfl = [[MoVFLHelper alloc] initWithSuperview:v metrics:@{@"m": @20, @"mm": @40} views:NSDictionaryOfVariableBindings(menubarLabel, calendarLabel, separator0, separator1, useOutlineIcon, showMonth, showDayOfWeek, showEventDots, useColoredDots, showWeeks, showLocation, _dateTimeFormat, helpButton, _hideIcon, highlight, themeLabel, themePopup, sizeMinLabel, sizeSlider, sizeMaxLabel)];
[vfl :@"V:|-m-[menubarLabel]-10-[useOutlineIcon]-[showMonth]-[showDayOfWeek]-[_dateTimeFormat]-[_hideIcon]-m-[calendarLabel]-10-[sizeSlider]-15-[themePopup]-m-[highlight]-m-[showEventDots]-[useColoredDots]-[showLocation]-[showWeeks]-m-|"];
MoVFLHelper *vfl = [[MoVFLHelper alloc] initWithSuperview:v metrics:@{@"m": @20, @"mm": @40} views:NSDictionaryOfVariableBindings(menubarLabel, calendarLabel, separator0, separator1, useOutlineIcon, showDaysUntilNewYear, showMonth, showDayOfWeek, showEventDots, useColoredDots, showWeeks, showLocation, _dateTimeFormat, helpButton, _hideIcon, highlight, themeLabel, themePopup, sizeMinLabel, sizeSlider, sizeMaxLabel)];
[vfl :@"V:|-m-[menubarLabel]-10-[useOutlineIcon]-[showDaysUntilNewYear]-[showMonth]-[showDayOfWeek]-[_dateTimeFormat]-[_hideIcon]-m-[calendarLabel]-10-[sizeSlider]-15-[themePopup]-m-[highlight]-m-[showEventDots]-[useColoredDots]-[showLocation]-[showWeeks]-m-|"];
[vfl :@"H:|-m-[menubarLabel]-[separator0]-m-|" :NSLayoutFormatAlignAllCenterY];
[vfl :@"H:|-m-[calendarLabel]-[separator1]-m-|" :NSLayoutFormatAlignAllCenterY];
[vfl :@"H:|-m-[useOutlineIcon]-(>=m)-|"];
[vfl :@"H:|-m-[showDaysUntilNewYear]-(>=m)-|"];
[vfl :@"H:|-m-[showMonth]-(>=m)-|"];
[vfl :@"H:|-m-[showDayOfWeek]-(>=m)-|"];
[vfl :@"H:|-m-[_dateTimeFormat]-[helpButton]-m-|" :NSLayoutFormatAlignAllCenterY];
Expand All @@ -129,6 +131,7 @@ - (void)loadView

// Bindings for icon preferences
[useOutlineIcon bind:@"value" toObject:[NSUserDefaultsController sharedUserDefaultsController] withKeyPath:[@"values." stringByAppendingString:kUseOutlineIcon] options:@{NSContinuouslyUpdatesValueBindingOption: @(YES)}];
[showDaysUntilNewYear bind:@"value" toObject:[NSUserDefaultsController sharedUserDefaultsController] withKeyPath:[@"values." stringByAppendingString:kShowDaysUntilNewYear] options:@{NSContinuouslyUpdatesValueBindingOption: @(YES)}];
[showMonth bind:@"value" toObject:[NSUserDefaultsController sharedUserDefaultsController] withKeyPath:[@"values." stringByAppendingString:kShowMonthInIcon] options:@{NSContinuouslyUpdatesValueBindingOption: @(YES)}];
[showDayOfWeek bind:@"value" toObject:[NSUserDefaultsController sharedUserDefaultsController] withKeyPath:[@"values." stringByAppendingString:kShowDayOfWeekInIcon] options:@{NSContinuouslyUpdatesValueBindingOption: @(YES)}];
[_hideIcon bind:@"value" toObject:[NSUserDefaultsController sharedUserDefaultsController] withKeyPath:[@"values." stringByAppendingString:kHideIcon] options:@{NSContinuouslyUpdatesValueBindingOption: @(YES)}];
Expand Down
19 changes: 19 additions & 0 deletions Itsycal/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,9 @@ - (NSString *)iconText
}
[_iconDateFormatter setDateFormat:[NSDateFormatter dateFormatFromTemplate:template options:0 locale:[NSLocale currentLocale]]];
iconText = [_iconDateFormatter stringFromDate:[NSDate new]];
} else if ([[NSUserDefaults standardUserDefaults] boolForKey:kShowDaysUntilNewYear]) {
NSInteger daysLeft = [self getDaysUntilNewYear];
iconText = [NSString stringWithFormat:@"%lu", daysLeft];
} else {
iconText = [NSString stringWithFormat:@"%zd", _moCal.todayDate.day];
}
Expand All @@ -495,6 +498,22 @@ - (NSString *)iconText
return iconText;
}

- (NSInteger)getDaysUntilNewYear
{
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *components = [gregorian components:NSCalendarUnitYear fromDate:today];

[components setDay:31];
[components setMonth:12];
NSDate *newYearsEve = [gregorian dateFromComponents:components];

NSDateComponents *daysLeftComponents = [gregorian components:NSCalendarUnitDay fromDate:today toDate:newYearsEve options:0];
NSInteger daysLeft = [daysLeftComponents day] + 1;

return daysLeft;
}

- (void)updateMenubarIcon
{
NSString *accessibilityTitle = @"Itsycal";
Expand Down