3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.fr/>.
5 It may be used under the terms of the GNU General Public License. */
7 #include "ChapterTitles.h"
10 @implementation ChapterTitles
22 - (void)resetWithTitle:(hb_title_t *)title
25 NSString *chapterString;
32 int count = hb_list_count( title->list_chapter );
34 for( i = 0; i < count; i++ )
36 hb_chapter_t *chapter = hb_list_item( title->list_chapter, i );
38 if( chapter != NULL && chapter->title[0] == '\0' )
40 chapterString = [NSString stringWithFormat:@"Chapter %2d",(i+1)];
42 strncpy( chapter->title, [chapterString UTF8String], 1023);
43 chapter->title[1023] = '\0';
49 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
57 return hb_list_count( fTitle->list_chapter );
61 - (void)tableView:(NSTableView *)aTableView
62 setObjectValue:(id)anObject
63 forTableColumn:(NSTableColumn *)aTableColumn
64 row:(NSInteger)rowIndex
66 if(aTableColumn != nil && [[aTableColumn identifier] intValue] == 2)
70 hb_chapter_t *chapter = hb_list_item( fTitle->list_chapter, rowIndex );
74 strncpy( chapter->title, [anObject UTF8String], 1023);
75 chapter->title[1023] = '\0';
81 - (id)tableView:(NSTableView *)aTableView
82 objectValueForTableColumn:(NSTableColumn *)aTableColumn
83 row:(NSInteger)rowIndex
85 NSString *cellEntry = @"__DATA ERROR__";
87 if([[aTableColumn identifier] intValue] == 1)
89 cellEntry = [NSString stringWithFormat:@"%d",rowIndex+1];
95 hb_chapter_t *chapter = hb_list_item( fTitle->list_chapter, rowIndex );
99 cellEntry = [NSString stringWithUTF8String:chapter->title];
107 /* Method to edit the next chapter when the user presses Return. We have to use
108 a timer to avoid interfering with the chain of events that handles the edit. */
109 - (void)controlTextDidEndEditing: (NSNotification *) notification
111 NSTableView *chapterTable = [notification object];
112 NSInteger column = [chapterTable editedColumn];
113 NSInteger row = [chapterTable editedRow];
114 NSInteger textMovement;
116 // Edit the cell in the next row, same column
118 textMovement = [[[notification userInfo] objectForKey:@"NSTextMovement"] integerValue];
119 if( textMovement == NSReturnTextMovement && row < [chapterTable numberOfRows] )
121 NSArray *info = [NSArray arrayWithObjects:chapterTable,
122 [NSNumber numberWithInteger:column], [NSNumber numberWithInteger:row], nil];
123 /* The delay is unimportant; editNextRow: won't be called until the responder
124 chain finishes because the event loop containing the timer is on this thread */
125 [self performSelector:@selector(editNextRow:) withObject:info afterDelay:0.0];
129 - (void)editNextRow: (id) objects
131 NSTableView *chapterTable = [objects objectAtIndex:0];
132 NSInteger column = [[objects objectAtIndex:1] integerValue];
133 NSInteger row = [[objects objectAtIndex:2] integerValue];
135 if( row >= 0 && row < [chapterTable numberOfRows] )
137 [chapterTable selectRow:row byExtendingSelection:NO];
138 [chapterTable editColumn:column row:row withEvent:nil select:YES];