Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1 from jeffmc/jeffmc/arc-xcode-10
Browse files Browse the repository at this point in the history
Jeffmc/arc xcode 10
  • Loading branch information
brentsimmons committed Aug 31, 2018
2 parents b0bd292 + ca05c44 commit c4ed724
Show file tree
Hide file tree
Showing 196 changed files with 15,781 additions and 16,528 deletions.
18 changes: 9 additions & 9 deletions Classes/NNWAddFeedWithURLWindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@

@interface NNWAddFeedWithURLWindowController : NSWindowController {
@private
NNWSubscriber *subscriber;
NSPopUpButton *folderPopupButton;
NSString *initialURLString;
NNWSubscribeRequest *initialSubscribeRequest;
NSTextField *titleTextField;
NSTextField *urlTextField;
NNWSubscriber *subscriber;
NSPopUpButton *folderPopupButton;
NSString *initialURLString;
NNWSubscribeRequest *initialSubscribeRequest;
NSTextField *titleTextField;
NSTextField *urlTextField;
}


@property (nonatomic, retain) IBOutlet NSPopUpButton *folderPopupButton;
@property (nonatomic, retain) IBOutlet NSTextField *titleTextField;
@property (nonatomic, retain) IBOutlet NSTextField *urlTextField;
@property (nonatomic, strong) IBOutlet NSPopUpButton *folderPopupButton;
@property (nonatomic, strong) IBOutlet NSTextField *titleTextField;
@property (nonatomic, strong) IBOutlet NSTextField *urlTextField;

- (id)initWithURLString:(NSString *)aURLString; //caller may have grabbed URL from pasteboard, for instance
- (id)initWithSubscribeRequest:(NNWSubscribeRequest *)aSubscribeRequest;
Expand Down
175 changes: 83 additions & 92 deletions Classes/NNWAddFeedWithURLWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

@interface NNWAddFeedWithURLWindowController ()

@property (nonatomic, retain) NNWSubscriber *subscriber;
@property (nonatomic, retain) NSString *initialURLString;
@property (nonatomic, retain) NNWSubscribeRequest *initialSubscribeRequest;
@property (nonatomic, strong) NNWSubscriber *subscriber;
@property (nonatomic, strong) NSString *initialURLString;
@property (nonatomic, strong) NNWSubscribeRequest *initialSubscribeRequest;

- (void)populateFolderMenu;
- (void)syncRequestedFolderAndMenu;
Expand All @@ -40,141 +40,132 @@ @implementation NNWAddFeedWithURLWindowController
#pragma mark Init

- (id)initWithURLString:(NSString *)aURLString {
self = [super initWithWindowNibName:@"AddFeedWithURL"];
if (self == nil)
return nil;
initialURLString = [aURLString copy];
return self;
self = [super initWithWindowNibName:@"AddFeedWithURL"];
if (self == nil)
return nil;
initialURLString = [aURLString copy];
return self;
}


- (id)initWithSubscribeRequest:(NNWSubscribeRequest *)aSubscribeRequest {
self = [self initWithURLString:[[aSubscribeRequest feedURL] absoluteString]];
if (self == nil)
return nil;
initialSubscribeRequest = [aSubscribeRequest retain];
return self;
self = [self initWithURLString:[[aSubscribeRequest feedURL] absoluteString]];
if (self == nil)
return nil;
initialSubscribeRequest = aSubscribeRequest;
return self;
}


#pragma mark Dealloc

- (void)dealloc {
[folderPopupButton release];
[initialSubscribeRequest release];
[initialURLString release];
[subscriber release];
[titleTextField release];
[urlTextField release];
[super dealloc];
}


#pragma mark Actions

- (void)cancel:(id)sender {
[NSApp stopModal];
[NSApp stopModal];
}


