Skip to content

Commit

Permalink
More cool stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
atg committed Mar 4, 2010
1 parent 124cc82 commit 564e010
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 80 deletions.
157 changes: 95 additions & 62 deletions CHDocumentationBrowser.xib

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions IGKArrayController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@
NSUInteger maxRows;

NSPredicate *predicate;
NSArray *sortDescriptors;
NSArray *smartSortDescriptors;
NSArray *currentSortDescriptors;

NSArray *fetchedObjects;

id vipObject;
BOOL fetchContainsVipObject;

BOOL sortIsAscending;
NSString *sortColumn;
}

@property (assign) NSPredicate *predicate;
@property (assign) NSArray *sortDescriptors;
@property (assign) NSArray *smartSortDescriptors;
@property (assign) NSArray *currentSortDescriptors;
@property (assign) NSUInteger maxRows;

//The VIP object, if set, will sit at the very top of the the predicate or anything else
Expand Down
101 changes: 94 additions & 7 deletions IGKArrayController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

#import "IGKArrayController.h"
#import "Ingredients_AppDelegate.h"
#import "IGKDocRecordManagedObject.h"

@implementation IGKArrayController

@synthesize predicate;
@synthesize sortDescriptors;
@synthesize smartSortDescriptors;
@synthesize currentSortDescriptors;
@synthesize maxRows;
@synthesize vipObject;

Expand All @@ -26,27 +28,35 @@ - (void)fetch
//TODO: Eventually we want to fetch on another thread. There are still some synchronization issues to sort out
//dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{

if (!predicate)
return;

if (!currentSortDescriptors)
currentSortDescriptors = smartSortDescriptors;

NSManagedObjectContext *ctx = [[[NSApp delegate] kitController] managedObjectContext];

NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"DocRecord" inManagedObjectContext:ctx]];
[request setPredicate:predicate];

if (maxRows != 0)

[request setFetchLimit:500];
if (maxRows != 0 && maxRows < 500)
{
//Limit the list to 100 items. This could be changed to more, if requested, but my view is that if anybody needs more than 100, our sorting isn't smart enough
[request setFetchLimit:maxRows];
}

//Sort results by priority, so that when we LIMIT our list, only the low priority items are cut
[request setSortDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"priority" ascending:NO]]];
//Fetch a list of <= 100 objects

//Fetch a list of objects
fetchedObjects = [ctx executeFetchRequest:request error:nil];

//NSFetchRequests and NSComparator-based sort descriptors apparently don't go together, so we can't tell the fetch request to sort using this descriptor
//Besides, it's far better to be sorting 100 objects with our expensive comparator than 10000
fetchedObjects = [fetchedObjects sortedArrayUsingDescriptors:sortDescriptors];
fetchedObjects = [fetchedObjects sortedArrayUsingDescriptors:currentSortDescriptors];

if ([fetchedObjects containsObject:vipObject])
fetchContainsVipObject = YES;
Expand Down Expand Up @@ -136,6 +146,77 @@ - (id)selection
return [fetchedObjects objectAtIndex:row];
}

- (void)tableView:(NSTableView *)tv sortDescriptorsDidChange:(NSArray *)oldDescriptors
{
currentSortDescriptors = [tableView sortDescriptors];
if (![currentSortDescriptors count])
{
currentSortDescriptors = smartSortDescriptors;
}
else
{
id firstObject = [currentSortDescriptors objectAtIndex:0];
id newSortDescriptor = firstObject;

if ([[firstObject key] isEqual:@"xentity"])
{
newSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:[firstObject ascending] comparator:^ NSComparisonResult (id obja, id objb) {

//So neither a nor b starts with q. Now we apply prioritization. Some types get priority over others. For instance, a class > method > typedef > constant
NSUInteger objaPriority = [[obja valueForKey:@"priority"] shortValue];
NSUInteger objbPriority = [[objb valueForKey:@"priority"] shortValue];

//Higher priorities are better
if (objaPriority > objbPriority)
return NSOrderedAscending;
else if (objaPriority < objbPriority)
return NSOrderedDescending;

//If the have the same priority, just compare the names of their entities (this is arbitrary, we just want to make sure there isn't an enum between two structs)
return [[[obja entity] name] localizedCompare:[[objb entity] name]];
}];
}
else if ([[firstObject key] isEqual:@"xcontainername"])
{
BOOL isAsc = [firstObject ascending];
newSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:YES comparator:^ NSComparisonResult (id obja, id objb) {
id a = [obja xcontainername];
id b = [objb xcontainername];

BOOL hasA = ([a length] != 0);
BOOL hasB = ([b length] != 0);

if (hasA == hasB)
{
NSComparisonResult r = [a localizedCompare:b];
if (isAsc)
return r;

//If this is a descending sort, then invert the result of the comparison
//We do this instead of using the ascending: option because items with an empty container name should always appear at the bottom, regardless of sort direction
if (r == NSOrderedAscending)
return NSOrderedDescending;

if (r == NSOrderedDescending)
return NSOrderedAscending;

return NSOrderedSame;
}
else if (hasA && !hasB)
{
return NSOrderedAscending;
}

return NSOrderedDescending;
}];
}

