Skip to content

Commit

Permalink
Добален отступ пунктам без иконки, прошедшие события показываются серым
Browse files Browse the repository at this point in the history
  • Loading branch information
Doka-NT committed Jun 3, 2024
1 parent 5e2aa98 commit 1902517
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions CalendarMenuApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

// Извлекаем URL из описания события
let menuItem: NSMenuItem
if let description = event.notes,
let url = extractURL(from: description),
let urlString = url.absoluteString.lowercased() as NSString?,
Expand All @@ -67,17 +68,27 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let phoneMenuItem = NSMenuItem(title: eventTitle, action: #selector(openEvent(_:)), keyEquivalent: "")
phoneMenuItem.representedObject = event
phoneMenuItem.image = phoneIcon
menu.addItem(phoneMenuItem)
menuItem = phoneMenuItem
} else {
// Добавляем обычный пункт меню без иконки
let menuItem = NSMenuItem(title: eventTitle, action: #selector(openEvent(_:)), keyEquivalent: "")
menuItem = NSMenuItem(title: eventTitle, action: #selector(openEvent(_:)), keyEquivalent: "")
menuItem.representedObject = event
menu.addItem(menuItem)
menuItem.indentationLevel = 2
}

if event.endDate < Date() {
menuItem.attributedTitle = NSAttributedString(string: eventTitle, attributes: [.foregroundColor: NSColor.lightGray])
}

// Добавление кружочка с цветом календаря
let colorCircle = createColorCircle(for: event.calendar)
menu.addItem(menuItem)
}
}
}

menu.addItem(NSMenuItem.separator()) // Разделитель между событиями и кнопкой Quit

let quitMenuItem = NSMenuItem(title: "Quit", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")
menu.addItem(quitMenuItem)

Expand Down Expand Up @@ -123,5 +134,16 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
return nil
}

func createColorCircle(for calendar: EKCalendar) -> NSImage {
let size = NSSize(width: 10, height: 10)
let image = NSImage(size: size)
image.lockFocus()
calendar.color.setFill()
let circle = NSBezierPath(ovalIn: NSRect(origin: .zero, size: size))
circle.fill()
image.unlockFocus()
return image
}

}

0 comments on commit 1902517

Please sign in to comment.