- (void)addFeed:(id)sender {
NNWSubscribeRequest *subscribeRequest = [[[NNWSubscribeRequest alloc] init] autorelease];
NSString *urlString = [self.urlTextField stringValue];
if (RSStringIsEmpty(urlString))
return;
if (![urlString hasPrefix:@"http://"] && ![urlString hasPrefix:@"https://"])
urlString = [NSString stringWithFormat:@"http://%@", urlString];
NSURL *aURL = [NSURL URLWithString:urlString];
if (aURL == nil)
return; //TODO: error message
subscribeRequest.feedURL = aURL;
id selectedFolder = [[self.folderPopupButton selectedItem] representedObject];
RSFolder *folder = nil;
id<RSAccount> account = nil;
if ([selectedFolder conformsToProtocol:@protocol(RSAccount)])
account = selectedFolder;
else if ([selectedFolder isKindOfClass:[RSFolder class]]) {
folder = selectedFolder;
account = folder.account;
}
subscribeRequest.account = account;
subscribeRequest.parentFolder = folder;
subscribeRequest.title = self.titleTextField.stringValue;
//subscribeRequest.backgroundWindow = [[self view] window];
self.subscriber = [[[NNWSubscriber alloc] initWithSubscribeRequest:subscribeRequest] autorelease];
[self.subscriber performSelector:@selector(subscribe) withObject:nil afterDelay:0.5f];
[NSApp stopModal];
NNWSubscribeRequest *subscribeRequest = [[NNWSubscribeRequest alloc] init];
NSString *urlString = [self.urlTextField stringValue];
if (RSStringIsEmpty(urlString))
return;
if (![urlString hasPrefix:@"http://"] && ![urlString hasPrefix:@"https://"])
urlString = [NSString stringWithFormat:@"http://%@", urlString];
NSURL *aURL = [NSURL URLWithString:urlString];
if (aURL == nil)
return; //TODO: error message
subscribeRequest.feedURL = aURL;
id selectedFolder = [[self.folderPopupButton selectedItem] representedObject];
RSFolder *folder = nil;
id<RSAccount> account = nil;
if ([selectedFolder conformsToProtocol:@protocol(RSAccount)])
account = selectedFolder;
else if ([selectedFolder isKindOfClass:[RSFolder class]]) {
folder = selectedFolder;
account = folder.account;
}
subscribeRequest.account = account;
subscribeRequest.parentFolder = folder;
subscribeRequest.title = self.titleTextField.stringValue;
//subscribeRequest.backgroundWindow = [[self view] window];
self.subscriber = [[NNWSubscriber alloc] initWithSubscribeRequest:subscribeRequest];
[self.subscriber performSelector:@selector(subscribe) withObject:nil afterDelay:0.5f];
[NSApp stopModal];
}


#pragma mark NSWindowController

- (void)windowDidLoad {
[self populateFolderMenu];
if (!RSStringIsEmpty(self.initialURLString))
[urlTextField setStringValue:self.initialURLString];
if (self.initialSubscribeRequest != nil) {
if (self.initialSubscribeRequest.title != nil)
[self.titleTextField setStringValue:self.initialSubscribeRequest.title];
if (self.initialSubscribeRequest.parentFolder != nil)
[self syncRequestedFolderAndMenu];
}
self.initialSubscribeRequest = nil; //not needed later
[self populateFolderMenu];
if (!RSStringIsEmpty(self.initialURLString))
[urlTextField setStringValue:self.initialURLString];
if (self.initialSubscribeRequest != nil) {
if (self.initialSubscribeRequest.title != nil)
[self.titleTextField setStringValue:self.initialSubscribeRequest.title];
if (self.initialSubscribeRequest.parentFolder != nil)
[self syncRequestedFolderAndMenu];
}
self.initialSubscribeRequest = nil; //not needed later
}


#pragma mark Folders Menu

- (void)syncRequestedFolderAndMenu {
for (NSMenuItem *oneMenuItem in [self.folderPopupButton itemArray]) {
if ([oneMenuItem representedObject] == self.initialSubscribeRequest.parentFolder) {
[self.folderPopupButton selectItem:oneMenuItem];
return;
}
}
for (NSMenuItem *oneMenuItem in [self.folderPopupButton itemArray]) {
if ([oneMenuItem representedObject] == self.initialSubscribeRequest.parentFolder) {
[self.folderPopupButton selectItem:oneMenuItem];
return;
}
}
}


- (void)addAccountMenuItem:(RSTreeNode *)accountTreeNode toMenu:(NSMenu *)aMenu indentLevel:(NSInteger)indentLevel {
NSMenuItem *menuItem = [[[NSMenuItem alloc] initWithTitle:accountTreeNode.representedObject.nameForDisplay action:nil keyEquivalent:@""] autorelease];
[menuItem setIndentationLevel:indentLevel];
[menuItem setRepresentedObject:accountTreeNode.representedObject];
[aMenu addItem:menuItem];
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:accountTreeNode.representedObject.nameForDisplay action:nil keyEquivalent:@""];
[menuItem setIndentationLevel:indentLevel];
[menuItem setRepresentedObject:accountTreeNode.representedObject];
[aMenu addItem:menuItem];
}


- (void)addFolderMenuItem:(RSTreeNode *)folderTreeNode toMenu:(NSMenu *)aMenu indentLevel:(NSInteger)indentLevel {
NSMenuItem *menuItem = [[[NSMenuItem alloc] initWithTitle:folderTreeNode.representedObject.nameForDisplay action:nil keyEquivalent:@""] autorelease];
[menuItem setIndentationLevel:indentLevel];
[menuItem setImage:[NSImage imageNamed:NSImageNameFolder]];
[menuItem setRepresentedObject:folderTreeNode.representedObject];
[aMenu addItem:menuItem];
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:folderTreeNode.representedObject.nameForDisplay action:nil keyEquivalent:@""];
[menuItem setIndentationLevel:indentLevel];
[menuItem setImage:[NSImage imageNamed:NSImageNameFolder]];
[menuItem setRepresentedObject:folderTreeNode.representedObject];
[aMenu addItem:menuItem];
}


