From 06b0e35739ec10196381f5c8d596864e30c1b57a Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 23 Oct 2019 22:00:14 -0700 Subject: [PATCH] Move Protocol declaration to top of ExportOPMLAccessoryViewController.swift. As critical API, it needs to be easy to spot. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Create separation extensions — one for protocol conformance, one for private methods — ExportOPMLController. Make minor code formatting change: instead of { return } — which is hard to set a breakpoint on — move the return to its own line. Remove an internal access qualifier, since internal is default and implied. --- .../ExportOPMLAccessoryViewController.swift | 7 ++-- .../OPML/ExportOPMLController.swift | 37 ++++++++++++------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Mac/MainWindow/OPML/ExportOPMLAccessoryViewController.swift b/Mac/MainWindow/OPML/ExportOPMLAccessoryViewController.swift index 3c7779198..d558d7da0 100644 --- a/Mac/MainWindow/OPML/ExportOPMLAccessoryViewController.swift +++ b/Mac/MainWindow/OPML/ExportOPMLAccessoryViewController.swift @@ -9,6 +9,10 @@ import AppKit import Account +protocol ExportOPMLAccessoryViewControllerDelegate: class { + func selectedAccountDidChange(_ accessoryViewController: ExportOPMLAccessoryViewController) +} + class ExportOPMLAccessoryViewController: NSViewController { @IBOutlet weak var accountPopUpButton: NSPopUpButton! @@ -56,6 +60,3 @@ class ExportOPMLAccessoryViewController: NSViewController { } } -protocol ExportOPMLAccessoryViewControllerDelegate: class { - func selectedAccountDidChange(_ accessoryViewController: ExportOPMLAccessoryViewController) -} diff --git a/Mac/MainWindow/OPML/ExportOPMLController.swift b/Mac/MainWindow/OPML/ExportOPMLController.swift index 87530df3a..eb3fae3b0 100644 --- a/Mac/MainWindow/OPML/ExportOPMLController.swift +++ b/Mac/MainWindow/OPML/ExportOPMLController.swift @@ -9,7 +9,7 @@ import AppKit import Account -class ExportOPMLController: ExportOPMLAccessoryViewControllerDelegate { +class ExportOPMLController { weak var savePanel: NSSavePanel? @@ -33,7 +33,9 @@ class ExportOPMLController: ExportOPMLAccessoryViewControllerDelegate { panel.beginSheetModal(for: hostWindow) { result in if result == NSApplication.ModalResponse.OK, let url = panel.url { DispatchQueue.main.async { - guard let account = accessoryViewController.selectedAccount else { return } + guard let account = accessoryViewController.selectedAccount else { + return + } let filename = url.lastPathComponent let opmlString = OPMLExporter.OPMLString(with: account, title: filename) do { @@ -45,22 +47,31 @@ class ExportOPMLController: ExportOPMLAccessoryViewControllerDelegate { } } } - } +} - private func updateNameFieldStringValueIfAppropriate(savePanel panel: NSSavePanel, from accessoryViewController: ExportOPMLAccessoryViewController, force: Bool = false) { +extension ExportOPMLController: ExportOPMLAccessoryViewControllerDelegate { - if !force && !panel.nameFieldStringValue.hasPrefix("Subscriptions-") { return } - - guard let account = accessoryViewController.selectedAccount else { return } - let accountName = account.nameForDisplay.replacingOccurrences(of: " ", with: "").trimmingCharacters(in: .whitespaces) - panel.nameFieldStringValue = "Subscriptions-\(accountName).opml" - - } - - internal func selectedAccountDidChange(_ accessoryViewController: ExportOPMLAccessoryViewController) { + func selectedAccountDidChange(_ accessoryViewController: ExportOPMLAccessoryViewController) { if let savePanel = savePanel { self.updateNameFieldStringValueIfAppropriate(savePanel: savePanel, from: accessoryViewController) } } } + +private extension ExportOPMLController { + + func updateNameFieldStringValueIfAppropriate(savePanel panel: NSSavePanel, from accessoryViewController: ExportOPMLAccessoryViewController, force: Bool = false) { + + if !force && !panel.nameFieldStringValue.hasPrefix("Subscriptions-") { + return + } + + guard let account = accessoryViewController.selectedAccount else { + return + } + let accountName = account.nameForDisplay.replacingOccurrences(of: " ", with: "").trimmingCharacters(in: .whitespaces) + panel.nameFieldStringValue = "Subscriptions-\(accountName).opml" + + } +}