From 803a3306a563543f9789b75d5b0ce7bf677e392f Mon Sep 17 00:00:00 2001 From: vspader Date: Sun, 10 Feb 2008 22:55:16 +0000 Subject: [PATCH] Forgot to add these files for undo support. --- Playlist/EntriesController.h | 23 ++++++++++++ Playlist/EntriesController.m | 72 ++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 Playlist/EntriesController.h create mode 100644 Playlist/EntriesController.m diff --git a/Playlist/EntriesController.h b/Playlist/EntriesController.h new file mode 100644 index 000000000..62245a7eb --- /dev/null +++ b/Playlist/EntriesController.h @@ -0,0 +1,23 @@ +// +// EntriesController.h +// Cog +// +// Created by Vincent Spader on 2/10/08. +// Copyright 2008 __MyCompanyName__. All rights reserved. +// + +#import +#import "PlaylistEntry.h" + +@interface EntriesController : NSObject { + NSUndoManager *undoManager; + NSMutableArray *playlistEntries; +} + +- (NSMutableArray *)entries; +- (void)setEntries:(NSMutableArray *)array; +- (void)insertObject:(PlaylistEntry *)pe inEntriesAtIndex:(int)index; +- (void)removeObjectFromEntriesAtIndex:(int)index; + + +@end diff --git a/Playlist/EntriesController.m b/Playlist/EntriesController.m new file mode 100644 index 000000000..bf741639f --- /dev/null +++ b/Playlist/EntriesController.m @@ -0,0 +1,72 @@ +// +// EntriesController.m +// Cog +// +// Created by Vincent Spader on 2/10/08. +// Copyright 2008 __MyCompanyName__. All rights reserved. +// + +#import "EntriesController.h" + +#define UNDO_STACK_LIMIT 0 + +@implementation EntriesController + +- (id)init +{ + self = [super init]; + + if (self) + { + playlistEntries = [[NSMutableArray alloc] init]; + undoManager = [[NSUndoManager alloc] init]; + + [undoManager setLevelsOfUndo:UNDO_STACK_LIMIT]; + } + + return self; +} + +- (void)dealloc +{ + [playlistEntries release]; + [undoManager release]; + + [super dealloc]; +} + +- (NSUndoManager *)undoManager +{ + return undoManager; +} + +- (NSMutableArray *)entries +{ + return playlistEntries; +} + +- (void)setEntries:(NSMutableArray *)array +{ + if (array == playlistEntries) + return; + + [array retain]; + [playlistEntries release]; + playlistEntries = array; +} + +- (void)insertObject:(PlaylistEntry *)pe inEntriesAtIndex:(int)index +{ + [[[self undoManager] prepareWithInvocationTarget:self] removeObjectFromEntriesAtIndex:index]; + [playlistEntries insertObject:pe atIndex:index]; +} + +- (void)removeObjectFromEntriesAtIndex:(int)index +{ + [[[self undoManager] prepareWithInvocationTarget:self] insertObject:[playlistEntries objectAtIndex:index] inEntriesAtIndex:index]; + + [playlistEntries removeObjectAtIndex:index]; +} + + +@end