Add the Add Reddit Feed dialog

This commit is contained in:
Maurice Parker 2020-05-10 11:44:30 -05:00
parent 7ab4ca4291
commit 06e91aa8b7
11 changed files with 468 additions and 6 deletions

View File

@ -27,6 +27,13 @@ public enum RedditFeedProviderError: LocalizedError {
}
}
public enum RedditFeedType: Int {
case home = 0
case popular = 1
case all = 2
case subreddit = 3
}
public final class RedditFeedProvider: FeedProvider {
var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "RedditFeedProvider")
@ -163,7 +170,12 @@ public final class RedditFeedProvider: FeedProvider {
return
}
let api = "\(urlComponents.path).json"
let api: String
if urlComponents.path.isEmpty {
api = "/.json"
} else {
api = "\(urlComponents.path).json"
}
let splitPath = urlComponents.path.split(separator: "/")
let identifySubreddit: Bool
@ -215,6 +227,39 @@ public final class RedditFeedProvider: FeedProvider {
}
}
public static func buildURL(_ type: RedditFeedType, username: String?, subreddit: String?) -> URL? {
var components = URLComponents()
components.scheme = "https"
components.host = "www.reddit.com"
switch type {
case .home:
guard let username = username else {
return nil
}
components.user = username
case .popular:
guard let username = username else {
return nil
}
components.user = username
components.path = "/r/popular"
case .all:
guard let username = username else {
return nil
}
components.user = username
components.path = "/r/all"
case .subreddit:
guard let subreddit = subreddit else {
return nil
}
components.path = "/r/\(subreddit)"
}
return components.url
}
}
// MARK: OAuth1SwiftProvider

View File