- (void)addChildNodesFrom:(RSTreeNode *)aTreeNode toMenu:(NSMenu *)aMenu indentLevel:(NSInteger)indentLevel {
for (RSTreeNode *oneTreeNode in aTreeNode.orderedChildren) {
if (oneTreeNode.isSpecialGroup && oneTreeNode.representedObject != [RSDataAccount localAccount])
continue;
if (oneTreeNode.isSpecialGroup && oneTreeNode.representedObject == [RSDataAccount localAccount]) {
[self addAccountMenuItem:oneTreeNode toMenu:aMenu indentLevel:indentLevel];
[self addChildNodesFrom:oneTreeNode toMenu:aMenu indentLevel:indentLevel + 1];
}
else if (oneTreeNode.isGroup) {
[self addFolderMenuItem:oneTreeNode toMenu:aMenu indentLevel:indentLevel];
[self addChildNodesFrom:oneTreeNode toMenu:aMenu indentLevel:indentLevel + 1];
}
}
for (RSTreeNode *oneTreeNode in aTreeNode.orderedChildren) {
if (oneTreeNode.isSpecialGroup && oneTreeNode.representedObject != [RSDataAccount localAccount])
continue;
if (oneTreeNode.isSpecialGroup && oneTreeNode.representedObject == [RSDataAccount localAccount]) {
[self addAccountMenuItem:oneTreeNode toMenu:aMenu indentLevel:indentLevel];
[self addChildNodesFrom:oneTreeNode toMenu:aMenu indentLevel:indentLevel + 1];
}
else if (oneTreeNode.isGroup) {
[self addFolderMenuItem:oneTreeNode toMenu:aMenu indentLevel:indentLevel];
[self addChildNodesFrom:oneTreeNode toMenu:aMenu indentLevel:indentLevel + 1];
}
}
}


- (void)populateFolderMenu {
NSMenu *folderMenu = [[[NSMenu alloc] initWithTitle:@"Folders"] autorelease];
RSTree *tree = [NNWSourceListTreeBuilder sharedTreeBuilder].tree;
[self addChildNodesFrom:(RSTreeNode *)tree toMenu:folderMenu indentLevel:0];
[self.folderPopupButton setMenu:folderMenu];
NSMenu *folderMenu = [[NSMenu alloc] initWithTitle:@"Folders"];
RSTree *tree = [NNWSourceListTreeBuilder sharedTreeBuilder].tree;
[self addChildNodesFrom:(RSTreeNode *)tree toMenu:folderMenu indentLevel:0];
[self.folderPopupButton setMenu:folderMenu];
}


Expand Down
4 changes: 2 additions & 2 deletions Classes/NNWAddFolderWindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

@interface NNWAddFolderWindowController : NSWindowController {
@private
NSTextField *folderNameTextField;
NSTextField *folderNameTextField;
}


@property (nonatomic, retain) IBOutlet NSTextField *folderNameTextField;
@property (nonatomic, strong) IBOutlet NSTextField *folderNameTextField;


@end
30 changes: 13 additions & 17 deletions Classes/NNWAddFolderWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,33 @@ @implementation NNWAddFolderWindowController
#pragma mark Init

- (id)init {
return [self initWithWindowNibName:@"AddFolder"];
return [self initWithWindowNibName:@"AddFolder"];
}


#pragma mark Dealloc

- (void)dealloc {
[folderNameTextField release];
[super dealloc];
}


#pragma mark Actions

- (void)cancel:(id)sender {
[NSApp stopModal];
[NSApp stopModal];
}


- (void)addFolder:(id)sender {
NSString *folderName = [[[self.folderNameTextField stringValue] copy] autorelease];
if (RSStringIsEmpty(folderName)) {
[NSApp stopModal];
return;
}
if ([[RSDataAccount localAccount] folderWithNameExists:folderName])
return; //TODO: validation so we don't get to this position
[[RSDataAccount localAccount] addFolderWithName:folderName];
[RSDataAccount localAccount].needsToBeSavedOnDisk = YES;
[NSApp stopModal];
[[NSNotificationCenter defaultCenter] rs_postNotificationOnMainThread:NNWFolderAddedNotification object:self userInfo:[NSDictionary dictionaryWithObject:folderName forKey:RSNameKey]];
NSString *folderName = [[self.folderNameTextField stringValue] copy];
if (RSStringIsEmpty(folderName)) {
[NSApp stopModal];
return;
}
if ([[RSDataAccount localAccount] folderWithNameExists:folderName])
return; //TODO: validation so we don't get to this position
[[RSDataAccount localAccount] addFolderWithName:folderName];
[RSDataAccount localAccount].needsToBeSavedOnDisk = YES;
[NSApp stopModal];
[[NSNotificationCenter defaultCenter] rs_postNotificationOnMainThread:NNWFolderAddedNotification object:self userInfo:[NSDictionary dictionaryWithObject:folderName forKey:RSNameKey]];
}


Expand Down
Loading

0 comments on commit c4ed724

Please sign in to comment.