Displaying items in the bar + FeedConfig type enum

This commit is contained in:
relikd
2018-08-15 19:41:52 +02:00
parent 4f688e36a5
commit c4110cd160
15 changed files with 342 additions and 122 deletions

View File

@@ -0,0 +1,36 @@
//
// The MIT License (MIT)
// Copyright (c) 2018 Oleg Geier
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#import "FeedConfig+CoreDataClass.h"
@interface FeedConfig (Ext)
typedef enum int16_t {
GROUP = 0,
FEED = 1,
SEPARATOR = 2
} FeedConfigType;
@property (getter=typ, setter=setTyp:) FeedConfigType typ;
@property (readonly) NSArray<FeedConfig*> *sortedChildren;
- (NSString*)readableRefreshString;
- (NSString*)readableDescription;
@end

View File

@@ -20,21 +20,35 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#ifndef FeedConfig_Print_h
#define FeedConfig_Print_h
#import "FeedConfig+Ext.h"
@implementation FeedConfig (Ext)
- (FeedConfigType)typ {
return (FeedConfigType)self.type;
}
- (void)setTyp:(FeedConfigType)typ {
self.type = typ;
}
- (NSArray<FeedConfig *> *)sortedChildren {
if (self.children.count == 0)
return nil;
return [self.children sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"sortIndex" ascending:YES]]];
}
@implementation FeedConfig (Print)
- (NSString*)readableRefreshString {
return [NSString stringWithFormat:@"%d%c", self.refreshNum, [@"smhdw" characterAtIndex:self.refreshUnit % 5]];
}
- (NSString*)readableDescription {
switch (self.type) {
case 0: return [NSString stringWithFormat:@"%@", self.name]; // Group
case 2: return @"-------------"; // Separator
default:
switch (self.typ) {
case SEPARATOR: return @"-------------";
case GROUP: return [NSString stringWithFormat:@"%@", self.name];
case FEED:
return [NSString stringWithFormat:@"%@ (%@) - %@", self.name, self.url, [self readableRefreshString]];
}
}
@end
#endif /* FeedConfig_Print_h */
@end

View File

@@ -21,9 +21,8 @@
// SOFTWARE.
#import "ModalFeedEdit.h"
#import "NewsController.h"
#import "FeedDownload.h"
#import "StoreCoordinator.h"
#import "FeedConfig+CoreDataProperties.h"
@interface ModalFeedEdit()
@property (weak) IBOutlet NSTextField *url;
@@ -140,7 +139,7 @@
self.feedError = nil;
[self.spinnerURL startAnimation:nil];
[self.spinnerName startAnimation:nil];
[NewsController downloadFeed:self.previousURL withBlock:^(NSDictionary *result, NSError *error) {
[FeedDownload getFeed:self.previousURL withBlock:^(NSDictionary *result, NSError *error) {
self.feedResult = result;
self.feedError = error; // warning indicator .hidden is bound to feedError
// TODO: play error sound?

View File

@@ -22,8 +22,7 @@
#import "SettingsFeeds.h"
#import "AppDelegate.h"
#import "DBv1+CoreDataModel.h"
#import "FeedConfig+Print.h"
#import "FeedConfig+Ext.h"
#import "ModalSheet.h"
#import "ModalFeedEdit.h"
#import "DrawImage.h"
@@ -62,7 +61,7 @@ static NSString *dragNodeType = @"baRSS-feed-drag";
[self.undoManager beginUndoGrouping];
FeedConfig *sp = [self insertSortedItemAtSelection];
sp.name = @"---";
sp.type = 2;
sp.typ = SEPARATOR;
[self.undoManager endUndoGrouping];
}
@@ -93,8 +92,8 @@ static NSString *dragNodeType = @"baRSS-feed-drag";
- (void)showModalForFeedConfig:(FeedConfig*)obj isGroupEdit:(BOOL)group {
BOOL existingItem = [obj isKindOfClass:[FeedConfig class]];
if (existingItem) {
if (obj.type == 2) return; // Separator
group = (obj.type == 0);
if (obj.typ == SEPARATOR) return;
group = (obj.typ == GROUP);
}
self.modalController = (group ? [ModalGroupEdit new] : [ModalFeedEdit new]);
self.modalController.representedObject = obj;
@@ -104,7 +103,7 @@ static NSString *dragNodeType = @"baRSS-feed-drag";
[self.undoManager beginUndoGrouping];
if (!existingItem) { // create new item
FeedConfig *item = [self insertSortedItemAtSelection];
item.type = (group ? 0 : 1);
item.typ = (group ? GROUP : FEED);
self.modalController.representedObject = item;
}
[self.modalController updateRepresentedObject];
@@ -120,7 +119,7 @@ static NSString *dragNodeType = @"baRSS-feed-drag";
FeedConfig *selected = [[[self.dataStore arrangedObjects] descendantNodeAtIndexPath:selectedIndex] representedObject];
NSUInteger lastIndex = selected.children.count;
BOOL groupSelected = (selected.type == 0);
BOOL groupSelected = (selected.typ == GROUP);
if (!groupSelected) {
lastIndex = (NSUInteger)selected.sortIndex + 1; // insert after selection
@@ -217,7 +216,7 @@ static NSString *dragNodeType = @"baRSS-feed-drag";
- (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index {
FeedConfig *fc = [(NSTreeNode*)item representedObject];
if (index == -1 && fc.type != 0) { // if drag is on specific item and that item isnt a group
if (index == -1 && fc.typ != GROUP) { // if drag is on specific item and that item isnt a group
return NSDragOperationNone;
}
@@ -238,8 +237,8 @@ static NSString *dragNodeType = @"baRSS-feed-drag";
- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
FeedConfig *f = [(NSTreeNode*)item representedObject];
BOOL isFeed = (f.type == 1);
BOOL isSeperator = (f.type == 2);
BOOL isFeed = (f.typ == FEED);
BOOL isSeperator = (f.typ == SEPARATOR);
BOOL isRefreshColumn = [tableColumn.identifier isEqualToString:@"RefreshColumn"];
NSString *cellIdent = (isRefreshColumn ? @"cellRefresh" : (isSeperator ? @"cellSeparator" : @"cellFeed"));
@@ -252,7 +251,7 @@ static NSString *dragNodeType = @"baRSS-feed-drag";
return cellView; // the refresh cell is already skipped with the above if condition
} else {
cellView.textField.objectValue = f.name;
if (f.type == 0) {
if (f.typ == GROUP) {
cellView.imageView.image = [NSImage imageNamed:NSImageNameFolder];
} else {
// TODO: load icon
@@ -283,7 +282,7 @@ static NSString *dragNodeType = @"baRSS-feed-drag";
if (aSelector == @selector(copy:))
return YES;
// can edit only if selection is not a separator
return (((FeedConfig*)self.dataStore.selectedNodes.firstObject.representedObject).type != 2);
return (((FeedConfig*)self.dataStore.selectedNodes.firstObject.representedObject).typ != SEPARATOR);
}
return [super respondsToSelector:aSelector];
}

View File

@@ -23,7 +23,6 @@
#import "Preferences.h"
#import "SettingsFeeds.h"
#import "SettingsGeneral.h"
#import "AppDelegate.h"
@interface Preferences ()
@@ -58,7 +57,7 @@
}
- (void)windowWillClose:(NSNotification *)notification {
[(AppDelegate*)[NSApp delegate] preferencesClosed];
[[NSNotificationCenter defaultCenter] postNotificationName:@"baRSSPreferencesClosed" object:nil];
}
@end