@ -403,6 +403,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
if item.action == #selector(showAddWebFeedWindow(_:)) || item.action == #selector(showAddFolderWindow(_:)) {
return !isDisplayingSheet && !AccountManager.shared.activeAccounts.isEmpty
}
if item.action == #selector(showAddRedditFeedWindow(_:)) {
guard !isDisplayingSheet && !AccountManager.shared.activeAccounts.isEmpty else {
return false
}
return ExtensionPointManager.shared.isRedditEnabled
}
if item.action == #selector(showAddTwitterFeedWindow(_:)) {
guard !isDisplayingSheet && !AccountManager.shared.activeAccounts.isEmpty else {
return false
@ -471,6 +477,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
addWebFeed(nil)
}
@IBAction func showAddRedditFeedWindow(_ sender: Any?) {
createAndShowMainWindowIfNecessary()
addFeedController = AddFeedController(hostWindow: mainWindowController!.window!)
addFeedController?.showAddFeedSheet(.redditFeed)
}
@IBAction func showAddTwitterFeedWindow(_ sender: Any?) {
createAndShowMainWindowIfNecessary()
addFeedController = AddFeedController(hostWindow: mainWindowController!.window!)

View File

@ -0,0 +1,199 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="16096" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16096"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="AddRedditFeedWindowController" customModule="NetNewsWire" customModuleProvider="target">
<connections>
<outlet property="accountLabel" destination="Acr-Ig-NVG" id="1gD-BE-CjH"/>
<outlet property="accountPopupButton" destination="X1H-Vv-1CJ" id="I0k-bb-XcU"/>
<outlet property="addButton" destination="dtI-Hu-rFb" id="D11-zR-dWH"/>
<outlet property="folderPopupButton" destination="6vt-DL-mVR" id="98M-xt-ZYU"/>
<outlet property="nameTextField" destination="TzV-3k-fXd" id="h4h-5v-4cY"/>
<outlet property="subredditTextField" destination="cEh-Wt-f5D" id="bnp-Zp-1fe"/>
<outlet property="typeDescriptionLabel" destination="f4Z-B8-HHm" id="jZ2-gz-Zr2"/>
<outlet property="typePopupButton" destination="j18-w8-wsH" id="KFC-K4-0tG"/>
<outlet property="window" destination="QvC-M9-y7g" id="7rH-S2-LF4"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Add Reddit Feed" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="QvC-M9-y7g">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="306" height="216"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
<view key="contentView" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="306" height="216"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="hXq-IS-19x">
<rect key="frame" x="128" y="13" width="82" height="32"/>
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Dop-HC-6Q9">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
Gw
</string>
</buttonCell>
<connections>
<action selector="cancel:" target="-2" id="tcT-tt-t99"/>
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="dtI-Hu-rFb">
<rect key="frame" x="210" y="13" width="82" height="32"/>
<buttonCell key="cell" type="push" title="Add" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="6NK-Ql-drk">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
DQ
</string>
</buttonCell>
<connections>
<action selector="addFeed:" target="-2" id="Ilv-Un-eDp"/>
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ddC-6D-Tvd">
<rect key="frame" x="40" y="178" width="41" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Type:" id="qto-IO-a1j">
<font key="font" metaFont="systemBold"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="j18-w8-wsH">
<rect key="frame" x="85" y="172" width="204" height="25"/>
<popUpButtonCell key="cell" type="push" title="Home" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="uE6-1a-w5g" id="bad-PM-uqO">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<menu key="menu" id="Ibj-Uy-KK7">
<items>
<menuItem title="Home" state="on" id="uE6-1a-w5g"/>
<menuItem title="Popular" tag="1" id="177-F8-Esj"/>
<menuItem title="All" tag="2" id="DBZ-RV-FfV"/>
<menuItem title="Subreddit" tag="3" id="0gG-oY-8yR"/>
</items>
</menu>
</popUpButtonCell>
<connections>
<action selector="selectedType:" target="-2" id="eAs-So-odx"/>
</connections>
</popUpButton>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Acr-Ig-NVG">
<rect key="frame" x="18" y="147" width="63" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Account:" id="LFf-JL-Ahl">
<font key="font" metaFont="systemBold"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="X1H-Vv-1CJ">
<rect key="frame" x="85" y="141" width="204" height="25"/>
<popUpButtonCell key="cell" type="push" title="u/username" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="Tfk-aQ-RKg" id="HPE-P1-Hje">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<menu key="menu" id="TmQ-5T-oaz">
<items>
<menuItem title="u/username" state="on" id="Tfk-aQ-RKg"/>
</items>
</menu>
</popUpButtonCell>
</popUpButton>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="cEh-Wt-f5D">
<rect key="frame" x="87" y="144" width="199" height="21"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" id="NLJ-ih-hZ8">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<outlet property="delegate" destination="-2" id="hNy-Li-bjr"/>
</connections>
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="f4Z-B8-HHm">
<rect key="frame" x="85" y="122" width="203" height="14"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="5AA-um-oEb">
<font key="font" metaFont="label" size="11"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="sM9-DX-M0c">
<rect key="frame" x="35" y="94" width="46" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Name:" id="8ca-Qp-BkT">
<font key="font" metaFont="systemBold"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="TzV-3k-fXd" userLabel="Name Text Field">
<rect key="frame" x="87" y="91" width="199" height="21"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" placeholderString="Optional" drawsBackground="YES" usesSingleLineMode="YES" id="pLP-pL-5R5">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="dNV-oD-vzR">
<rect key="frame" x="31" y="63" width="50" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Folder:" id="Kwx-7B-CIu">
<font key="font" metaFont="systemBold"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="6vt-DL-mVR" userLabel="Folder Popup">
<rect key="frame" x="85" y="57" width="204" height="25"/>
<popUpButtonCell key="cell" type="push" title="Item 1" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="tLJ-zY-CcZ" id="0cM-5q-Snl">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<menu key="menu" id="OpL-Uf-woJ">
<items>
<menuItem title="Item 1" state="on" id="tLJ-zY-CcZ"/>
<menuItem title="Item 2" id="APc-af-7Um"/>
<menuItem title="Item 3" id="j09-9b-bGs"/>
</items>
</menu>
</popUpButtonCell>
</popUpButton>
</subviews>
<constraints>
<constraint firstItem="dNV-oD-vzR" firstAttribute="baseline" secondItem="6vt-DL-mVR" secondAttribute="baseline" id="14b-jN-4Y6"/>
<constraint firstItem="X1H-Vv-1CJ" firstAttribute="firstBaseline" secondItem="Acr-Ig-NVG" secondAttribute="firstBaseline" id="3Cl-Bw-Pcy"/>
<constraint firstItem="X1H-Vv-1CJ" firstAttribute="top" secondItem="j18-w8-wsH" secondAttribute="bottom" constant="10" id="48A-2f-2Wq"/>
<constraint firstAttribute="bottom" secondItem="dtI-Hu-rFb" secondAttribute="bottom" constant="20" symbolic="YES" id="6ac-2K-RnD"/>
<constraint firstItem="cEh-Wt-f5D" firstAttribute="leading" secondItem="j18-w8-wsH" secondAttribute="leading" id="73d-zR-g8z"/>
<constraint firstItem="TzV-3k-fXd" firstAttribute="leading" secondItem="cEh-Wt-f5D" secondAttribute="leading" id="Ap9-Ln-amq"/>
<constraint firstAttribute="trailing" secondItem="X1H-Vv-1CJ" secondAttribute="trailing" constant="20" id="Boa-Qw-dIK"/>
<constraint firstItem="TzV-3k-fXd" firstAttribute="leading" secondItem="sM9-DX-M0c" secondAttribute="trailing" constant="8" id="Ebw-Fa-w9o"/>
<constraint firstItem="TzV-3k-fXd" firstAttribute="top" secondItem="f4Z-B8-HHm" secondAttribute="bottom" constant="10" id="Elk-Gm-e4i"/>
<constraint firstItem="X1H-Vv-1CJ" firstAttribute="leading" secondItem="Acr-Ig-NVG" secondAttribute="trailing" constant="8" id="HwM-IS-kMa"/>
<constraint firstItem="dtI-Hu-rFb" firstAttribute="width" secondItem="hXq-IS-19x" secondAttribute="width" id="J80-aG-OjE"/>
<constraint firstItem="sM9-DX-M0c" firstAttribute="baseline" secondItem="TzV-3k-fXd" secondAttribute="baseline" id="K9a-t8-khQ"/>
<constraint firstAttribute="trailing" secondItem="f4Z-B8-HHm" secondAttribute="trailing" constant="20" id="POl-uX-qpn"/>
<constraint firstItem="f4Z-B8-HHm" firstAttribute="leading" secondItem="j18-w8-wsH" secondAttribute="leading" id="RbK-fc-c6E"/>
<constraint firstItem="hXq-IS-19x" firstAttribute="centerY" secondItem="dtI-Hu-rFb" secondAttribute="centerY" id="Sgq-Cy-rII"/>
<constraint firstItem="6vt-DL-mVR" firstAttribute="top" secondItem="TzV-3k-fXd" secondAttribute="bottom" constant="10" id="Sjo-Bv-alZ"/>
<constraint firstAttribute="trailing" secondItem="TzV-3k-fXd" secondAttribute="trailing" constant="20" symbolic="YES" id="V1s-JA-hA8"/>
<constraint firstItem="6vt-DL-mVR" firstAttribute="leading" secondItem="dNV-oD-vzR" secondAttribute="trailing" constant="8" id="WNy-vn-p8M"/>
<constraint firstItem="f4Z-B8-HHm" firstAttribute="top" secondItem="cEh-Wt-f5D" secondAttribute="bottom" constant="8" id="WiN-GE-aPh"/>
<constraint firstAttribute="trailing" secondItem="cEh-Wt-f5D" secondAttribute="trailing" constant="20" id="ZSt-ga-a8N"/>
<constraint firstItem="dtI-Hu-rFb" firstAttribute="leading" secondItem="hXq-IS-19x" secondAttribute="trailing" constant="12" symbolic="YES" id="ahD-oU-iFu"/>
<constraint firstItem="Acr-Ig-NVG" firstAttribute="leading" secondItem="EiT-Mj-1SZ" secondAttribute="leading" constant="20" id="dhv-D0-aPe"/>
<constraint firstAttribute="trailing" secondItem="j18-w8-wsH" secondAttribute="trailing" constant="20" id="eQ9-hw-PXg"/>
<constraint firstItem="j18-w8-wsH" firstAttribute="top" secondItem="EiT-Mj-1SZ" secondAttribute="top" constant="20" symbolic="YES" id="fK6-IW-NhJ"/>
<constraint firstItem="j18-w8-wsH" firstAttribute="leading" secondItem="X1H-Vv-1CJ" secondAttribute="leading" id="gSv-gG-TLd"/>
<constraint firstItem="6vt-DL-mVR" firstAttribute="leading" secondItem="TzV-3k-fXd" secondAttribute="leading" id="hMP-wG-fsP"/>
<constraint firstItem="cEh-Wt-f5D" firstAttribute="top" secondItem="j18-w8-wsH" secondAttribute="bottom" constant="10" id="hxS-Z9-dWU"/>
<constraint firstItem="j18-w8-wsH" firstAttribute="firstBaseline" secondItem="ddC-6D-Tvd" secondAttribute="firstBaseline" id="iz7-4p-NWj"/>
<constraint firstAttribute="trailing" secondItem="dtI-Hu-rFb" secondAttribute="trailing" constant="20" symbolic="YES" id="kEo-af-SUe"/>
<constraint firstItem="j18-w8-wsH" firstAttribute="leading" secondItem="ddC-6D-Tvd" secondAttribute="trailing" constant="8" id="n9D-4Y-HXk"/>
<constraint firstAttribute="trailing" secondItem="6vt-DL-mVR" secondAttribute="trailing" constant="20" id="suO-dd-E0b"/>
</constraints>
</view>
<point key="canvasLocation" x="102" y="-768"/>
</window>
</objects>
</document>

View File

@ -91,12 +91,12 @@ DQ
</textField>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="X1H-Vv-1CJ">
<rect key="frame" x="85" y="141" width="204" height="25"/>
<popUpButtonCell key="cell" type="push" title="@vincode_io" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="Tfk-aQ-RKg" id="HPE-P1-Hje">
<popUpButtonCell key="cell" type="push" title="@username" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="Tfk-aQ-RKg" id="HPE-P1-Hje">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<menu key="menu" id="TmQ-5T-oaz">
<items>
<menuItem title="@vincode_io" state="on" id="Tfk-aQ-RKg"/>
<menuItem title="@username" state="on" id="Tfk-aQ-RKg"/>
</items>
</menu>
</popUpButtonCell>
@ -115,7 +115,7 @@ DQ
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="f4Z-B8-HHm">
<rect key="frame" x="85" y="122" width="203" height="14"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="5AA-um-oEb">
<font key="font" metaFont="controlContent" size="11"/>
<font key="font" metaFont="menu" size="11"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>

View File

@ -73,6 +73,12 @@
<action selector="showAddWebFeedWindow:" target="Ady-hI-5gd" id="LkT-kx-aCR"/>
</connections>
</menuItem>
<menuItem title="New Reddit Feed" id="36v-YK-HdM">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="showAddRedditFeedWindow:" target="Ady-hI-5gd" id="pIf-cn-NHR"/>
</connections>
</menuItem>
<menuItem title="New Twitter Feed" id="Wlk-34-AUR">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>

View File

@ -44,6 +44,9 @@ class AddFeedController: AddFeedWindowControllerDelegate {
folder: folder,
folderTreeController: folderTreeController,
delegate: self)
case .redditFeed:
addFeedWindowController = AddRedditFeedWindowController(folderTreeController: folderTreeController,
delegate: self)
case .twitterFeed:
addFeedWindowController = AddTwitterFeedWindowController(folderTreeController: folderTreeController,
delegate: self)

View File

@ -11,6 +11,7 @@ import Account
enum AddFeedWindowControllerType {
case webFeed
case redditFeed
case twitterFeed
}

View File

@ -25,7 +25,6 @@ class AddTwitterFeedWindowController : NSWindowController, AddFeedWindowControll
@IBOutlet var addButton: NSButton!
@IBOutlet var folderPopupButton: NSPopUpButton!
private var urlString: String?
private weak var delegate: AddFeedWindowControllerDelegate?
private var folderTreeController: TreeController!

View File

@ -0,0 +1,177 @@
//
// AddRedditFeedWindowController.swift
// NetNewsWire
//
// Created by Maurice Parker on 5/10/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import AppKit
import RSCore
import RSTree
import Articles
import Account
class AddRedditFeedWindowController : NSWindowController, AddFeedWindowController {
@IBOutlet weak var typePopupButton: NSPopUpButton!
@IBOutlet weak var typeDescriptionLabel: NSTextField!
@IBOutlet weak var accountLabel: NSTextField!
@IBOutlet weak var accountPopupButton: NSPopUpButton!
@IBOutlet weak var subredditTextField: NSTextField!
@IBOutlet var nameTextField: NSTextField!
@IBOutlet var addButton: NSButton!
@IBOutlet var folderPopupButton: NSPopUpButton!
private weak var delegate: AddFeedWindowControllerDelegate?
private var folderTreeController: TreeController!
private var userEnteredSubreddit: String? {
var s = subredditTextField.stringValue
s = s.collapsingWhitespace
if s.isEmpty {
return nil
}
return s
}
private var userEnteredTitle: String? {
var s = nameTextField.stringValue
s = s.collapsingWhitespace
if s.isEmpty {
return nil
}
return s
}
var hostWindow: NSWindow!
convenience init(folderTreeController: TreeController, delegate: AddFeedWindowControllerDelegate?) {
self.init(windowNibName: NSNib.Name("AddRedditFeedSheet"))
self.folderTreeController = folderTreeController
self.delegate = delegate
}
func runSheetOnWindow(_ hostWindow: NSWindow) {
hostWindow.beginSheet(window!) { (returnCode: NSApplication.ModalResponse) -> Void in
}
}
override func windowDidLoad() {
let accountMenu = NSMenu()
for feedProvider in ExtensionPointManager.shared.activeFeedProviders {
if let redditFeedProvider = feedProvider as? RedditFeedProvider {
let accountMenuItem = NSMenuItem()
accountMenuItem.title = redditFeedProvider.title
accountMenu.addItem(accountMenuItem)
}
}
accountPopupButton.menu = accountMenu
folderPopupButton.menu = FolderTreeMenu.createFolderPopupMenu(with: folderTreeController.rootNode)
if let container = AddWebFeedDefaultContainer.defaultContainer {
if let folder = container as? Folder, let account = folder.account {
FolderTreeMenu.select(account: account, folder: folder, in: folderPopupButton)
} else {
if let account = container as? Account {
FolderTreeMenu.select(account: account, folder: nil, in: folderPopupButton)
}
}
}
updateUI()
}
// MARK: Actions
@IBAction func selectedType(_ sender: Any) {
subredditTextField.stringValue = ""
updateUI()
}
@IBAction func cancel(_ sender: Any?) {
cancelSheet()
}
@IBAction func addFeed(_ sender: Any?) {
guard let type = RedditFeedType(rawValue: typePopupButton.selectedItem?.tag ?? 0),
let atUsername = accountPopupButton.selectedItem?.title else { return }
let username = String(atUsername[atUsername.index(atUsername.startIndex, offsetBy: 2)..<atUsername.endIndex])
guard let url = RedditFeedProvider.buildURL(type, username: username, subreddit: userEnteredSubreddit) else { return }
let container = selectedContainer()!
AddWebFeedDefaultContainer.saveDefaultContainer(container)
delegate?.addFeedWindowController(self, userEnteredURL: url, userEnteredTitle: userEnteredTitle, container: container)
}
}
extension AddRedditFeedWindowController: NSTextFieldDelegate {
func controlTextDidChange(_ obj: Notification) {
updateUI()
}
}
private extension AddRedditFeedWindowController {
private func updateUI() {
switch typePopupButton.selectedItem?.tag ?? 0 {
case 0:
accountLabel.isHidden = false
accountPopupButton.isHidden = false
typeDescriptionLabel.stringValue = NSLocalizedString("Your personal Reddit frontpage", comment: "Home")
subredditTextField.isHidden = true
addButton.isEnabled = true
case 1:
accountLabel.isHidden = false
accountPopupButton.isHidden = false
typeDescriptionLabel.stringValue = NSLocalizedString("Best posts on Reddit for you", comment: "Popular")
subredditTextField.isHidden = true
addButton.isEnabled = true
case 2:
accountLabel.isHidden = false
accountPopupButton.isHidden = false
typeDescriptionLabel.stringValue = NSLocalizedString("The most active posts", comment: "All")
subredditTextField.isHidden = true
addButton.isEnabled = true
default:
accountLabel.isHidden = true
accountPopupButton.isHidden = true
if !subredditTextField.stringValue.isEmpty {
typeDescriptionLabel.stringValue = NSLocalizedString("Posts from r/\(subredditTextField.stringValue)", comment: "Subreddit")
} else {
typeDescriptionLabel.stringValue = ""
}
subredditTextField.placeholderString = NSLocalizedString("Subreddit", comment: "Search Term")
subredditTextField.isHidden = false
addButton.isEnabled = !subredditTextField.stringValue.isEmpty
}
}
func cancelSheet() {
delegate?.addFeedWindowControllerUserDidCancel(self)
}
func selectedContainer() -> Container? {
return folderPopupButton.selectedItem?.representedObject as? Container
}
}

View File

@ -93,6 +93,10 @@
51314705235C41FC00387FDC /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 51314707235C41FC00387FDC /* Intents.intentdefinition */; };
513228FB233037630033D4ED /* Reachability.swift in Sources */ = {isa = PBXBuildFile; fileRef = 513228F2233037620033D4ED /* Reachability.swift */; };
513228FC233037630033D4ED /* Reachability.swift in Sources */ = {isa = PBXBuildFile; fileRef = 513228F2233037620033D4ED /* Reachability.swift */; };
51333D1624685D2E00EB5C91 /* AddRedditFeedWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51333D1524685D2E00EB5C91 /* AddRedditFeedWindowController.swift */; };
51333D1724685D2E00EB5C91 /* AddRedditFeedWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51333D1524685D2E00EB5C91 /* AddRedditFeedWindowController.swift */; };
51333D3B2468615D00EB5C91 /* AddRedditFeedSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = 51333D392468615D00EB5C91 /* AddRedditFeedSheet.xib */; };
51333D3C2468615D00EB5C91 /* AddRedditFeedSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = 51333D392468615D00EB5C91 /* AddRedditFeedSheet.xib */; };
513C5CE9232571C2003D4054 /* ShareViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 513C5CE8232571C2003D4054 /* ShareViewController.swift */; };
513C5CEC232571C2003D4054 /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 513C5CEA232571C2003D4054 /* MainInterface.storyboard */; };
513C5CF0232571C2003D4054 /* NetNewsWire iOS Share Extension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 513C5CE6232571C2003D4054 /* NetNewsWire iOS Share Extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
@ -1441,6 +1445,8 @@
51314706235C41FC00387FDC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; name = Base; path = Base.lproj/Intents.intentdefinition; sourceTree = "<group>"; };
51314714235C420900387FDC /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Intents.strings; sourceTree = "<group>"; };
513228F2233037620033D4ED /* Reachability.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reachability.swift; sourceTree = "<group>"; };
51333D1524685D2E00EB5C91 /* AddRedditFeedWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddRedditFeedWindowController.swift; sourceTree = "<group>"; };
51333D3A2468615D00EB5C91 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Mac/Base.lproj/AddRedditFeedSheet.xib; sourceTree = SOURCE_ROOT; };
513C5CE6232571C2003D4054 /* NetNewsWire iOS Share Extension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "NetNewsWire iOS Share Extension.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
513C5CE8232571C2003D4054 /* ShareViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareViewController.swift; sourceTree = "<group>"; };
513C5CEB232571C2003D4054 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = "<group>"; };
@ -2563,6 +2569,8 @@
children = (
849A97511ED9EAC0007D329B /* AddFeedController.swift */,
51A052CD244FB9D6006C2024 /* AddFeedWIndowController.swift */,
51333D392468615D00EB5C91 /* AddRedditFeedSheet.xib */,
51333D1524685D2E00EB5C91 /* AddRedditFeedWindowController.swift */,
514A897F244FD63F0085E65D /* AddTwitterFeedSheet.xib */,
514A89A4244FD6640085E65D /* AddTwitterFeedWindowController.swift */,
848363002262A3BC00DA1D35 /* AddWebFeedSheet.xib */,
@ -3806,6 +3814,7 @@
514A89A3244FD63F0085E65D /* AddTwitterFeedSheet.xib in Resources */,
5103A9F5242258C600410853 /* AccountsAddCloudKit.xib in Resources */,
65ED405E235DEF6C0081F399 /* DefaultFeeds.opml in Resources */,
51333D3C2468615D00EB5C91 /* AddRedditFeedSheet.xib in Resources */,
65ED405F235DEF6C0081F399 /* Preferences.storyboard in Resources */,
65ED4061235DEF6C0081F399 /* Assets.xcassets in Resources */,
65ED4062235DEF6C0081F399 /* styleSheet.css in Resources */,
@ -3915,6 +3924,7 @@
55E15BCB229D65A900D6602A /* AccountsReaderAPI.xib in Resources */,
49F40DF82335B71000552BF4 /* newsfoot.js in Resources */,
510C43ED243C0973009F70C3 /* ExtensionPointAdd.xib in Resources */,
51333D3B2468615D00EB5C91 /* AddRedditFeedSheet.xib in Resources */,
BDCB516724282C8A00102A80 /* AccountsNewsBlur.xib in Resources */,
514A89A2244FD63F0085E65D /* AddTwitterFeedSheet.xib in Resources */,
5103A9982421643300410853 /* blank.html in Resources */,
@ -4127,6 +4137,7 @@
65ED3FD4235DEF6C0081F399 /* Article+Scriptability.swift in Sources */,
515A5172243E802B0089E588 /* ExtensionPointDetailViewController.swift in Sources */,
65ED3FD5235DEF6C0081F399 /* SmartFeed.swift in Sources */,
51333D1724685D2E00EB5C91 /* AddRedditFeedWindowController.swift in Sources */,
65ED3FD6235DEF6C0081F399 /* MarkStatusCommand.swift in Sources */,
65ED3FD7235DEF6C0081F399 /* NSApplication+Scriptability.swift in Sources */,
65ED3FD8235DEF6C0081F399 /* NSView-Extensions.swift in Sources */,
@ -4573,6 +4584,7 @@
849A97541ED9EAC0007D329B /* AddWebFeedWindowController.swift in Sources */,
5144EA40227A37EC00D19003 /* ImportOPMLWindowController.swift in Sources */,
849A976D1ED9EBC8007D329B /* TimelineTableView.swift in Sources */,
51333D1624685D2E00EB5C91 /* AddRedditFeedWindowController.swift in Sources */,
84D52E951FE588BB00D14F5B /* DetailStatusBarView.swift in Sources */,
D5E4CC64202C1AC1009B4FFC /* MainWindowController+Scriptability.swift in Sources */,
51A052CE244FB9D7006C2024 /* AddFeedWIndowController.swift in Sources */,
@ -4789,6 +4801,14 @@
name = Intents.intentdefinition;
sourceTree = "<group>";
};
51333D392468615D00EB5C91 /* AddRedditFeedSheet.xib */ = {
isa = PBXVariantGroup;
children = (
51333D3A2468615D00EB5C91 /* Base */,
);
name = AddRedditFeedSheet.xib;
sourceTree = "<group>";
};
513C5CEA232571C2003D4054 /* MainInterface.storyboard */ = {
isa = PBXVariantGroup;
children = (

View File

@ -30,7 +30,7 @@ extension RedditFeedProvider: ExtensionPoint {
guard let username = username else {
fatalError()
}
return "/u/\(username)"
return "u/\(username)"
}
}