|
From: Geisschaes <gei...@us...> - 2005-06-12 15:14:08
|
Update of /cvsroot/macattrick/macattrick In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24760 Added Files: HistoryController.h HistoryController.m Log Message: history management added --- NEW FILE: HistoryController.h --- //---- license ---------------------------------------------------------------// // // // Macattrick: a Manager Assistant Tool for the online Game Hattrick.org // // Copyright (C) 2004 Roman Bertolami // // // // this file is part of Macattrick application // // http://sourceforge.net/macattrick // // // // Macattrick is free software; you can redistribute it and/or // // modify it under the terms of the GNU General Public License // // as published by the Free Software Foundation; either version 2 // // of the License, or (at your option) any later version. // // // // Macattrick is distributed in the hope that it will be useful, // // but WITHOUT ANY WARRANTY; without even the implied warranty of // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // // GNU General Public License for more details. // // // // You should have received a copy of the GNU General Public License // // along with this program; if not, write to the Free Software // // Foundation, Inc., 59 Temple Place - Suite 330, // // Boston, MA 02111-1307, USA. // // // // Macattrick, Copyright (C) 2004 Roman Bertolami // // Macattrick comes with ABSOLUTELY NO WARRANTY! // // // //---- eo licence ------------------------------------------------------------// #import <Cocoa/Cocoa.h> #import "HistoryManager.h" #import "DateStringTransformer.h" @interface HistoryController : NSObject { IBOutlet NSView *historyView; IBOutlet NSTableView *tableView; IBOutlet NSPopUpButton *choice; NSMutableArray *toRemove; HistoryManager *historyManager; NSMutableArray *dates; DateStringTransformer *transformer; } - (NSView *) historyView; - (IBAction) removeSelected: (id) sender; - (IBAction) changeChoice: (id) sender; // Data source protocoll - (int)numberOfRowsInTableView:(NSTableView *)aTableView; - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex; - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex; @end --- NEW FILE: HistoryController.m --- //---- license ---------------------------------------------------------------// // // // Macattrick: a Manager Assistant Tool for the online Game Hattrick.org // // Copyright (C) 2004 Roman Bertolami // // // // this file is part of Macattrick application // // http://sourceforge.net/macattrick // // // // Macattrick is free software; you can redistribute it and/or // // modify it under the terms of the GNU General Public License // // as published by the Free Software Foundation; either version 2 // // of the License, or (at your option) any later version. // // // // Macattrick is distributed in the hope that it will be useful, // // but WITHOUT ANY WARRANTY; without even the implied warranty of // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // // GNU General Public License for more details. // // // // You should have received a copy of the GNU General Public License // // along with this program; if not, write to the Free Software // // Foundation, Inc., 59 Temple Place - Suite 330, // // Boston, MA 02111-1307, USA. // // // // Macattrick, Copyright (C) 2004 Roman Bertolami // // Macattrick comes with ABSOLUTELY NO WARRANTY! // // // //---- eo licence ------------------------------------------------------------// #import "HistoryController.h" @interface HistoryController (Private) - (void) reload; @end @implementation HistoryController - (id) init { self = [super init]; if(self) { historyManager = [[HistoryManager alloc] init]; transformer = [[DateStringTransformer alloc] init]; [NSBundle loadNibNamed:@"HistoryView" owner: self]; [self reload]; } return self; } - (void) reload { if(dates) {[dates release];} if(toRemove) {[toRemove release];} dates = [[NSMutableArray alloc] initWithArray: [historyManager historyDates]]; toRemove = [[NSMutableArray alloc] initWithCapacity: [dates count]]; int i; for(i=0;i<[dates count];i++) { NSNumber *no = [[NSNumber alloc] initWithInt:0]; [toRemove addObject:no]; [no release]; } [tableView reloadData]; } - (IBAction) removeSelected: (id) sender { int i=0; NSMutableArray *toRemoveDirs = [[NSMutableArray alloc] init]; for (i=0; i<[dates count]; i++) { if([[toRemove objectAtIndex:i] intValue]) { [toRemoveDirs addObject: [dates objectAtIndex:i]]; } } if([toRemoveDirs count]) { NSString *question = NSLocalizedString(@"Are you shure to remove the selected dates?", @"Are you shure to remove the selected dates?"); NSString *yes =NSLocalizedString(@"Yes", @"Yes"); NSString *no =NSLocalizedString(@"No", @"No"); int questionResult = NSRunAlertPanel(@"", question, yes, no, nil); if(questionResult) { NSEnumerator *en = [toRemoveDirs objectEnumerator]; NSString *current = nil; while(current = [en nextObject]) { [historyManager removeDate:current]; } } } [self reload]; } - (NSView *) historyView { return historyView; } - (IBAction) changeChoice: (id) sender { int selected = [choice indexOfSelectedItem]; int count = [toRemove count]; int i=0; if(selected == 1) { //select all for(i=0; i<count; i++) { NSNumber *yes = [[NSNumber alloc] initWithInt:1]; [toRemove replaceObjectAtIndex:i withObject:yes]; [yes release]; } } else if(selected == 2) { // deselect all for(i=0; i<count; i++) { NSNumber *no = [[NSNumber alloc] initWithInt:0]; [toRemove replaceObjectAtIndex:i withObject:no]; [no release]; } } [tableView reloadData]; } // Data source protocoll - (int)numberOfRowsInTableView:(NSTableView *)aTableView { return [dates count]; } - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { if( [[aTableColumn identifier] isEqualToString: @"ToRemove"]) { [toRemove replaceObjectAtIndex:rowIndex withObject:anObject]; } } - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex{ if ([[aTableColumn identifier] isEqualToString: @"Date"]) { NSString *transformed = [transformer transformedValue:[dates objectAtIndex:rowIndex] ]; return transformed; } else if( [[aTableColumn identifier] isEqualToString: @"ToRemove"]) { return [toRemove objectAtIndex:rowIndex]; } else return 0; } @end |