/*
Copyright (C) 2002-2003, Jeffrey D. Argast.
The authors make NO WARRANTY or representation, either express or implied,
with respect to this software, its quality, accuracy, merchantability, or
fitness for a particular purpose. This software is provided "AS IS", and you,
its user, assume the entire risk as to its quality and accuracy.
Permission is hereby granted to use, copy, modify, and distribute this
software or portions thereof for any purpose, without fee, subject to these
conditions:
(1) If any part of the source code is distributed, then this
statement must be included, with this copyright and no-warranty notice
unaltered.
(2) Permission for use of this software is granted only if the user accepts
full responsibility for any undesirable consequences; the authors accept
NO LIABILITY for damages of any kind.
*/
#import "BranchesController.h"
#import "IconDefs.h"
#import "PerforceActionBranches.h"
#import "MessageDefs.h"
static NSString* kBrowserCellColumnName = @"getBranchName";
static NSString* kDefaultSortColumnKey = @"BranchesSortColumn";
static NSString* kDefaultSortDirectionKey = @"BranchesSortDirection";
@implementation BranchesController
+ (void) initialize
{
NSMutableDictionary* defaultValues = [NSMutableDictionary dictionary];
[defaultValues setObject:kBrowserCellColumnName forKey:kDefaultSortColumnKey];
[defaultValues setObject:[NSNumber numberWithBool:YES] forKey:kDefaultSortDirectionKey];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
}
- (void) awakeFromNib
{
fTableView = fBranchesView;
fIconID = kBranchesIcon;
fIconColumnName = kBrowserCellColumnName;
//fPerforceActionMethod = @selector(branches);
fDefaultSortColumnKey = kDefaultSortColumnKey;
fDefaultSortDirectionKey = kDefaultSortDirectionKey;
NSNotificationCenter* nCenter = [NSNotificationCenter defaultCenter];
[nCenter addObserver:self selector:@selector(branchChanged:) name:kBranchChanged object:nil];
[super setUpCell];
[fBranchesView setAutosaveName:@"BranchesTableInfo"];
[fBranchesView setAutosaveTableColumns:YES];
}
- (void) branchChanged:(NSNotification*) notification
{
[self refreshData];
}
- (void) resultFromPerforce: (PerforceActionBranches*) action
{
if ( [action wasSuccess] )
{
[fChildren setArray:[action getBranches]];
[self sortChildren];
}
}
- (void) buildChildren
{
fChildren = [[NSMutableArray alloc] init];
[PerforceActionBranches defaultRunFor:self selector:@selector(resultFromPerforce:)];
}
- (void) doubleClick: (id) sender
{
[self doDescribe];
}
// The enablement
- (BOOL) canEdit
{
id <BranchProtocol> selection = [self getSelection];
return [selection canEdit];
}
- (BOOL) canDescribe
{
id <BranchProtocol> selection = [self getSelection];
return [selection canDescribe];
}
- (BOOL) canDelete
{
id <BranchProtocol> selection = [self getSelection];
return [selection canDelete];
}
// The actions
- (void) doEdit
{
id <BranchProtocol> selection = [self getSelection];
[selection doEdit];
}
- (void) doDescribe
{
id <BranchProtocol> selection = [self getSelection];
[selection doDescribe];
}
- (void) doDelete
{
id <BranchProtocol> selection = [self getSelection];
[selection doDelete];
}
@end