From 3ca230bb4a43751e8c034c9216a19b6902773bef Mon Sep 17 00:00:00 2001 From: relikd Date: Fri, 3 Aug 2018 01:48:30 +0200 Subject: [PATCH] prettify ui and insert corresponding items --- .../seperator.imageset/Contents.json | 23 +++++++++ .../seperator.imageset/separator.png | Bin 0 -> 109 bytes .../seperator.imageset/separator@2x.png | Bin 0 -> 153 bytes .../seperator.imageset/separator@3x.png | Bin 0 -> 171 bytes baRSS/Base.lproj/Main.xib | 39 +++++++++++---- baRSS/NewsController.m | 47 ++++++++++++++---- 6 files changed, 88 insertions(+), 21 deletions(-) create mode 100644 baRSS/Assets.xcassets/seperator.imageset/Contents.json create mode 100644 baRSS/Assets.xcassets/seperator.imageset/separator.png create mode 100644 baRSS/Assets.xcassets/seperator.imageset/separator@2x.png create mode 100644 baRSS/Assets.xcassets/seperator.imageset/separator@3x.png diff --git a/baRSS/Assets.xcassets/seperator.imageset/Contents.json b/baRSS/Assets.xcassets/seperator.imageset/Contents.json new file mode 100644 index 0000000..2b9622b --- /dev/null +++ b/baRSS/Assets.xcassets/seperator.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "separator.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "separator@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "separator@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/baRSS/Assets.xcassets/seperator.imageset/separator.png b/baRSS/Assets.xcassets/seperator.imageset/separator.png new file mode 100644 index 0000000000000000000000000000000000000000..76321bd19af1a6d783c8f79b02848fb02ae13106 GIT binary patch literal 109 zcmeAS@N?(olHy`uVBq!ia0y~yU^vdez`(@8#=yYvM&ZOk1_lNbPZ!6K3dUp}es1A} zgaiwQBfA{_$anoem=V>{JImJMuBpu5O-WC^6ny0p4(Zu&xgFGCV34xk$+&RdeijA> O1_n=8KbLh*2~7Y2%^%wU literal 0 HcmV?d00001 diff --git a/baRSS/Assets.xcassets/seperator.imageset/separator@2x.png b/baRSS/Assets.xcassets/seperator.imageset/separator@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..7e295e2519c40d67281237d1e81970d334306d85 GIT binary patch literal 153 zcmeAS@N?(olHy`uVBq!ia0y~yVC-dJU|`{3V_;w?%1k_ba4!+U`*oS=N3*# zNU&fyQswYxJ|ok=#hV0c9^GVKpZ8-|lRr#QP6;HXLMPILg9cch>IrGKL0rxdqH3S!*t7FfcGMc)I$z JtaD0e0sx-FGa&!~ literal 0 HcmV?d00001 diff --git a/baRSS/Assets.xcassets/seperator.imageset/separator@3x.png b/baRSS/Assets.xcassets/seperator.imageset/separator@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..d38e4bb2d9dc2631196500af4d3f63422780db73 GIT binary patch literal 171 zcmeAS@N?(olHy`uVBq!ia0y~yU;0t&_ZB8;VcyIWcv}@;tQ7xUedqK6L8Z@70t3@451P-_`HCzlC2f zt+cweW!<*i - + @@ -338,30 +338,45 @@ - + - - + + - + - - + + - + - + - + + + + + + + + + + + + + + + + @@ -410,6 +425,7 @@ + @@ -437,7 +453,7 @@ - + @@ -502,5 +518,6 @@ CA + diff --git a/baRSS/NewsController.m b/baRSS/NewsController.m index 5c62c5e..992c783 100644 --- a/baRSS/NewsController.m +++ b/baRSS/NewsController.m @@ -44,8 +44,18 @@ static NSString *dragNodeType = @"baRSS-feed-type"; } - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item { - // this delegate method is only here to set owner to null and prohibit repeated awakeFromNib calls - return [self.outlineView makeViewWithIdentifier:tableColumn.identifier owner:nil]; + // owner is nil to prohibit repeated awakeFromNib calls + NSTableCellView *cellView = [self.outlineView makeViewWithIdentifier:tableColumn.identifier owner:nil]; + if (cellView) + return cellView; // is a refresh cell + + FeedConfig *f = [(NSTreeNode*)item representedObject]; + if (f.type == 2) { // Seperator + return [self.outlineView makeViewWithIdentifier:@"cellFeedConfigSeperator" owner:nil]; + } + cellView = [self.outlineView makeViewWithIdentifier:@"cellFeedConfigName" owner:nil]; + cellView.imageView.image = [NSImage imageNamed:NSImageNameFolder]; + return cellView; } - (IBAction)pauseUpdates:(NSMenuItem *)sender { @@ -90,19 +100,29 @@ static NSString *dragNodeType = @"baRSS-feed-type"; - (IBAction)addFeed:(NSButton *)sender { NSLog(@"add feed"); + [self.managedObjectContext.undoManager beginUndoGrouping]; + FeedConfig *nf = [self insertSortedItemAtSelection]; + nf.type = 1; + nf.name = [NSString stringWithFormat:@"%@", [NSDate date]]; + nf.refresh = @"42s"; + [self.managedObjectContext.undoManager endUndoGrouping]; } - (IBAction)addGroup:(NSButton *)sender { - FeedConfig *g = [[FeedConfig alloc] initWithEntity:FeedConfig.entity insertIntoManagedObjectContext:self.managedObjectContext]; + [self.managedObjectContext.undoManager beginUndoGrouping]; + FeedConfig *g = [self insertSortedItemAtSelection]; g.name = @"Group"; g.type = 0; - NSLog(@"add group"); + [self.managedObjectContext.undoManager endUndoGrouping]; } - (IBAction)addSeparator:(NSButton *)sender { NSLog(@"add separator"); - // [self.managedObjectContext.undoManager beginUndoGrouping]; - // [self.managedObjectContext.undoManager endUndoGrouping]; + [self.managedObjectContext.undoManager beginUndoGrouping]; + FeedConfig *sp = [self insertSortedItemAtSelection]; + sp.name = @"-------------"; + sp.type = 2; + [self.managedObjectContext.undoManager endUndoGrouping]; } - (NSString*)copyDescriptionOfSelectedItems { @@ -130,13 +150,20 @@ static NSString *dragNodeType = @"baRSS-feed-type"; } } -- (FeedConfig*)insertNewItemAtCurrentSelection { +- (FeedConfig*)insertSortedItemAtSelection { FeedConfig *selected = [[[self arrangedObjects] descendantNodeAtIndexPath:[self selectionIndexPath]] representedObject]; + if (selected.type != 0) { // other than group + [self incrementIndicesBy:+1 forSubsequentNodes:[self selectionIndexPath]]; + } FeedConfig *newItem = [[FeedConfig alloc] initWithEntity:FeedConfig.entity insertIntoManagedObjectContext:self.managedObjectContext]; - if (selected.type == 0) // a group + if (selected.type == 0) { // a group newItem.sortIndex = (int32_t)selected.children.count; - else - newItem.sortIndex = selected.sortIndex + 1; + newItem.parent = selected; + } else { + newItem.sortIndex = selected.sortIndex; + newItem.parent = selected.parent; + --selected.sortIndex; // was increased before the new item is inserted + } return newItem; }