Commit d076b4c7 authored by A. Wilcox's avatar A. Wilcox

XUI: No more X-specific account cruft for Tree controller to use.

parent 0f2eaf88
......@@ -7,15 +7,45 @@
//
#import "AuXAccountTreeController.h"
#import "AuXAccount.h"
#import "AuXAccountManager.h"
#import <Cocoa/Cocoa.h>
#include <Managers/AuAccountManager.h>
@implementation AuXAccountTreeController
@synthesize dashboard;
-(AuAccount)accountForItem:(id)item
{
AuAccount account = AuAccountManager::accounts().at([item intValue]);
return account;
}
/*!
@brief Determines if the item is editable.
@result YES if this item is an account (and editable); NO otherwise.
*/
-(BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
if([item isKindOfClass:[NSValue class]])
return YES;
else
return NO;
}
-(void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
NSAssert(([item isKindOfClass:[NSNumber class]]), @"editing item must be an account");
AuAccount account = [self accountForItem:item];
AuAccountManager::changeFriendly(account.site, [object UTF8String]);
[outlineView reloadItem:item reloadChildren:NO];
}
/*!
@brief Determines if the item is a "group" item, or a main heading.
@result YES if this item is a group item; NO otherwise.
......@@ -43,7 +73,7 @@
{
if([item isKindOfClass:[NSDictionary class]])
return YES;
else if([item isKindOfClass:[AuXAccount class]])
else if([item isKindOfClass:[NSNumber class]])
return YES;
else
return NO;
......@@ -62,8 +92,8 @@
{
if([item isKindOfClass:[NSDictionary class]])
return [[[item allObjects] objectAtIndex:0] count];
else if([item isKindOfClass:[AuXAccount class]])
return ([item site]->siteCode() == SITE_ETSY ? 4 : 6);
else if([item isKindOfClass:[NSNumber class]])
return ([self accountForItem:item].site->siteCode() == SITE_ETSY ? 4 : 6);
else
return 0;
}
......@@ -83,16 +113,30 @@
switch(index)
{
case 0: // eBay
return [[NSDictionary dictionaryWithObject:[[AuXAccountManager sharedAccountManager] accountsForSite:SITE_EBAY] forKey:@"eBay"] retain];
{
AccountVector raw = AuAccountManager::accounts();
NSMutableArray *eBays = [NSMutableArray arrayWithCapacity:raw.size()];
for(unsigned int next = 0; next < raw.size(); next++)
if(raw.at(next).site->siteCode() == SITE_EBAY)
[eBays addObject:[NSNumber numberWithInt:next]];
return [[NSDictionary dictionaryWithObject:eBays forKey:@"eBay"] retain];
}
case 1: // Etsy
return [[NSDictionary dictionaryWithObject:[[AuXAccountManager sharedAccountManager] accountsForSite:SITE_ETSY] forKey:@"Etsy"] retain];
{
AccountVector raw = AuAccountManager::accounts();
NSMutableArray *Etsys = [NSMutableArray arrayWithCapacity:raw.size()];
for(unsigned int next = 0; next < raw.size(); next++)
if(raw.at(next).site->siteCode() == SITE_ETSY)
[Etsys addObject:[NSNumber numberWithInt:next]];
return [[NSDictionary dictionaryWithObject:Etsys forKey:@"Etsy"] retain];
}
}
} else {
if([item isKindOfClass:[NSDictionary class]])
return [[[item allObjects] objectAtIndex:0] objectAtIndex:index];
else if([item isKindOfClass:[AuXAccount class]])
else if([item isKindOfClass:[NSNumber class]])
{
if([item site]->siteCode() == SITE_ETSY && index > 0) index++;
if([self accountForItem:item].site->siteCode() == SITE_ETSY && index > 0) index++;
switch(index)
{
case 0: return @"Listed";
......@@ -122,8 +166,8 @@
{
if([item isKindOfClass:[NSDictionary class]])
return [[item allKeys] objectAtIndex:0];
else if([item isKindOfClass:[AuXAccount class]])
return [item friendly];
else if([item isKindOfClass:[NSNumber class]])
return [NSString stringWithUTF8String:[self accountForItem:item].friendly];
else
return item;
}
......@@ -138,8 +182,8 @@
if([selection isKindOfClass:[NSDictionary class]])
{
NSLog(@"Site selected");
} else if([selection isKindOfClass:[AuXAccount class]]) {
[dashboard setAccount:selection];
} else if([selection isKindOfClass:[NSNumber class]]) {
[dashboard setAccount:[self accountForItem:selection]];
} else
NSLog(@"Detail selected");
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment