Change extension point so that multiple of the same type can exist.
This commit is contained in:
parent
b0781c6df4
commit
14189b19e9
@ -10,8 +10,10 @@ import Foundation
|
||||
|
||||
public struct TwitterFeedProvider: FeedProvider {
|
||||
|
||||
public init() {
|
||||
|
||||
public var username: String
|
||||
|
||||
public init(username: String) {
|
||||
self.username = username
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ class ExtensionPointAddViewController: NSViewController {
|
||||
|
||||
@IBOutlet weak var tableView: NSTableView!
|
||||
|
||||
private var availableExtensionPoints = [ExtensionPoint]()
|
||||
private var availableExtensionPointTypes = [ExtensionPointType]()
|
||||
private var extensionPointAddWindowController: NSWindowController?
|
||||
|
||||
init() {
|
||||
@ -28,7 +28,7 @@ class ExtensionPointAddViewController: NSViewController {
|
||||
super.viewDidLoad()
|
||||
tableView.dataSource = self
|
||||
tableView.delegate = self
|
||||
availableExtensionPoints = ExtensionPointManager.shared.availableExtensionPoints
|
||||
availableExtensionPointTypes = ExtensionPointManager.shared.availableExtensionPointTypes
|
||||
}
|
||||
|
||||
}
|
||||
@ -38,7 +38,7 @@ class ExtensionPointAddViewController: NSViewController {
|
||||
extension ExtensionPointAddViewController: NSTableViewDataSource {
|
||||
|
||||
func numberOfRows(in tableView: NSTableView) -> Int {
|
||||
return availableExtensionPoints.count
|
||||
return availableExtensionPointTypes.count
|
||||
}
|
||||
|
||||
func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
|
||||
@ -55,9 +55,9 @@ extension ExtensionPointAddViewController: NSTableViewDelegate {
|
||||
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
|
||||
|
||||
if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "Cell"), owner: nil) as? ExtensionPointAddTableCellView {
|
||||
let extensionPoint = availableExtensionPoints[row]
|
||||
cell.titleLabel?.stringValue = extensionPoint.title
|
||||
cell.imageView?.image = extensionPoint.templateImage
|
||||
let extensionPointType = availableExtensionPointTypes[row]
|
||||
cell.titleLabel?.stringValue = extensionPointType.title
|
||||
cell.imageView?.image = extensionPointType.templateImage
|
||||
return cell
|
||||
}
|
||||
return nil
|
||||
|
@ -9,12 +9,65 @@
|
||||
import Foundation
|
||||
import RSCore
|
||||
|
||||
protocol ExtensionPoint {
|
||||
enum ExtensionPointType {
|
||||
case marsEdit
|
||||
case microblog
|
||||
case twitter
|
||||
|
||||
/// The title of the command.
|
||||
var title: String { get }
|
||||
var title: String {
|
||||
switch self {
|
||||
case .marsEdit:
|
||||
return NSLocalizedString("MarsEdit", comment: "MarsEdit")
|
||||
case .microblog:
|
||||
return NSLocalizedString("Micro.blog", comment: "Micro.blog")
|
||||
case .twitter:
|
||||
return NSLocalizedString("Twitter", comment: "Twitter")
|
||||
}
|
||||
|
||||
/// The template image for the command.
|
||||
var templateImage: RSImage { get }
|
||||
}
|
||||
|
||||
var templateImage: RSImage {
|
||||
switch self {
|
||||
case .marsEdit:
|
||||
return AppAssets.extensionPointMarsEdit
|
||||
case .microblog:
|
||||
return AppAssets.extensionPointMicroblog
|
||||
case .twitter:
|
||||
return AppAssets.extensionPointTwitter
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
enum ExtensionPointIdentifer {
|
||||
case marsEdit
|
||||
case microblog
|
||||
case twitter(String)
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
case .marsEdit:
|
||||
return ExtensionPointType.marsEdit.title
|
||||
case .microblog:
|
||||
return ExtensionPointType.microblog.title
|
||||
case .twitter(let username):
|
||||
return "\(ExtensionPointType.microblog.title) (\(username))"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protocol ExtensionPoint {
|
||||
|
||||
var extensionPointType: ExtensionPointType { get }
|
||||
var extensionPointID: ExtensionPointIdentifer { get }
|
||||
|
||||
}
|
||||
|
||||
extension ExtensionPoint {
|
||||
|
||||
var title: String {
|
||||
return extensionPointID.title
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,34 +14,22 @@ struct ExtensionPointManager {
|
||||
|
||||
static let shared = ExtensionPointManager()
|
||||
|
||||
let marsEdit = SendToMarsEditCommand()
|
||||
let microblog = SendToMicroBlogCommand()
|
||||
let twitter = TwitterFeedProvider()
|
||||
|
||||
let availableExtensionPoints: [ExtensionPoint]
|
||||
let activeSendToCommands: [SendToCommand]
|
||||
let activeFeedProviders: [FeedProvider]
|
||||
let availableExtensionPointTypes: [ExtensionPointType]
|
||||
// let activeSendToCommands: [SendToCommand]
|
||||
// let activeFeedProviders: [FeedProvider]
|
||||
|
||||
init() {
|
||||
#if os(macOS)
|
||||
#if DEBUG
|
||||
availableExtensionPoints = [marsEdit, microblog, twitter]
|
||||
activeSendToCommands = [marsEdit, microblog]
|
||||
activeFeedProviders = [twitter]
|
||||
availableExtensionPointTypes = [.marsEdit, .microblog, .twitter]
|
||||
#else
|
||||
availableExtensionPoints = [marsEdit, microblog, twitter]
|
||||
activeSendToCommands = [marsEdit, microblog]
|
||||
activeFeedProviders = [twitter]
|
||||
availableExtensionPointTypes = [.marsEdit, .microblog, .twitter]
|
||||
#endif
|
||||
#else
|
||||
#if DEBUG
|
||||
availableExtensionPoints = [twitter]
|
||||
activeSendToCommands = []()
|
||||
activeFeedProviders = [twitter]
|
||||
availableExtensionPoints = [.twitter]
|
||||
#else
|
||||
availableExtensionPoints = [twitter]
|
||||
activeSendToCommands = []()
|
||||
activeFeedProviders = [twitter]
|
||||
availableExtensionPoints = [.twitter]
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
@ -12,9 +12,9 @@ import Articles
|
||||
|
||||
final class SendToMarsEditCommand: ExtensionPoint, SendToCommand {
|
||||
|
||||
let title = NSLocalizedString("MarsEdit", comment: "MarsEdit")
|
||||
let templateImage = AppAssets.extensionPointMarsEdit
|
||||
|
||||
let extensionPointType = ExtensionPointType.marsEdit
|
||||
let extensionPointID = ExtensionPointIdentifer.marsEdit
|
||||
|
||||
var image: NSImage? {
|
||||
return appToUse()?.icon ?? nil
|
||||
}
|
||||
|
@ -14,9 +14,9 @@ import RSCore
|
||||
|
||||
final class SendToMicroBlogCommand: ExtensionPoint, SendToCommand {
|
||||
|
||||
let title = NSLocalizedString("Micro.blog", comment: "Micro.blog")
|
||||
let templateImage = AppAssets.extensionPointMicroblog
|
||||
|
||||
let extensionPointType = ExtensionPointType.microblog
|
||||
let extensionPointID = ExtensionPointIdentifer.microblog
|
||||
|
||||
var image: NSImage? {
|
||||
return microBlogApp.icon
|
||||
}
|
||||
|
@ -12,12 +12,13 @@ import RSCore
|
||||
|
||||
extension TwitterFeedProvider: ExtensionPoint {
|
||||
|
||||
var title: String {
|
||||
return NSLocalizedString("Twitter", comment: "Twitter")
|
||||
var extensionPointType: ExtensionPointType {
|
||||
return ExtensionPointType.twitter
|
||||
}
|
||||
|
||||
var extensionPointID: ExtensionPointIdentifer {
|
||||
return ExtensionPointIdentifer.twitter(username)
|
||||
}
|
||||
|
||||
var templateImage: RSImage {
|
||||
return AppAssets.extensionPointTwitter
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user