currentSortDescriptors = [NSArray arrayWithObject:newSortDescriptor];
}

[self refresh];
}

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tv
{
return [fetchedObjects count] + (vipObject && !fetchContainsVipObject ? 1 : 0);
Expand Down Expand Up @@ -171,6 +252,12 @@ - (id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)tab
return [fo valueForKey:@"name"];
}

//*** Container Names ***
if ([identifier isEqual:@"xcontainername"])
{
return [fo valueForKey:@"xcontainername"];
}

return nil;
}

Expand Down
3 changes: 3 additions & 0 deletions IGKDocRecordManagedObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ typedef enum {

- (CHRecordPriority)priorityval;

- (NSString *)xcontainername;
- (IGKDocRecordManagedObject *)xcontainer;

@end
13 changes: 13 additions & 0 deletions IGKDocRecordManagedObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ - (CHRecordPriority)priorityval
return CHPriorityOther;
}

- (NSString *)xcontainername
{
return [[self xcontainer] valueForKey:@"name"];
}
- (IGKDocRecordManagedObject *)xcontainer
{
NSDictionary *relationships = [[self entity] relationshipsByName];
if ([relationships objectForKey:@"container"])
return [self valueForKey:@"container"];

return [self valueForKey:@"misccontainer"];
}

- (NSImage *)normalIcon
{
return [self iconForSelectedState:NO];
Expand Down
1 change: 0 additions & 1 deletion IGKMatteSegmentedControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ - (void)drawRect:(NSRect)rect

int i;
float runningY = 0.0;
//NSLog(@"[self segmentCount] = %d", [self segmentCount]);
float sely = 0.0;
for (i = 0; i < [self segmentCount]; i++)
{
Expand Down
5 changes: 1 addition & 4 deletions IGKScraper.m
Original file line number Diff line number Diff line change
Expand Up @@ -1018,9 +1018,7 @@ - (void)createMethodNamed:(NSString *)name description:(NSString *)description p
{
if (name == nil)
return;

//NSLog(@"name / proto = %@ -- %@", name, prototype);


IGKDocRecordManagedObject *newMethod = [[IGKDocRecordManagedObject alloc] initWithEntity:methodEntity insertIntoManagedObjectContext:transientContext];

[newMethod setValue:name forKey:@"name"];
Expand Down Expand Up @@ -1392,7 +1390,6 @@ - (void)createMethodNamed:(NSString *)name description:(NSString *)description p
if (name == nil)
return;

//NSLog(@"createMethodNamed = %@", name);
IGKDocRecordManagedObject *newMethod = [[IGKDocRecordManagedObject alloc] initWithEntity:methodEntity insertIntoManagedObjectContext:ctx];

[newMethod setValue:name forKey:@"name"];
Expand Down
14 changes: 10 additions & 4 deletions IGKWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ - (void)windowDidLoad

if (shouldIndex)
[self startIndexing];
else
[self setBrowserActive:NO];

[searchViewTable setTarget:self];
[searchViewTable setDoubleAction:@selector(advancedSearchDoubleAction:)];
Expand Down Expand Up @@ -149,9 +151,9 @@ - (void)windowDidLoad
}];

[sideSearchController setMaxRows:100];
[sideSearchController setSortDescriptors:[NSArray arrayWithObject:sideSortDescriptor]];
[sideSearchController setSmartSortDescriptors:[NSArray arrayWithObject:sideSortDescriptor]];

[advancedController setSortDescriptors:[NSArray arrayWithObject:sideSortDescriptor]];
[advancedController setSmartSortDescriptors:[NSArray arrayWithObject:sideSortDescriptor]];

[searchViewPredicateEditor addRow:nil];

Expand Down Expand Up @@ -587,7 +589,6 @@ - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColum

- (void)advancedSearchDoubleAction:(id)sender
{
NSLog(@"Double action");
[self sideSearchTableChangedSelection];
}
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
Expand Down Expand Up @@ -625,7 +626,9 @@ - (void)sideSearchTableChangedSelection
else if ([sideSearchController selection] == nil)
{
[self setBrowserActive:NO];

[self reloadTableOfContents];
acceptableDisplayTypes = 0;

return;
}

Expand Down Expand Up @@ -667,6 +670,9 @@ - (IGKArrayController *)currentArrayController
- (void)loadDocIntoBrowser
{
//Generate the HTML
if (![[self currentArrayController] selection])
return;

IGKHTMLGenerator *generator = [[IGKHTMLGenerator alloc] init];
[generator setContext:[[[NSApp delegate] valueForKey:@"kitController"] managedObjectContext]];
[generator setManagedObject:[[self currentArrayController] selection]];
Expand Down

0 comments on commit 564e010

Please sign in to comment.