Remember last OPML export account, suggest account name for OPML export file name, allow export of inactive accounts. Issue #659 & Issue #652

This commit is contained in:
Maurice Parker 2019-05-21 15:15:26 -05:00
parent 0da916fa68
commit 4667035e61
2 changed files with 26 additions and 7 deletions

View File

@ -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)
}

View File

@ -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)
}
accountPopUpButton.menu = menu
if oneAccount.accountID == AppDefaults.exportOPMLAccountID {
accountPopUpButton.select(oneMenuItem)
}
}
}
// 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 {