Remember account selection for Add Feed and Add Folder dialogs. Issue #651 & Issue #654

This commit is contained in:
Maurice Parker 2019-05-21 09:36:33 -05:00
parent e6680a23b9
commit fb33008b36
3 changed files with 53 additions and 4 deletions

View File

@ -26,6 +26,8 @@ struct AppDefaults {
static let openInBrowserInBackground = "openInBrowserInBackground"
static let mainWindowWidths = "mainWindowWidths"
static let refreshInterval = "refreshInterval"
static let addFeedAccountID = "addFeedAccountID"
static let addFolderAccountID = "addFolderAccountID"
// Hidden prefs
static let showTitleOnMainWindow = "KafasisTitleMode"
@ -79,6 +81,24 @@ struct AppDefaults {
}
}
static var addFeedAccountID: String? {
get {
return string(for: Key.addFeedAccountID)
}
set {
setString(for: Key.addFeedAccountID, newValue)
}
}
static var addFolderAccountID: String? {
get {
return string(for: Key.addFolderAccountID)
}
set {
setString(for: Key.addFolderAccountID, newValue)
}
}
static var showTitleOnMainWindow: Bool {
return bool(for: Key.showTitleOnMainWindow)
}
@ -178,6 +198,14 @@ private extension AppDefaults {
setInt(for: key, fontSize.rawValue)
}
static func string(for key: String) -> String? {
return UserDefaults.standard.string(forKey: key)
}
static func setString(for key: String, _ value: String?) {
UserDefaults.standard.set(value, forKey: key)
}
static func bool(for key: String) -> Bool {
return UserDefaults.standard.bool(forKey: key)
}

View File

@ -71,6 +71,10 @@ class AddFeedWindowController : NSWindowController {
folderPopupButton.menu = FolderTreeMenu.createFolderPopupMenu(with: folderTreeController.rootNode)
if let account = initialAccount {
FolderTreeMenu.select(account: account, folder: initialFolder, in: folderPopupButton)
} else if let accountID = AppDefaults.addFeedAccountID {
if let account = AccountManager.shared.existingAccount(with: accountID) {
FolderTreeMenu.select(account: account, folder: nil, in: folderPopupButton)
}
}
updateUI()
@ -94,8 +98,16 @@ class AddFeedWindowController : NSWindowController {
cancelSheet()
return
}
let container = selectedContainer()!
if let selectedAccount = container as? Account {
AppDefaults.addFeedAccountID = selectedAccount.accountID
} else if let selectedFolder = container as? Folder, let selectedAccount = selectedFolder.account {
AppDefaults.addFeedAccountID = selectedAccount.accountID
}
delegate?.addFeedWindowController(self, userEnteredURL: url, userEnteredTitle: userEnteredTitle, container: selectedContainer()!)
delegate?.addFeedWindowController(self, userEnteredURL: url, userEnteredTitle: userEnteredTitle, container: container)
}
@IBAction func localShowFeedList(_ sender: Any?) {

View File

@ -37,26 +37,35 @@ class AddFolderWindowController : NSWindowController {
// MARK: NSViewController
override func windowDidLoad() {
let preferredAccountID = AppDefaults.addFolderAccountID
accountPopupButton.removeAllItems()
let menu = NSMenu()
accountPopupButton.menu = menu
for oneAccount in AccountManager.shared.sortedActiveAccounts {
let oneMenuItem = NSMenuItem()
oneMenuItem.title = oneAccount.nameForDisplay
oneMenuItem.representedObject = oneAccount
menu.addItem(oneMenuItem)
if oneAccount.accountID == preferredAccountID {
accountPopupButton.select(oneMenuItem)
}
}
accountPopupButton.menu = menu
}
// MARK: Private
private func addFolderIfNeeded() {
guard let menuItem = accountPopupButton.selectedItem else {
return
}
let account = menuItem.representedObject as! Account
AppDefaults.addFolderAccountID = account.accountID
let folderName = self.folderNameTextField.stringValue
if folderName.isEmpty {