From 4667035e616e7e959ef1a8ce65f15f8df1bc97be Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 21 May 2019 15:15:26 -0500 Subject: [PATCH] Remember last OPML export account, suggest account name for OPML export file name, allow export of inactive accounts. Issue #659 & Issue #652 --- Mac/AppDefaults.swift | 10 ++++++++ .../OPML/ExportOPMLWindowController.swift | 23 +++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Mac/AppDefaults.swift b/Mac/AppDefaults.swift index aa1503428..390d55ab6 100644 --- a/Mac/AppDefaults.swift +++ b/Mac/AppDefaults.swift @@ -29,6 +29,7 @@ struct AppDefaults { static let addFeedAccountID = "addFeedAccountID" static let addFolderAccountID = "addFolderAccountID" static let importOPMLAccountID = "importOPMLAccountID" + static let exportOPMLAccountID = "exportOPMLAccountID" // Hidden prefs static let showTitleOnMainWindow = "KafasisTitleMode" @@ -109,6 +110,15 @@ struct AppDefaults { } } + static var exportOPMLAccountID: String? { + get { + return string(for: Key.exportOPMLAccountID) + } + set { + setString(for: Key.exportOPMLAccountID, newValue) + } + } + static var showTitleOnMainWindow: Bool { return bool(for: Key.showTitleOnMainWindow) } diff --git a/Mac/MainWindow/OPML/ExportOPMLWindowController.swift b/Mac/MainWindow/OPML/ExportOPMLWindowController.swift index d9e997619..5b7250875 100644 --- a/Mac/MainWindow/OPML/ExportOPMLWindowController.swift +++ b/Mac/MainWindow/OPML/ExportOPMLWindowController.swift @@ -19,17 +19,23 @@ class ExportOPMLWindowController: NSWindowController { } override func windowDidLoad() { - accountPopUpButton.removeAllItems() + let menu = NSMenu() - for oneAccount in AccountManager.shared.sortedActiveAccounts { + accountPopUpButton.menu = menu + + for oneAccount in AccountManager.shared.sortedAccounts { + let oneMenuItem = NSMenuItem() oneMenuItem.title = oneAccount.nameForDisplay oneMenuItem.representedObject = oneAccount menu.addItem(oneMenuItem) + + if oneAccount.accountID == AppDefaults.exportOPMLAccountID { + accountPopUpButton.select(oneMenuItem) + } + } - accountPopUpButton.menu = menu - } // MARK: API @@ -38,8 +44,8 @@ class ExportOPMLWindowController: NSWindowController { self.hostWindow = hostWindow - if AccountManager.shared.activeAccounts.count == 1 { - let account = AccountManager.shared.activeAccounts.first! + if AccountManager.shared.accounts.count == 1 { + let account = AccountManager.shared.accounts.first! exportOPML(account: account) } else { hostWindow.beginSheet(window!) @@ -60,6 +66,7 @@ class ExportOPMLWindowController: NSWindowController { } let account = menuItem.representedObject as! Account + AppDefaults.exportOPMLAccountID = account.accountID hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK) exportOPML(account: account) @@ -75,7 +82,9 @@ class ExportOPMLWindowController: NSWindowController { panel.nameFieldLabel = NSLocalizedString("Export to:", comment: "Export OPML") panel.message = NSLocalizedString("Choose a location for the exported OPML file.", comment: "Export OPML") panel.isExtensionHidden = false - panel.nameFieldStringValue = "MySubscriptions.opml" + + let accountName = account.nameForDisplay.replacingOccurrences(of: " ", with: "").trimmingCharacters(in: .whitespaces) + panel.nameFieldStringValue = "\(accountName).opml" panel.beginSheetModal(for: hostWindow!) { result in if result == NSApplication.ModalResponse.OK, let url = panel.url {