126 lines
3.7 KiB
Objective-C
Executable File
126 lines
3.7 KiB
Objective-C
Executable File
//
|
|
// ChapterViewController.m
|
|
// Subler
|
|
//
|
|
// Created by Damiano Galassi on 06/02/09.
|
|
// Copyright 2009 Damiano Galassi. All rights reserved.
|
|
//
|
|
|
|
#import "SBChapterViewController.h"
|
|
#import "SBTableView.h"
|
|
|
|
#import <MP42Foundation/MP42Utilities.h>
|
|
|
|
@implementation SBChapterViewController
|
|
|
|
- (void)awakeFromNib
|
|
{
|
|
NSMutableParagraphStyle * ps = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
|
|
[ps setHeadIndent: -10.0];
|
|
[ps setAlignment:NSRightTextAlignment];
|
|
|
|
detailBoldAttr = [[NSDictionary dictionaryWithObjectsAndKeys:
|
|
[NSFont boldSystemFontOfSize:11.0], NSFontAttributeName,
|
|
ps, NSParagraphStyleAttributeName,
|
|
[NSColor grayColor], NSForegroundColorAttributeName,
|
|
nil] retain];
|
|
|
|
chapterTableView.defaultEditingColumn = 1;
|
|
}
|
|
|
|
- (void)setTrack:(MP42ChapterTrack *)chapterTrack
|
|
{
|
|
track = chapterTrack;
|
|
}
|
|
|
|
- (NSAttributedString *)boldString:(NSString *)string
|
|
{
|
|
return [[[NSAttributedString alloc] initWithString:string attributes:detailBoldAttr] autorelease];
|
|
}
|
|
|
|
- (NSInteger)numberOfRowsInTableView:(NSTableView *)t
|
|
{
|
|
return [track chapterCount];
|
|
}
|
|
|
|
- (id) tableView:(NSTableView *)tableView
|
|
objectValueForTableColumn:(NSTableColumn *)tableColumn
|
|
row:(NSInteger)rowIndex
|
|
{
|
|
MP42TextSample * chapter = [track chapterAtIndex:rowIndex];
|
|
if ([tableColumn.identifier isEqualToString:@"time"])
|
|
return [self boldString:StringFromTime(chapter.timestamp, 1000)];
|
|
|
|
if ([tableColumn.identifier isEqualToString:@"title"])
|
|
return chapter.title;
|
|
|
|
return nil;
|
|
}
|
|
|
|
- (void)tableView:(NSTableView *)tableView
|
|
setObjectValue:(id)anObject
|
|
forTableColumn:(NSTableColumn *)tableColumn
|
|
row:(NSInteger)rowIndex
|
|
{
|
|
MP42TextSample * chapter = [track chapterAtIndex:rowIndex];
|
|
|
|
if ([tableColumn.identifier isEqualToString:@"title"]) {
|
|
if (![chapter.title isEqualToString:anObject]) {
|
|
[track setTitle:anObject forChapter:chapter];
|
|
|
|
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
|
}
|
|
}
|
|
else if ([tableColumn.identifier isEqualToString:@"time"]) {
|
|
MP42Duration timestamp = TimeFromString(anObject, 1000);
|
|
if (!(chapter.timestamp == timestamp)) {
|
|
[track setTimestamp:timestamp forChapter:chapter];
|
|
|
|
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
|
}
|
|
}
|
|
}
|
|
|
|
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
|
|
{
|
|
if ([chapterTableView selectedRow] != -1)
|
|
[removeChapter setEnabled:YES];
|
|
else
|
|
[removeChapter setEnabled:NO];
|
|
}
|
|
|
|
- (IBAction)removeChapter:(id)sender {
|
|
NSInteger current_index = [chapterTableView selectedRow];
|
|
if (current_index < [track chapterCount]) {
|
|
[track removeChapterAtIndex:current_index];
|
|
|
|
[chapterTableView reloadData];
|
|
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
|
}
|
|
}
|
|
|
|
- (IBAction)addChapter:(id)sender {
|
|
[track addChapter:@"Chapter" duration:0];
|
|
|
|
[chapterTableView reloadData];
|
|
[[[[[self view]window] windowController] document] updateChangeCount:NSChangeDone];
|
|
}
|
|
|
|
- (IBAction)renameChapters:(id)sender {
|
|
[track.chapters enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
|
NSString *title = [NSString stringWithFormat:@"Chapter %lu", (unsigned long) idx + 1];
|
|
[track setTitle:title forChapter:(MP42TextSample *)obj];
|
|
}];
|
|
|
|
[chapterTableView reloadData];
|
|
[[[[[self view] window] windowController] document] updateChangeCount:NSChangeDone];
|
|
}
|
|
|
|
- (void)dealloc
|
|
{
|
|
[detailBoldAttr release];
|
|
[super dealloc];
|
|
}
|
|
|
|
@end
|