mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
implement 'current article' property of the application
Also, fix the unique-id based accessors (the four byte code for id was wrong in the sdef) Add valueIn<Key>WithUniqueID accessors Add a few protocols and protocol implementations for the AppDelegate and MainWindowControllor so as to expose needed functionality for scriptability
This commit is contained in:
@@ -20,27 +20,74 @@ extension NSApplication : ScriptingObjectContainer {
|
||||
return "application"
|
||||
}
|
||||
|
||||
@objc(currentArticle)
|
||||
func currentArticle() -> ScriptableArticle? {
|
||||
var scriptableArticle: ScriptableArticle?
|
||||
if let currentArticle = appDelegate.scriptingCurrentArticle {
|
||||
if let feed = currentArticle.feed {
|
||||
let scriptableFeed = ScriptableFeed(feed, container:self)
|
||||
scriptableArticle = ScriptableArticle(currentArticle, container:scriptableFeed)
|
||||
}
|
||||
}
|
||||
return scriptableArticle
|
||||
}
|
||||
|
||||
@objc(selectedArticles)
|
||||
func selectedArticles() -> NSArray {
|
||||
let articles = appDelegate.scriptingSelectedArticles
|
||||
let scriptableArticles:[ScriptableArticle] = articles.compactMap { article in
|
||||
if let feed = article.feed {
|
||||
let scriptableFeed = ScriptableFeed(feed, container:self)
|
||||
return ScriptableArticle(article, container:scriptableFeed)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return scriptableArticles as NSArray
|
||||
}
|
||||
|
||||
// MARK: --- scriptable elements ---
|
||||
|
||||
@objc(accounts)
|
||||
func accounts() -> NSArray {
|
||||
let accounts = AccountManager.shared.accounts
|
||||
return accounts.map { ScriptableAccount($0) } as NSArray
|
||||
}
|
||||
|
||||
@objc(valueInAccountsWithUniqueID:)
|
||||
func valueInAccounts(withUniqueID id:String) -> ScriptableAccount? {
|
||||
let accounts = AccountManager.shared.accounts
|
||||
guard let account = accounts.first(where:{$0.accountID == id}) else { return nil }
|
||||
return ScriptableAccount(account)
|
||||
}
|
||||
|
||||
/*
|
||||
accessing feeds from the application object skips the 'account' containment hierarchy
|
||||
this allows a script like 'articles of feed "The Shape of Everything"' as a shorthand
|
||||
for 'articles of feed "The Shape of Everything" of account "On My Mac"'
|
||||
*/
|
||||
@objc(feeds)
|
||||
func feeds() -> NSArray {
|
||||
*/
|
||||
|
||||
func allFeeds() -> [Feed] {
|
||||
let accounts = AccountManager.shared.accounts
|
||||
let emptyFeeds:[Feed] = []
|
||||
let feeds = accounts.reduce(emptyFeeds) { (result, nthAccount) -> [Feed] in
|
||||
return accounts.reduce(emptyFeeds) { (result, nthAccount) -> [Feed] in
|
||||
let accountFeeds = nthAccount.children.compactMap { $0 as? Feed }
|
||||
return result + accountFeeds
|
||||
}
|
||||
}
|
||||
|
||||
@objc(feeds)
|
||||
func feeds() -> NSArray {
|
||||
let feeds = self.allFeeds()
|
||||
return feeds.map { ScriptableFeed($0, container:self) } as NSArray
|
||||
}
|
||||
|
||||
@objc(valueInFeedsWithUniqueID:)
|
||||
func valueInFeeds(withUniqueID id:String) -> ScriptableFeed? {
|
||||
let feeds = self.allFeeds()
|
||||
guard let feed = feeds.first(where:{$0.feedID == id}) else { return nil }
|
||||
return ScriptableFeed(feed, container:self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user