mamburu: Randomizing playlist is now undoable, adding playlist entry no longer causes un-randomization

CQTexperiment
Chris Moeller 2013-10-11 12:33:58 -07:00
parent 7b416e5877
commit 521eb67183
7 changed files with 75 additions and 178 deletions

View File

@ -23,7 +23,6 @@
172A12330F5911D20078EF0C /* RepeatTransformers.m in Sources */ = {isa = PBXBuildFile; fileRef = 172A12320F5911D20078EF0C /* RepeatTransformers.m */; };
172A123C0F5912AE0078EF0C /* ShuffleTransformers.m in Sources */ = {isa = PBXBuildFile; fileRef = 172A123B0F5912AE0078EF0C /* ShuffleTransformers.m */; };
172A12A90F59AF8A0078EF0C /* NSString+CogSort.m in Sources */ = {isa = PBXBuildFile; fileRef = 172A12A80F59AF8A0078EF0C /* NSString+CogSort.m */; };
173428F50D5FB1C400E8D854 /* EntriesController.m in Sources */ = {isa = PBXBuildFile; fileRef = 173428F40D5FB1C400E8D854 /* EntriesController.m */; };
17342A9A0D5FD20B00E8D854 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 17342A980D5FD20B00E8D854 /* MainMenu.xib */; };
17342ABF0D5FD36400E8D854 /* OpenURLPanel.xib in Resources */ = {isa = PBXBuildFile; fileRef = 17342ABD0D5FD36400E8D854 /* OpenURLPanel.xib */; };
173855FF0E0CC81F00488CD4 /* FileTreeOutlineView.m in Sources */ = {isa = PBXBuildFile; fileRef = 173855FE0E0CC81F00488CD4 /* FileTreeOutlineView.m */; };
@ -594,8 +593,6 @@
172A123B0F5912AE0078EF0C /* ShuffleTransformers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ShuffleTransformers.m; path = Window/ShuffleTransformers.m; sourceTree = "<group>"; };
172A12A70F59AF8A0078EF0C /* NSString+CogSort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+CogSort.h"; sourceTree = "<group>"; };
172A12A80F59AF8A0078EF0C /* NSString+CogSort.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+CogSort.m"; sourceTree = "<group>"; };
173428F30D5FB1C400E8D854 /* EntriesController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EntriesController.h; sourceTree = "<group>"; };
173428F40D5FB1C400E8D854 /* EntriesController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EntriesController.m; sourceTree = "<group>"; };
17342A990D5FD20B00E8D854 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
17342ABE0D5FD36400E8D854 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/OpenURLPanel.xib; sourceTree = "<group>"; };
173855FD0E0CC81F00488CD4 /* FileTreeOutlineView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileTreeOutlineView.h; path = FileTree/FileTreeOutlineView.h; sourceTree = "<group>"; };
@ -1513,8 +1510,6 @@
8E75753009F31D5A0080F1EE /* PlaylistEntry.m */,
8E75753309F31D5A0080F1EE /* Shuffle.h */,
8E75753409F31D5A0080F1EE /* Shuffle.m */,
173428F30D5FB1C400E8D854 /* EntriesController.h */,
173428F40D5FB1C400E8D854 /* EntriesController.m */,
170B55920D6E5E7B006B9E92 /* StatusImageTransformer.h */,
170B55930D6E5E7B006B9E92 /* StatusImageTransformer.m */,
17249F0D0D82E17700F33392 /* ToggleQueueTitleTransformer.h */,
@ -2042,7 +2037,6 @@
178BAB990CD4E1B700B33D47 /* GCOneShotEffectTimer.m in Sources */,
178BAB9A0CD4E1B700B33D47 /* GCWindowMenu.m in Sources */,
178BAB9B0CD4E1B700B33D47 /* PopupButton.m in Sources */,
173428F50D5FB1C400E8D854 /* EntriesController.m in Sources */,
5604D45B0D60349B004F5C5D /* SpotlightWindowController.m in Sources */,
5604D4F60D60726E004F5C5D /* SpotlightPlaylistEntry.m in Sources */,
56462EAF0D6341F6000AB68C /* SpotlightTransformers.m in Sources */,

View File

@ -1,24 +0,0 @@
//
// EntriesController.h
// Cog
//
// Created by Vincent Spader on 2/10/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "PlaylistEntry.h"
@interface EntriesController : NSObject {
NSUndoManager *undoManager;
NSMutableArray *playlistEntries;
}
- (NSUndoManager *)undoManager;
- (NSMutableArray *)entries;
- (void)setEntries:(NSMutableArray *)array;
- (void)insertObject:(PlaylistEntry *)pe inEntriesAtIndex:(int)index;
- (void)removeObjectFromEntriesAtIndex:(int)index;
@end

View File

@ -1,72 +0,0 @@
//
// 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

View File

@ -12,7 +12,6 @@
@class PlaylistLoader;
@class PlaylistEntry;
@class EntriesController;
@class SpotlightWindowController;
@class PlaybackController;
@ -37,7 +36,6 @@ typedef enum {
@interface PlaylistController : DNDArrayController {
IBOutlet PlaylistLoader *playlistLoader;
IBOutlet EntriesController *entriesController;
IBOutlet SpotlightWindowController *spotlightWindowController;
IBOutlet PlaybackController *playbackController;
@ -47,6 +45,8 @@ typedef enum {
NSString *totalTime;
PlaylistEntry *currentEntry;
NSUndoManager *undoManager;
}
@property(nonatomic, retain) PlaylistEntry *currentEntry;
@ -76,7 +76,7 @@ typedef enum {
- (IBAction)toggleRepeat:(id)sender;
- (IBAction)sortByPath;
- (IBAction)randomizeList;
- (IBAction)randomizeList:(id)sender;
- (IBAction)showEntryInFinder:(id)sender;
- (IBAction)clearFilterPredicate:(id)sender;

View File

@ -6,23 +6,21 @@
// Copyright 2005 Vincent Spader All rights reserved.
//
#import "PlaylistLoader.h"
#import "PlaylistController.h"
#import "PlaybackController.h"
#import "EntriesController.h"
#import "PlaylistEntry.h"
#import "PlaylistLoader.h"
#import "PlaybackController.h"
#import "Shuffle.h"
#import "SpotlightWindowController.h"
#import "RepeatTransformers.h"
#import "ShuffleTransformers.h"
#import "StatusImageTransformer.h"
#import "ToggleQueueTitleTransformer.h"
#import "TagEditorController.h"
#import "CogAudio/AudioPlayer.h"
#import "Logging.h"
#define UNDO_STACK_LIMIT 0
@implementation PlaylistController
@synthesize currentEntry;
@ -97,6 +95,11 @@
{
shuffleList = [[NSMutableArray alloc] init];
queueList = [[NSMutableArray alloc] init];
undoManager = [[NSUndoManager alloc] init];
[undoManager setLevelsOfUndo:UNDO_STACK_LIMIT];
[self initDefaults];
}
@ -108,6 +111,8 @@
{
[shuffleList release];
[queueList release];
[undoManager release];
[super dealloc];
}
@ -270,7 +275,7 @@
{
[self willInsertURLs:acceptedURLs origin:URLOriginInternal];
if (![[entriesController entries] count]) {
if (![[self content] count]) {
row = 0;
}
@ -288,50 +293,59 @@
- (NSUndoManager *)undoManager
{
return [entriesController undoManager];
return undoManager;
}
- (void)insertObjects:(NSArray *)objects atArrangedObjectIndexes:(NSIndexSet *)indexes
{
[super insertObjects:objects atArrangedObjectIndexes:indexes];
if ([self shuffle] != ShuffleOff)
[self resetShuffleList];
[[[self undoManager] prepareWithInvocationTarget:self] removeObjectsAtArrangedObjectIndexes:indexes];
NSString *actionName = [NSString stringWithFormat:@"Adding %d entries", [objects count]];
[[self undoManager] setActionName:actionName];
[super insertObjects:objects atArrangedObjectIndexes:indexes];
if ([self shuffle] != ShuffleOff)
[self resetShuffleList];
}
- (void)removeObjectsAtArrangedObjectIndexes:(NSIndexSet *)indexes
{
DLog(@"Removing indexes: %@", indexes);
DLog(@"Current index: %i", currentEntry.index);
NSArray *objects = [[self content] objectsAtIndexes:indexes];
[[[self undoManager] prepareWithInvocationTarget:self] insertObjects:objects atArrangedObjectIndexes:indexes];
NSString *actionName = [NSString stringWithFormat:@"Removing %d entries", [indexes count]];
[[self undoManager] setActionName:actionName];
DLog(@"Removing indexes: %@", indexes);
DLog(@"Current index: %i", currentEntry.index);
if (currentEntry.index >= 0 && [indexes containsIndex:currentEntry.index])
{
currentEntry.index = -currentEntry.index - 1;
DLog(@"Current removed: %i", currentEntry.index);
}
if (currentEntry.index < 0) //Need to update the negative index
{
int i = -currentEntry.index - 1;
DLog(@"I is %i", i);
int j;
for (j = i - 1; j >= 0; j--)
{
if ([indexes containsIndex:j]) {
DLog(@"Removing 1");
i--;
}
}
currentEntry.index = -i - 1;
if (currentEntry.index >= 0 && [indexes containsIndex:currentEntry.index])
{
currentEntry.index = -currentEntry.index - 1;
DLog(@"Current removed: %i", currentEntry.index);
}
if (currentEntry.index < 0) //Need to update the negative index
{
int i = -currentEntry.index - 1;
DLog(@"I is %i", i);
int j;
for (j = i - 1; j >= 0; j--)
{
if ([indexes containsIndex:j]) {
DLog(@"Removing 1");
i--;
}
}
currentEntry.index = -i - 1;
}
}
[super removeObjectsAtArrangedObjectIndexes:indexes];
if ([self shuffle] != ShuffleOff)
[self resetShuffleList];
[super removeObjectsAtArrangedObjectIndexes:indexes];
[playbackController playlistDidChange:self];
if ([self shuffle] != ShuffleOff)
[self resetShuffleList];
[playbackController playlistDidChange:self];
}
- (void)setSortDescriptors:(NSArray *)sortDescriptors
@ -354,25 +368,25 @@
[playbackController playlistDidChange:self];
}
- (IBAction)sortByPath
{
NSSortDescriptor *s = [[NSSortDescriptor alloc] initWithKey:@"url" ascending:YES selector:@selector(compare:)];
[self setSortDescriptors:[NSArray arrayWithObject:s]];
[s release];
if ([self shuffle] != ShuffleOff)
[self resetShuffleList];
}
- (IBAction)randomizeList
- (IBAction)randomizeList:(id)sender
{
[self setSortDescriptors:nil];
[self setContent:[Shuffle shuffleList:[self content]]];
if ([self shuffle] != ShuffleOff)
[self resetShuffleList];
NSArray *unrandomized = [self content];
[[[self undoManager] prepareWithInvocationTarget:self] unrandomizeList:unrandomized];
[self setContent:[Shuffle shuffleList:[self content]]];
if ([self shuffle] != ShuffleOff)
[self resetShuffleList];
[[self undoManager] setActionName:@"Playlist Randomization"];
}
- (void)unrandomizeList:(NSArray *)entries
{
[[[self undoManager] prepareWithInvocationTarget:self] randomizeList:self];
[self setContent:entries];
}
- (IBAction)toggleShuffle:(id)sender
@ -867,7 +881,7 @@
}
//Auto start playback
if (shouldPlay && [[entriesController entries] count] > 0) {
if (shouldPlay && [[self content] count] > 0) {
[playbackController playEntry: [urls objectAtIndex:0]];
}
}

View File

@ -18,9 +18,6 @@
NSMenu *headerContextMenu;
}
- (IBAction)sortByPath:(id)sender;
- (IBAction)shufflePlaylist:(id)sender;
- (IBAction)toggleColumn:(id)sender;
- (IBAction)scrollToCurrentEntry:(id)sender;

View File

@ -217,18 +217,6 @@
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:[[playlistController currentEntry] index]] byExtendingSelection:NO];
}
- (IBAction)sortByPath:(id)sender
{
[self setSortDescriptors:nil];
[playlistController sortByPath];
}
- (IBAction)shufflePlaylist:(id)sender
{
[self setSortDescriptors:nil];
[playlistController randomizeList];
}
- (IBAction)undo:(id)sender
{
[[playlistController undoManager] undo];