Change how ExtensionPoint titles are handled.
This commit is contained in:
parent
ad6d5ef7ed
commit
df79da291f
|
@ -12,10 +12,25 @@ import OAuthSwift
|
|||
|
||||
public struct TwitterFeedProvider {
|
||||
|
||||
public var username: String
|
||||
public var userID: String
|
||||
public var screenName: String
|
||||
|
||||
public init(tokenSuccess: OAuthSwift.TokenSuccess) {
|
||||
// TODO: beef this up
|
||||
userID = tokenSuccess.parameters["user_id"] as? String ?? ""
|
||||
screenName = tokenSuccess.parameters["screen_name"] as? String ?? ""
|
||||
|
||||
// let token = tokenSuccess.credential.oauthToken
|
||||
// let secret = tokenSuccess.credential.oauthTokenSecret
|
||||
|
||||
// TODO: save credentials here
|
||||
}
|
||||
|
||||
public init(username: String) {
|
||||
self.username = username
|
||||
self.userID = username
|
||||
self.screenName = "Stored Somewhere"
|
||||
|
||||
// TODO: load credentials here
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,20 +26,20 @@
|
|||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<stackView distribution="fill" orientation="horizontal" alignment="bottom" spacing="19" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Z8D-OO-XZd">
|
||||
<rect key="frame" x="69" y="200" width="189" height="38"/>
|
||||
<rect key="frame" x="85" y="208" width="157" height="30"/>
|
||||
<subviews>
|
||||
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="I6P-Q2-DtA">
|
||||
<rect key="frame" x="0.0" y="0.0" width="36" height="36"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="28" height="28"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="36" id="HqU-9L-bqb"/>
|
||||
<constraint firstAttribute="height" constant="36" id="bpI-uD-bzZ"/>
|
||||
<constraint firstAttribute="width" constant="28" id="HqU-9L-bqb"/>
|
||||
<constraint firstAttribute="height" constant="28" id="bpI-uD-bzZ"/>
|
||||
</constraints>
|
||||
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="NSAdvanced" id="iCo-JD-zZy"/>
|
||||
</imageView>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="d0R-Cs-axs">
|
||||
<rect key="frame" x="53" y="0.0" width="138" height="38"/>
|
||||
<rect key="frame" x="45" y="0.0" width="114" height="30"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="Extension" id="CGj-bV-rXW">
|
||||
<font key="font" metaFont="system" size="32"/>
|
||||
<font key="font" metaFont="system" size="26"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
|
@ -55,7 +55,7 @@
|
|||
</customSpacing>
|
||||
</stackView>
|
||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tK2-QL-hvM">
|
||||
<rect key="frame" x="31" y="168" width="264" height="16"/>
|
||||
<rect key="frame" x="31" y="176" width="264" height="16"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="260" id="GRp-qY-UP1"/>
|
||||
</constraints>
|
||||
|
@ -70,7 +70,9 @@
|
|||
<constraint firstItem="tK2-QL-hvM" firstAttribute="top" secondItem="Z8D-OO-XZd" secondAttribute="bottom" constant="16" id="3Ww-vg-yg7"/>
|
||||
<constraint firstItem="Z8D-OO-XZd" firstAttribute="top" secondItem="jT6-Hh-gWM" secondAttribute="top" constant="16" id="3hP-9H-3IX"/>
|
||||
<constraint firstItem="tK2-QL-hvM" firstAttribute="centerX" secondItem="jT6-Hh-gWM" secondAttribute="centerX" id="7ik-M6-Wmx"/>
|
||||
<constraint firstItem="Z8D-OO-XZd" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="jT6-Hh-gWM" secondAttribute="leading" constant="8" id="U8D-q2-eyi"/>
|
||||
<constraint firstItem="Z8D-OO-XZd" firstAttribute="centerX" secondItem="jT6-Hh-gWM" secondAttribute="centerX" id="XZC-Yp-uT5"/>
|
||||
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="Z8D-OO-XZd" secondAttribute="trailing" constant="8" id="pok-cn-NFH"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</tabViewItem>
|
||||
|
|
|
@ -15,11 +15,11 @@ class ExtensionPointDetailViewController: NSViewController {
|
|||
@IBOutlet weak var descriptionLabel: NSTextField!
|
||||
|
||||
private var extensionPointWindowController: NSWindowController?
|
||||
private var extensionPointID: ExtensionPointIdentifer?
|
||||
private var extensionPoint: ExtensionPoint?
|
||||
|
||||
init(extensionPointID: ExtensionPointIdentifer) {
|
||||
init(extensionPoint: ExtensionPoint) {
|
||||
super.init(nibName: "ExtensionPointDetail", bundle: nil)
|
||||
self.extensionPointID = extensionPointID
|
||||
self.extensionPoint = extensionPoint
|
||||
}
|
||||
|
||||
public required init?(coder: NSCoder) {
|
||||
|
@ -28,10 +28,10 @@ class ExtensionPointDetailViewController: NSViewController {
|
|||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
guard let extensionPointID = extensionPointID else { return }
|
||||
imageView.image = extensionPointID.templateImage
|
||||
titleLabel.stringValue = extensionPointID.title
|
||||
descriptionLabel.attributedStringValue = extensionPointID.description
|
||||
guard let extensionPoint = extensionPoint else { return }
|
||||
imageView.image = extensionPoint.templateImage
|
||||
titleLabel.stringValue = extensionPoint.title
|
||||
descriptionLabel.attributedStringValue = extensionPoint.description
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -116,13 +116,12 @@ private extension ExtensionPointEnableWindowController {
|
|||
oauth1.authorizeURLHandler = self
|
||||
|
||||
oauth1.authorize(withCallbackURL: callbackURL) { [weak self] result in
|
||||
guard let self = self else { return }
|
||||
guard let self = self, let extensionPointType = self.extensionPointType else { return }
|
||||
|
||||
switch result {
|
||||
case .success(let tokenSuccess):
|
||||
|
||||
// let token = tokenSuccess.credential.oauthToken
|
||||
// let secret = tokenSuccess.credential.oauthTokenSecret
|
||||
ExtensionPointManager.shared.activateExtensionPoint(extensionPointType, tokenSuccess: tokenSuccess)
|
||||
let screenName = tokenSuccess.parameters["screen_name"] as? String ?? ""
|
||||
print("******************* \(screenName)")
|
||||
self.hostWindow!.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK)
|
||||
|
|
|
@ -14,7 +14,7 @@ final class ExtensionPointPreferencesViewController: NSViewController {
|
|||
@IBOutlet weak var detailView: NSView!
|
||||
@IBOutlet weak var deleteButton: NSButton!
|
||||
|
||||
private var activeExtensionPointIDs = [ExtensionPointIdentifer]()
|
||||
private var activeExtensionPoints = [ExtensionPoint]()
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
@ -42,8 +42,8 @@ final class ExtensionPointPreferencesViewController: NSViewController {
|
|||
return
|
||||
}
|
||||
|
||||
let extensionPointID = activeExtensionPointIDs[tableView.selectedRow]
|
||||
ExtensionPointManager.shared.deactivateExtensionPoint(extensionPointID)
|
||||
let extensionPoint = activeExtensionPoints[tableView.selectedRow]
|
||||
ExtensionPointManager.shared.deactivateExtensionPoint(extensionPoint.extensionPointID)
|
||||
|
||||
showController(ExtensionPointAddViewController())
|
||||
}
|
||||
|
@ -54,11 +54,11 @@ final class ExtensionPointPreferencesViewController: NSViewController {
|
|||
extension ExtensionPointPreferencesViewController: NSTableViewDataSource {
|
||||
|
||||
func numberOfRows(in tableView: NSTableView) -> Int {
|
||||
return activeExtensionPointIDs.count
|
||||
return activeExtensionPoints.count
|
||||
}
|
||||
|
||||
func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
|
||||
return activeExtensionPointIDs[row]
|
||||
return activeExtensionPoints[row]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,9 +70,9 @@ extension ExtensionPointPreferencesViewController: NSTableViewDelegate {
|
|||
|
||||
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
|
||||
if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "Cell"), owner: nil) as? NSTableCellView {
|
||||
let extensionPointID = activeExtensionPointIDs[row]
|
||||
cell.textField?.stringValue = extensionPointID.title
|
||||
cell.imageView?.image = extensionPointID.templateImage
|
||||
let extensionPoint = activeExtensionPoints[row]
|
||||
cell.textField?.stringValue = extensionPoint.title
|
||||
cell.imageView?.image = extensionPoint.templateImage
|
||||
return cell
|
||||
}
|
||||
return nil
|
||||
|
@ -88,8 +88,8 @@ extension ExtensionPointPreferencesViewController: NSTableViewDelegate {
|
|||
deleteButton.isEnabled = true
|
||||
}
|
||||
|
||||
let extensionPointID = activeExtensionPointIDs[selectedRow]
|
||||
let controller = ExtensionPointDetailViewController(extensionPointID: extensionPointID)
|
||||
let extensionPoint = activeExtensionPoints[selectedRow]
|
||||
let controller = ExtensionPointDetailViewController(extensionPoint: extensionPoint)
|
||||
showController(controller)
|
||||
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ private extension ExtensionPointPreferencesViewController {
|
|||
}
|
||||
|
||||
func showDefaultView() {
|
||||
activeExtensionPointIDs = Array(ExtensionPointManager.shared.activeExtensionPoints.keys).sorted(by: { $0.title < $1.title })
|
||||
activeExtensionPoints = Array(ExtensionPointManager.shared.activeExtensionPoints.values).sorted(by: { $0.title < $1.title })
|
||||
tableView.reloadData()
|
||||
showController(ExtensionPointAddViewController())
|
||||
}
|
||||
|
|
|
@ -16,16 +16,21 @@ protocol ExtensionPoint {
|
|||
static var templateImage: RSImage { get }
|
||||
static var description: NSAttributedString { get }
|
||||
|
||||
var title: String { get }
|
||||
var extensionPointID: ExtensionPointIdentifer { get }
|
||||
|
||||
}
|
||||
|
||||
extension ExtensionPoint {
|
||||
|
||||
var title: String {
|
||||
return extensionPointID.title
|
||||
var templateImage: RSImage {
|
||||
return extensionPointID.type.templateImage
|
||||
}
|
||||
|
||||
var description: NSAttributedString {
|
||||
return extensionPointID.type.description
|
||||
}
|
||||
|
||||
static func makeAttrString(_ text: String) -> NSMutableAttributedString {
|
||||
let paragraphStyle = NSMutableParagraphStyle()
|
||||
paragraphStyle.alignment = .center
|
||||
|
|
|
@ -15,23 +15,6 @@ enum ExtensionPointIdentifer: Hashable {
|
|||
case marsEdit
|
||||
case microblog
|
||||
case twitter(String)
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
case .twitter(let username):
|
||||
return "\(type.title) (\(username)"
|
||||
default:
|
||||
return type.title
|
||||
}
|
||||
}
|
||||
|
||||
var templateImage: RSImage {
|
||||
return type.templateImage
|
||||
}
|
||||
|
||||
var description: NSAttributedString {
|
||||
return type.description
|
||||
}
|
||||
|
||||
var type: ExtensionPoint.Type {
|
||||
switch self {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
import Foundation
|
||||
import FeedProvider
|
||||
import RSCore
|
||||
import OAuthSwift
|
||||
|
||||
public extension Notification.Name {
|
||||
static let ActiveExtensionPointsDidChange = Notification.Name(rawValue: "ActiveExtensionPointsDidChange")
|
||||
|
@ -62,8 +63,8 @@ final class ExtensionPointManager {
|
|||
loadExtensionPoints()
|
||||
}
|
||||
|
||||
func activateExtensionPoint(_ extensionPointType: ExtensionPoint.Type) {
|
||||
if let extensionPoint = self.extensionPoint(for: extensionPointType) {
|
||||
func activateExtensionPoint(_ extensionPointType: ExtensionPoint.Type, tokenSuccess: OAuthSwift.TokenSuccess? = nil) {
|
||||
if let extensionPoint = self.extensionPoint(for: extensionPointType, tokenSuccess: tokenSuccess) {
|
||||
activeExtensionPoints[extensionPoint.extensionPointID] = extensionPoint
|
||||
saveExtensionPointIDs()
|
||||
}
|
||||
|
@ -93,14 +94,18 @@ private extension ExtensionPointManager {
|
|||
NotificationCenter.default.post(name: .ActiveExtensionPointsDidChange, object: nil, userInfo: nil)
|
||||
}
|
||||
|
||||
func extensionPoint(for extensionPointType: ExtensionPoint.Type) -> ExtensionPoint? {
|
||||
func extensionPoint(for extensionPointType: ExtensionPoint.Type, tokenSuccess: OAuthSwift.TokenSuccess?) -> ExtensionPoint? {
|
||||
switch extensionPointType {
|
||||
case is SendToMarsEditCommand.Type:
|
||||
return SendToMarsEditCommand()
|
||||
case is SendToMicroBlogCommand.Type:
|
||||
return SendToMicroBlogCommand()
|
||||
// case is TwitterFeedProvider.Type:
|
||||
// return TwitterFeedProvider(username: username)
|
||||
case is TwitterFeedProvider.Type:
|
||||
if let tokenSuccess = tokenSuccess {
|
||||
return TwitterFeedProvider(tokenSuccess: tokenSuccess)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
default:
|
||||
assertionFailure("Unrecognized Extension Point Type.")
|
||||
}
|
||||
|
|
|
@ -27,6 +27,10 @@ final class SendToMarsEditCommand: ExtensionPoint, SendToCommand {
|
|||
|
||||
let extensionPointID = ExtensionPointIdentifer.marsEdit
|
||||
|
||||
var title: String {
|
||||
return extensionPointID.type.title
|
||||
}
|
||||
|
||||
var image: NSImage? {
|
||||
return appToUse()?.icon ?? nil
|
||||
}
|
||||
|
|
|
@ -30,6 +30,10 @@ final class SendToMicroBlogCommand: ExtensionPoint, SendToCommand {
|
|||
|
||||
let extensionPointID = ExtensionPointIdentifer.microblog
|
||||
|
||||
var title: String {
|
||||
return extensionPointID.type.title
|
||||
}
|
||||
|
||||
var image: NSImage? {
|
||||
return microBlogApp.icon
|
||||
}
|
||||
|
|
|
@ -28,7 +28,11 @@ extension TwitterFeedProvider: ExtensionPoint {
|
|||
}()
|
||||
|
||||
var extensionPointID: ExtensionPointIdentifer {
|
||||
return ExtensionPointIdentifer.twitter(username)
|
||||
return ExtensionPointIdentifer.twitter(userID)
|
||||
}
|
||||
|
||||
var title: String {
|
||||
return "@\(screenName)"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue