Permalink
Browse files

Move code in SPNarrowDownCompletion to where it should be (part of #3062

)

Still a bit strange…
  • Loading branch information...
dmoagx committed Jun 3, 2018
1 parent 8c23f9b commit bc3b8ab575f4e981afdb3a363a280766fca0dba6
Showing with 82 additions and 88 deletions.
  1. +82 −88 Source/SPNarrowDownCompletion.m
@@ -491,69 +491,107 @@ - (NSIndexSet *)tableView:(NSTableView *)tableView selectionIndexesForProposedSe
return proposedSelectionIndexes;
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
- (NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex
{
NSString *identifier = [aTableColumn identifier];
if([identifier isEqualToString:@"image"]) {
if(!dictMode) {
if(isQueryingDatabaseStructure && rowIndex == 0) {
return [syncArrowImages objectAtIndex:currentSyncImage];
}
else {
NSImage* image = nil;
NSString *imageName = [[filtered objectAtIndex:rowIndex] objectForKey:@"image"];
if(imageName) image = [NSImage imageNamed:imageName];
return image;
// tableColumn == nil is called for a potential group row by the table view, which we don't have
if(!tableColumn) return nil;
NSString *identifier = [tableColumn identifier];
if ([identifier isEqualToString:@"list"]) {
if(
!(isQueryingDatabaseStructure && rowIndex == 0) &&
!dictMode &&
[[filtered objectAtIndex:rowIndex] objectForKey:@"list"]
) {
NSPopUpButtonCell *b = [NSPopUpButtonCell new];
[b setPullsDown:NO];
[b setAltersStateOfSelectedItem:NO];
[b setControlSize:NSMiniControlSize];
{
NSMenu *m = [[NSMenu alloc] init];
NSMenuItem *aMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Type Declaration:", @"type declaration header") action:NULL keyEquivalent:@""] autorelease];
[aMenuItem setEnabled:NO];
[m addItem:aMenuItem];
[m addItemWithTitle:[[filtered objectAtIndex:rowIndex] objectForKey:@"list"] action:NULL keyEquivalent:@""];
[b setMenu:m];
[m release];
}
[b setPreferredEdge:NSMinXEdge];
[b setArrowPosition:NSPopUpArrowAtCenter];
[b setFont:[NSFont systemFontOfSize:11]];
[b setBordered:NO];
return [b autorelease];
}
return @"";
}
else if([identifier isEqualToString:@"name"]) {
if(isQueryingDatabaseStructure && rowIndex == 0) {
return NSLocalizedString(@"fetching database structure in progress", @"fetching database structure in progress");
else if([identifier isEqualToString:@"type"]) {
if(!(isQueryingDatabaseStructure && rowIndex == 0) && !dictMode) {
NSTokenFieldCell *b = [[NSTokenFieldCell alloc] init];
[b setEditable:NO];
[b setAlignment:NSRightTextAlignment];
[b setFont:[NSFont systemFontOfSize:11]];
return [b autorelease];
}
return [[filtered objectAtIndex:rowIndex] objectForKey:@"display"];
}
else if ([identifier isEqualToString:@"list"]) {
if(isQueryingDatabaseStructure && rowIndex == 0) {
NSPopUpButtonCell *b = [[NSPopUpButtonCell new] autorelease];
else if ([identifier isEqualToString:@"path"]) {
if(
!(isQueryingDatabaseStructure && rowIndex == 0) &&
!dictMode &&
[[filtered objectAtIndex:rowIndex] objectForKey:@"path"]
) {
NSPopUpButtonCell *b = [NSPopUpButtonCell new];
[b setPullsDown:NO];
[b setArrowPosition:NSPopUpNoArrow];
[b setAltersStateOfSelectedItem:NO];
[b setControlSize:NSMiniControlSize];
{
NSMenu *m = [[NSMenu alloc] init];
for(id p in [[[[[filtered objectAtIndex:rowIndex] objectForKey:@"path"] componentsSeparatedByString:SPUniqueSchemaDelimiter] reverseObjectEnumerator] allObjects]) {
[m addItemWithTitle:p action:NULL keyEquivalent:@""];
}
if([m numberOfItems] > 2) {
[m removeItemAtIndex:[m numberOfItems]-1];
[m removeItemAtIndex:0];
}
[b setMenu:m];
[m release];
}
[b setPreferredEdge:NSMinXEdge];
[b setArrowPosition:([b numberOfItems] > 1 ? NSPopUpArrowAtCenter : NSPopUpNoArrow)];
[b setFont:[NSFont systemFontOfSize:11]];
[b setBordered:NO];
[aTableColumn setDataCell:b];
return @"";
return [b autorelease];
}
}
// ... otherwise use the default cell for the column (text field cell)
return nil;
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
NSString *identifier = [aTableColumn identifier];
if([identifier isEqualToString:@"image"]) {
if(dictMode) {
return @"";
}
if([[filtered objectAtIndex:rowIndex] objectForKey:@"list"]) {
NSPopUpButtonCell *b = [[NSPopUpButtonCell new] autorelease];
[b setPullsDown:NO];
[b setAltersStateOfSelectedItem:NO];
[b setControlSize:NSMiniControlSize];
NSMenu *m = [[NSMenu alloc] init];
NSMenuItem *aMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Type Declaration:", @"type declaration header") action:NULL keyEquivalent:@""] autorelease];
[aMenuItem setEnabled:NO];
[m addItem:aMenuItem];
[m addItemWithTitle:[[filtered objectAtIndex:rowIndex] objectForKey:@"list"] action:NULL keyEquivalent:@""];
[b setMenu:m];
[m release];
[b setPreferredEdge:NSMinXEdge];
[b setArrowPosition:NSPopUpArrowAtCenter];
[b setFont:[NSFont systemFontOfSize:11]];
[b setBordered:NO];
[aTableColumn setDataCell:b];
if(isQueryingDatabaseStructure && rowIndex == 0) {
return [syncArrowImages objectAtIndex:currentSyncImage];
}
else {
[aTableColumn setDataCell:[[NSTextFieldCell new] autorelease]];
NSImage* image = nil;
NSString *imageName = [[filtered objectAtIndex:rowIndex] objectForKey:@"image"];
if(imageName) image = [NSImage imageNamed:imageName];
return image;
}
}
else if([identifier isEqualToString:@"name"]) {
if(isQueryingDatabaseStructure && rowIndex == 0) {
return NSLocalizedString(@"fetching database structure in progress", @"fetching database structure in progress");
}
return [[filtered objectAtIndex:rowIndex] objectForKey:@"display"];
}
else if ([identifier isEqualToString:@"list"]) {
return @"";
}
else if([identifier isEqualToString:@"type"]) {
@@ -565,53 +603,9 @@ - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColu
return @"";
}
NSTokenFieldCell *b = [[[NSTokenFieldCell alloc] initTextCell:([[filtered objectAtIndex:rowIndex] objectForKey:@"type"]) ? [[filtered objectAtIndex:rowIndex] objectForKey:@"type"] : @""] autorelease];
[b setEditable:NO];
[b setAlignment:NSRightTextAlignment];
[b setFont:[NSFont systemFontOfSize:11]];
return b;
return ([[filtered objectAtIndex:rowIndex] objectForKey:@"type"] ? [[filtered objectAtIndex:rowIndex] objectForKey:@"type"] : @"");
}
else if ([identifier isEqualToString:@"path"]) {
if(isQueryingDatabaseStructure && rowIndex == 0) {
NSPopUpButtonCell *b = [[NSPopUpButtonCell new] autorelease];
[b setPullsDown:NO];
[b setArrowPosition:NSPopUpNoArrow];
[b setControlSize:NSMiniControlSize];
[b setFont:[NSFont systemFontOfSize:11]];
[b setBordered:NO];
[aTableColumn setDataCell:b];
return @"";
}
if(dictMode) {
return @"";
}
if([[filtered objectAtIndex:rowIndex] objectForKey:@"path"]) {
NSPopUpButtonCell *b = [[NSPopUpButtonCell new] autorelease];
[b setPullsDown:NO];
[b setAltersStateOfSelectedItem:NO];
[b setControlSize:NSMiniControlSize];
NSMenu *m = [[NSMenu alloc] init];
for(id p in [[[[[filtered objectAtIndex:rowIndex] objectForKey:@"path"] componentsSeparatedByString:SPUniqueSchemaDelimiter] reverseObjectEnumerator] allObjects]) {
[m addItemWithTitle:p action:NULL keyEquivalent:@""];
}
if([m numberOfItems]>2) {
[m removeItemAtIndex:[m numberOfItems]-1];
[m removeItemAtIndex:0];
}
[b setMenu:m];
[m release];
[b setPreferredEdge:NSMinXEdge];
[b setArrowPosition:([m numberOfItems]>1) ? NSPopUpArrowAtCenter : NSPopUpNoArrow];
[b setFont:[NSFont systemFontOfSize:11]];
[b setBordered:NO];
[aTableColumn setDataCell:b];
}
else {
[aTableColumn setDataCell:[[NSTextFieldCell new] autorelease]];
}
return @"";
}

0 comments on commit bc3b8ab

Please sign in to comment.