Skip to content

Commit

Permalink
feat(events): allow to hide tentative events leits#515
Browse files Browse the repository at this point in the history
- allows to show, hide or mark tentative events as inactive. Tentative events are maybe events where the recipient do not know if he will attend.
  • Loading branch information
jgoldhammer committed Mar 12, 2023
1 parent 6102f2f commit 98ffebd
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ MeetingBar.xcodeproj/xcuserdata/*
MeetingBar.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/*

Archive/*
build
1 change: 1 addition & 0 deletions MeetingBar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
keys: .selectedCalendarIDs, .showEventsForPeriod,
.disablePastEvents, .pastEventsAppereance,
.declinedEventsAppereance, .showPendingEvents,
.showTentativeEvents,
.allDayEvents, .nonAllDayEvents, .customRegexes,
.personalEventsAppereance, .showEventsForPeriod,
options: []
Expand Down
7 changes: 7 additions & 0 deletions MeetingBar/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ enum PendingEventsAppereance: String, Codable, CaseIterable {
case hide
}

enum TentativeEventsAppereance: String, Codable, CaseIterable {
case show
case show_inactive
case show_underlined
case hide
}

enum PastEventsAppereance: String, Codable, CaseIterable {
case show_active
case show_inactive
Expand Down
15 changes: 15 additions & 0 deletions MeetingBar/EventStores/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ func filterEvents(_ events: [MBEvent]) -> [MBEvent] {
continue // Skip this event
}
}

// Filter tentative events
switch Defaults[.showTentativeEvents] {
case .show, .show_inactive, .show_underlined:
break
case .hide:
if calendarEvent.participationStatus == .tentative {
continue // Skip this event
}
}

filteredCalendarEvents.append(calendarEvent)
}
Expand Down Expand Up @@ -261,6 +271,11 @@ func getNextEvent(events: [MBEvent]) -> MBEvent? {
if event.participationStatus == .pending, Defaults[.showPendingEvents] == .hide || Defaults[.showPendingEvents] == .show_inactive {
continue
}

// Skip event if pending events should be skipped
if event.participationStatus == .tentative, Defaults[.showTentativeEvents] == .hide || Defaults[.showTentativeEvents] == .show_inactive {
continue
}

// Skip event if canceled
if event.status == .canceled {
Expand Down
4 changes: 4 additions & 0 deletions MeetingBar/Extensions/DefaultsKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ extension Defaults.Keys {
// appearance of pending events should be shown in the statusbar and menu
static let showPendingEvents = Key<PendingEventsAppereance>("showPendingEvents", default: PendingEventsAppereance.show)

// appearance of tentative events
static let showTentativeEvents = Key<TentativeEventsAppereance>("showTentativeEvents", default: TentativeEventsAppereance.show)


static let timeFormat = Key<TimeFormat>("timeFormat", default: .military)

// Bookmarks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"preferences_appearance_events_past_title" = "Past events:";
"preferences_appearance_events_pending_title" = "Pending events";
"preferences_appearance_events_declined_title" = "Declined events:";
"preferences_appearance_events_tentative_title" = "Tentative events:";
"preferences_appearance_events_value_show" = "show";
"preferences_appearance_events_value_hide" = "hide";
"preferences_appearance_events_value_as_inactive" = "show as inactive";
Expand Down
25 changes: 25 additions & 0 deletions MeetingBar/StatusBarItemController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ class StatusBarItemController {
if nextEvent.participationStatus == .pending, Defaults[.showPendingEvents] == PendingEventsAppereance.show_underlined {
styles[NSAttributedString.Key.underlineStyle] = NSUnderlineStyle.single.rawValue | NSUnderlineStyle.patternDot.rawValue | NSUnderlineStyle.byWord.rawValue
}

if nextEvent.participationStatus == .tentative, Defaults[.showTentativeEvents] == TentativeEventsAppereance.show_underlined {
styles[NSAttributedString.Key.underlineStyle] = NSUnderlineStyle.single.rawValue | NSUnderlineStyle.patternDot.rawValue | NSUnderlineStyle.byWord.rawValue
}

menuTitle.append(NSAttributedString(string: eventTitle, attributes: styles))
} else {
Expand All @@ -226,6 +230,12 @@ class StatusBarItemController {
} else if nextEvent.participationStatus == .pending, Defaults[.showPendingEvents] == PendingEventsAppereance.show_underlined {
styles[NSAttributedString.Key.underlineStyle] = NSUnderlineStyle.single.rawValue | NSUnderlineStyle.patternDot.rawValue | NSUnderlineStyle.byWord.rawValue
}

if nextEvent.participationStatus == .tentative, Defaults[.showTentativeEvents] == TentativeEventsAppereance.show_inactive {
styles[NSAttributedString.Key.foregroundColor] = NSColor.disabledControlTextColor
} else if nextEvent.participationStatus == .tentative, Defaults[.showTentativeEvents] == TentativeEventsAppereance.show_underlined {
styles[NSAttributedString.Key.underlineStyle] = NSUnderlineStyle.single.rawValue | NSUnderlineStyle.patternDot.rawValue | NSUnderlineStyle.byWord.rawValue
}

menuTitle.append(NSAttributedString(string: title, attributes: styles))

Expand Down Expand Up @@ -434,6 +444,14 @@ class StatusBarItemController {
styles[NSAttributedString.Key.underlineStyle] = NSUnderlineStyle.single.rawValue | NSUnderlineStyle.patternDot.rawValue | NSUnderlineStyle.byWord.rawValue
}
}

if event.participationStatus == .tentative {
if Defaults[.showTentativeEvents] == TentativeEventsAppereance.show_inactive {
styles[NSAttributedString.Key.foregroundColor] = NSColor.disabledControlTextColor
} else if Defaults[.showTentativeEvents] == TentativeEventsAppereance.show_underlined {
styles[NSAttributedString.Key.underlineStyle] = NSUnderlineStyle.single.rawValue | NSUnderlineStyle.patternDot.rawValue | NSUnderlineStyle.byWord.rawValue
}
}

if event.attendees.isEmpty, Defaults[.personalEventsAppereance] == .show_inactive {
styles[NSAttributedString.Key.foregroundColor] = NSColor.disabledControlTextColor
Expand Down Expand Up @@ -467,6 +485,13 @@ class StatusBarItemController {
} else {
styles[NSAttributedString.Key.font] = NSFont.systemFont(ofSize: 14)
}

if shouldShowAsActive, Defaults[.showTentativeEvents] != TentativeEventsAppereance.show_underlined {
// add the NSTextAttachment wrapper to our full string, then add some more text.
styles[NSAttributedString.Key.font] = NSFont.boldSystemFont(ofSize: 14)
} else {
styles[NSAttributedString.Key.font] = NSFont.systemFont(ofSize: 14)
}

eventTitle.append(NSAttributedString(string: itemTitle, attributes: styles))

Expand Down
20 changes: 15 additions & 5 deletions MeetingBar/Views/Preferences/AppearanceTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ struct EventsSection: View {
@Default(.allDayEvents) var allDayEvents
@Default(.nonAllDayEvents) var nonAllDayEvents
@Default(.showPendingEvents) var showPendingEvents
@Default(.showTentativeEvents) var showTentativeEvents
@Default(.showEventsForPeriod) var showEventsForPeriod

var body: some View {
Expand All @@ -149,7 +150,13 @@ struct EventsSection: View {
Picker("preferences_appearance_events_show_events_for_title".loco(), selection: $showEventsForPeriod) {
Text("preferences_appearance_events_show_events_for_today_value".loco()).tag(ShowEventsForPeriod.today)
Text("preferences_appearance_events_show_events_for_today_tomorrow_value".loco()).tag(ShowEventsForPeriod.today_n_tomorrow)
}.frame(width: 300)
}

Picker("preferences_appearance_events_past_title".loco(), selection: $pastEventsAppereance) {
Text("preferences_appearance_events_value_show".loco()).tag(PastEventsAppereance.show_active)
Text("preferences_appearance_events_value_as_inactive".loco()).tag(PastEventsAppereance.show_inactive)
Text("preferences_appearance_events_value_hide".loco()).tag(PastEventsAppereance.hide)
}
}

HStack {
Expand All @@ -172,11 +179,14 @@ struct EventsSection: View {
Text("preferences_appearance_events_value_as_inactive".loco()).tag(PastEventsAppereance.show_inactive)
Text("preferences_appearance_events_value_hide".loco()).tag(PastEventsAppereance.hide)
}
Picker("preferences_appearance_events_past_title".loco(), selection: $pastEventsAppereance) {
Text("preferences_appearance_events_value_show".loco()).tag(PastEventsAppereance.show_active)
Text("preferences_appearance_events_value_as_inactive".loco()).tag(PastEventsAppereance.show_inactive)
Text("preferences_appearance_events_value_hide".loco()).tag(PastEventsAppereance.hide)

Picker("preferences_appearance_events_tentative_title".loco(), selection: $showTentativeEvents) {
Text("preferences_appearance_events_value_show".loco()).tag(TentativeEventsAppereance.show)
Text("preferences_appearance_events_value_as_underlined".loco()).tag(TentativeEventsAppereance.show_underlined)
Text("preferences_appearance_events_value_as_inactive".loco()).tag(TentativeEventsAppereance.show_inactive)
Text("preferences_appearance_events_value_hide".loco()).tag(TentativeEventsAppereance.hide)
}

}
HStack {
Picker("preferences_appearance_events_pending_title".loco(), selection: $showPendingEvents) {
Expand Down

0 comments on commit 98ffebd

Please sign in to comment.