From aad283f330eb6061246688b7087d975b6064df7b Mon Sep 17 00:00:00 2001 From: Reza Moallemi Date: Mon, 21 Mar 2022 17:47:13 +0100 Subject: [PATCH] Ability to show or hide month border in calendar view --- Itsycal/AppDelegate.m | 1 + Itsycal/Itsycal.h | 1 + Itsycal/Itsycal.m | 1 + Itsycal/MoCalendar.h | 3 +++ Itsycal/MoCalendar.m | 12 +++++++++++- Itsycal/PrefsAppearanceVC.m | 9 +++++++-- Itsycal/ViewController.m | 1 + 7 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Itsycal/AppDelegate.m b/Itsycal/AppDelegate.m index 9070ba1b..d809c84a 100644 --- a/Itsycal/AppDelegate.m +++ b/Itsycal/AppDelegate.m @@ -37,6 +37,7 @@ + (void)initialize kShowMonthInIcon: @(NO), kShowDayOfWeekInIcon: @(NO), kShowEventDots: @(YES), + kShowMonthBorder: @(YES), kUseColoredDots: @(YES), kThemePreference: @0, // System=0, Light=1, Dark=2 kHideIcon: @(NO) diff --git a/Itsycal/Itsycal.h b/Itsycal/Itsycal.h index 3da6e401..f04d6a4d 100644 --- a/Itsycal/Itsycal.h +++ b/Itsycal/Itsycal.h @@ -24,5 +24,6 @@ extern NSString * const kAllowOutsideApplicationsFolder; extern NSString * const kClockFormat; extern NSString * const kHideIcon; extern NSString * const kShowLocation; +extern NSString * const kShowMonthBorder; extern NSString * const kShowEventDots; extern NSString * const kUseColoredDots; diff --git a/Itsycal/Itsycal.m b/Itsycal/Itsycal.m index 19026ada..5f0eb750 100644 --- a/Itsycal/Itsycal.m +++ b/Itsycal/Itsycal.m @@ -23,5 +23,6 @@ NSString * const kClockFormat = @"ClockFormat"; NSString * const kHideIcon = @"HideIcon"; NSString * const kShowLocation = @"ShowLocation"; +NSString * const kShowMonthBorder = @"kShowMonthBorder"; NSString * const kShowEventDots = @"kShowEventDots"; NSString * const kUseColoredDots = @"UseColoredDots"; diff --git a/Itsycal/MoCalendar.h b/Itsycal/MoCalendar.h index a54dc74d..923cedc0 100644 --- a/Itsycal/MoCalendar.h +++ b/Itsycal/MoCalendar.h @@ -57,6 +57,9 @@ typedef enum : NSInteger { // Should calendar show dots under days with events? @property (nonatomic) BOOL showEventDots; +// Should calendar show border around each month? +@property (nonatomic) BOOL showMonthBorder; + // Should event dots use calendar colors? @property (nonatomic) BOOL useColoredDots; diff --git a/Itsycal/MoCalendar.m b/Itsycal/MoCalendar.m index 4cad442e..81ae35ba 100644 --- a/Itsycal/MoCalendar.m +++ b/Itsycal/MoCalendar.m @@ -228,6 +228,12 @@ - (void)setShowEventDots:(BOOL)showEventDots [self reloadData]; } +- (void)setShowMonthBorder:(BOOL)showMonthBorder +{ + _showMonthBorder = showMonthBorder; + [self reloadData]; +} + - (void)setUseColoredDots:(BOOL)useColoredDots { _useColoredDots = useColoredDots; @@ -806,7 +812,11 @@ - (void)drawRect:(NSRect)dirtyRect NSBezierPath *outlinePath = [self bezierPathWithStartCell:_monthStartCell endCell:_monthEndCell radius:radius inset:0 useRects:NO]; - [Theme.currentMonthOutlineColor set]; + if (_showMonthBorder) { + [Theme.currentMonthOutlineColor set]; + } else { + [NSColor.clearColor set]; + } [outlinePath setLineWidth:1.5]; [outlinePath stroke]; } diff --git a/Itsycal/PrefsAppearanceVC.m b/Itsycal/PrefsAppearanceVC.m index 8f75d7ff..323d5c37 100644 --- a/Itsycal/PrefsAppearanceVC.m +++ b/Itsycal/PrefsAppearanceVC.m @@ -53,6 +53,7 @@ - (void)loadView NSButton *useColoredDots = chkbx(NSLocalizedString(@"Use colored dots", @"")); NSButton *showWeeks = chkbx(NSLocalizedString(@"Show calendar weeks", @"")); NSButton *showLocation = chkbx(NSLocalizedString(@"Show event location", @"")); + NSButton *showMonthBorder = chkbx(NSLocalizedString(@"Show month border", @"")); _hideIcon = chkbx(NSLocalizedString(@"Hide icon", @"")); // Datetime format text field @@ -108,8 +109,8 @@ - (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, showMonth, showDayOfWeek, showMonthBorder, 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-[showMonthBorder]-[showEventDots]-[useColoredDots]-[showLocation]-[showWeeks]-m-|"]; [vfl :@"H:|-m-[menubarLabel]-[separator0]-m-|" :NSLayoutFormatAlignAllCenterY]; [vfl :@"H:|-m-[calendarLabel]-[separator1]-m-|" :NSLayoutFormatAlignAllCenterY]; [vfl :@"H:|-m-[useOutlineIcon]-(>=m)-|"]; @@ -120,6 +121,7 @@ - (void)loadView [vfl :@"H:|-m-[highlight]-(>=m)-|"]; [vfl :@"H:|-(>=m)-[sizeMinLabel]-[sizeSlider(90)]-[sizeMaxLabel]-(>=m)-|" :NSLayoutFormatAlignAllCenterY]; [vfl :@"H:|-m-[themeLabel]-[themePopup]-(>=m)-|" :NSLayoutFormatAlignAllFirstBaseline]; + [vfl :@"H:|-m-[showMonthBorder]-(>=m)-|"]; [vfl :@"H:|-m-[showEventDots]-(>=m)-|"]; [vfl :@"H:|-mm-[useColoredDots]-(>=m)-|"]; [vfl :@"H:|-m-[showWeeks]-(>=m)-|"]; @@ -153,6 +155,9 @@ - (void)loadView // Bindings for showLocation preference [showLocation bind:@"value" toObject:[NSUserDefaultsController sharedUserDefaultsController] withKeyPath:[@"values." stringByAppendingString:kShowLocation] options:@{NSContinuouslyUpdatesValueBindingOption: @(YES)}]; + + // Bindings for showMonthBorder preference + [showMonthBorder bind:@"value" toObject:[NSUserDefaultsController sharedUserDefaultsController] withKeyPath:[@"values." stringByAppendingString:kShowMonthBorder] options:@{NSContinuouslyUpdatesValueBindingOption: @(YES)}]; // Bindings for highlight picker [highlight bind:@"weekStartDOW" toObject:[NSUserDefaultsController sharedUserDefaultsController] withKeyPath:[@"values." stringByAppendingString:kWeekStartDOW] options:@{NSContinuouslyUpdatesValueBindingOption: @(YES)}]; diff --git a/Itsycal/ViewController.m b/Itsycal/ViewController.m index 87582fc5..bbff2d03 100644 --- a/Itsycal/ViewController.m +++ b/Itsycal/ViewController.m @@ -146,6 +146,7 @@ - (void)viewDidLoad [_moCal bind:@"highlightedDOWs" toObject:[NSUserDefaultsController sharedUserDefaultsController] withKeyPath:[@"values." stringByAppendingString:kHighlightedDOWs] options:@{NSContinuouslyUpdatesValueBindingOption: @(YES)}]; [_moCal bind:@"weekStartDOW" toObject:[NSUserDefaultsController sharedUserDefaultsController] withKeyPath:[@"values." stringByAppendingString:kWeekStartDOW] options:@{NSContinuouslyUpdatesValueBindingOption: @(YES)}]; [_agendaVC bind:@"showLocation" toObject:[NSUserDefaultsController sharedUserDefaultsController] withKeyPath:[@"values." stringByAppendingString:kShowLocation] options:@{NSContinuouslyUpdatesValueBindingOption: @(YES)}]; + [_moCal bind:@"showMonthBorder" toObject:[NSUserDefaultsController sharedUserDefaultsController] withKeyPath:[@"values." stringByAppendingString:kShowMonthBorder] options:@{NSContinuouslyUpdatesValueBindingOption: @(YES)}]; // A very ugly and questionable hack. Maybe it doesn't work. It // shouldn't work. But I think it might. Somehow prevents(?!?)