From 94c9b53ab7a4f9a8fb4b30e0a3ad22fe8150fe8a Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 2 May 2020 15:51:50 -0700 Subject: [PATCH] Lazy Loading Popover! --- Clocker/Panel/PanelController.swift | 4 ++++ Clocker/Panel/ParentPanelController.swift | 21 +++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Clocker/Panel/PanelController.swift b/Clocker/Panel/PanelController.swift index 2dc8fe8..c0f5204 100644 --- a/Clocker/Panel/PanelController.swift +++ b/Clocker/Panel/PanelController.swift @@ -313,6 +313,10 @@ class PanelController: ParentPanelController { } override func showNotesPopover(forRow row: Int, relativeTo positioningRect: NSRect, andButton target: NSButton!) -> Bool { + if morePopover == nil { + morePopover = NSPopover() + } + guard let popover = morePopover else { return false } diff --git a/Clocker/Panel/ParentPanelController.swift b/Clocker/Panel/ParentPanelController.swift index 8fd9aad..9e329f5 100644 --- a/Clocker/Panel/ParentPanelController.swift +++ b/Clocker/Panel/ParentPanelController.swift @@ -36,7 +36,7 @@ class ParentPanelController: NSWindowController { private lazy var feedbackWindow: AppFeedbackWindowController = AppFeedbackWindowController.shared() - private var note: NotesPopover? + private var notePopover: NotesPopover? private lazy var oneWindow: OneWindowController? = { let preferencesStoryboard = NSStoryboard(name: "Preferences", bundle: nil) @@ -571,8 +571,8 @@ class ParentPanelController: NSWindowController { popover.animates = true - if note == nil { - note = NotesPopover(nibName: NSNib.Name.notesPopover, bundle: nil) + if notePopover == nil { + notePopover = NotesPopover(nibName: NSNib.Name.notesPopover, bundle: nil) popover.behavior = .applicationDefined popover.delegate = self } @@ -585,12 +585,12 @@ class ParentPanelController: NSWindowController { let current = defaults[correctRow] if let model = TimezoneData.customObject(from: current) { - note?.setDataSource(data: model) - note?.setRow(row: correctRow) - note?.set(timezones: defaults) + notePopover?.setDataSource(data: model) + notePopover?.setRow(row: correctRow) + notePopover?.set(timezones: defaults) - popover.contentViewController = note - note?.set(with: popover) + popover.contentViewController = notePopover + notePopover?.set(with: popover) return true } @@ -790,9 +790,10 @@ class ParentPanelController: NSWindowController { // If the popover is displayed, close it // Called when preferences are going to be displayed! func updatePopoverDisplayState() { - if note != nil, let isShown = note?.popover?.isShown, isShown { - note?.popover?.close() + if notePopover != nil, let isShown = notePopover?.popover?.isShown, isShown { + notePopover?.popover?.close() } + morePopover = nil } // MARK: Review