/* 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 "SubmittedChangesController.h" #import "IconDefs.h" #import "PerforceActionChangesSubmitted.h" #import "MessageDefs.h" #import "PerforceFileRevision.h" #import "PerforceActionDescribe.h" #import "ReadOnlyEditorController.h" #import "PerforceSubmittedChange.h" #import "AppUtils.h" #import "SubmittedChangeView.h" static NSString* kBrowserCellColumnName = @"getChangeNumber"; static NSString* kDefaultSortColumnKey = @"SubmittedChangesSortColumn"; static NSString* kDefaultSortDirectionKey = @"SubmittedChangesSortDirection"; @implementation SubmittedChangesController + (void) initialize { NSMutableDictionary* defaultValues = [NSMutableDictionary dictionary]; [defaultValues setObject:kBrowserCellColumnName forKey:kDefaultSortColumnKey]; [defaultValues setObject:[NSNumber numberWithBool:NO] forKey:kDefaultSortDirectionKey]; [[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues]; } - (void) dealloc { [fFilterPath release]; [super dealloc]; } - (void) doubleClick: (id) sender { [self doDescribe]; } - (void) handleContentChanged: (NSNotification*) aNotification { [self refreshData]; } - (void) awakeFromNib { fTableView = fSubmittedView; fIconID = kSubmittedChangeIcon; fIconColumnName = kBrowserCellColumnName; fFilterPath = [[NSString alloc] initWithString:@""]; //fPerforceActionMethod = @selector(allsubmittedchanges); fDefaultSortColumnKey = kDefaultSortColumnKey; fDefaultSortDirectionKey = kDefaultSortDirectionKey; [fSubmittedView registerForDraggedTypes:[NSArray arrayWithObject:NSStringPboardType]]; [fFilterPathEditBox registerForDraggedTypes:[NSArray arrayWithObject:NSStringPboardType]]; [super setUpCell]; NSNotificationCenter* nCenter = [NSNotificationCenter defaultCenter]; [nCenter addObserver:self selector:@selector(handleContentChanged:) name:kDefaultsNumChangesToFetchChanged object:nil]; [nCenter addObserver:self selector:@selector(handleContentChanged:) name:kActionSubmitSucceeded object:nil]; [fSubmittedView setAutosaveName:@"SubmittedChangesTableInfo"]; [fSubmittedView setAutosaveTableColumns:YES]; } - (void) resultFromPerforce: (PerforceActionChangesSubmitted*) action { if ( [action wasSuccess] ) { [fChildren setArray:[action getChangesSubmitted]]; [self sortChildren]; } } - (void) buildChildren { fChildren = [[NSMutableArray alloc] init]; [PerforceActionChangesSubmitted defaultRunFor:self selector:@selector(resultFromPerforce:) withPath:fFilterPath]; } - (void) setFilterPath: (NSString*) newPath { if ( ![newPath isEqualToString:fFilterPath] ) { [fFilterPath release]; fFilterPath = [newPath retain]; [self refreshData]; } } - (void)controlTextDidEndEditing:(NSNotification *)aNotification { NSString* newPath = [fFilterPathEditBox stringValue]; [self setFilterPath:newPath]; } - (void) textDidClear:(id)sender { NSString* newPath = [fFilterPathEditBox stringValue]; [self setFilterPath:newPath]; } // This method is used by NSTableView to determine a valid drop target. // Based on the mouse position, the table view will suggest a proposed drop // location. This method must return a value that indicates which dragging // operation the data source will perform. The data source may "re-target" a // drop if desired by calling setDropRow:dropOperation: and returning something // other than NSDragOperationNone. One may choose to re-target for various // reasons (eg. for better visual feedback when inserting into a sorted position). - (NSDragOperation) tableView:(NSTableView*)tv validateDrop:(id )info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op { [tv setDropRow:-1 dropOperation:NSTableViewDropOn]; //NSLog (@"drop row = %d, op = %d", row, op); return NSDragOperationCopy; } // This method is called when the mouse is released over an outline view that // previously decided to allow a drop via the validateDrop method. The data // source should incorporate the data from the dragging pasteboard at this time. - (BOOL) tableView:(NSTableView*)tv acceptDrop:(id )info row:(int)row dropOperation:(NSTableViewDropOperation)op { NSPasteboard* pb = [info draggingPasteboard]; NSString* value = ReadStringFromPasteboard (pb); if ( value ) { [fFilterPathEditBox setStringValue:value]; [self setFilterPath:value]; return YES; } return NO; } // The enablement - (BOOL) canDescribe { id selection = [self getSelection]; return [selection canDescribe]; } - (BOOL) canSyncTo { id selection = [self getSelection]; return [selection canSyncTo]; } - (BOOL) canSyncOnly { id selection = [self getSelection]; return [selection canSyncOnly]; } // The actions - (void) doDescribe { id selection = [self getSelection]; [selection doDescribe]; } - (void) doSyncTo { id selection = [self getSelection]; [selection doSyncTo]; } - (void) doSyncOnly { id selection = [self getSelection]; [selection doSyncOnly]; } @end