1/* GormSoundEditor.m 2 * 3 * Copyright (C) 2002 Free Software Foundation, Inc. 4 * 5 * Author: Gregory John Casamento <greg_casamento@yahoo.com> 6 * Date: 2002 7 * 8 * This file is part of GNUstep. 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 3 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. 23 */ 24 25#include "GormSoundEditor.h" 26#include "GormProtocol.h" 27#include "GormFunctions.h" 28#include "GormPalettesManager.h" 29#include <AppKit/NSSound.h> 30#include "GormSound.h" 31 32@implementation GormSoundEditor 33 34static NSMapTable *docMap = 0; 35 36+ (void) initialize 37{ 38 if (self == [GormSoundEditor class]) 39 { 40 docMap = NSCreateMapTable(NSNonRetainedObjectMapKeyCallBacks, 41 NSNonRetainedObjectMapValueCallBacks, 2); 42 } 43} 44 45+ (GormSoundEditor*) editorForDocument: (id<IBDocuments>)aDocument 46{ 47 id editor = NSMapGet(docMap, (void*)aDocument); 48 49 if (editor == nil) 50 { 51 editor = [[self alloc] initWithObject: nil inDocument: aDocument]; 52 AUTORELEASE(editor); 53 } 54 return editor; 55} 56 57- (NSArray *) fileTypes 58{ 59 return [NSSound soundUnfilteredFileTypes]; 60} 61 62- (NSArray *)pbTypes 63{ 64 return [NSArray arrayWithObject: GormSoundPboardType]; 65} 66 67- (NSString *) resourceType 68{ 69 return @"sound"; 70} 71 72- (id) placeHolderWithPath: (NSString *)string 73{ 74 return [GormSound soundForPath: string]; 75} 76 77- (void) addSystemResources 78{ 79 NSMutableArray *list = [NSMutableArray array]; 80 NSEnumerator *en; 81 id obj; 82 GormPalettesManager *palettesManager = [(id<Gorm>)NSApp palettesManager]; 83 84 // add all of the system objects... 85 [list addObjectsFromArray: systemSoundsList()]; 86 [list addObjectsFromArray: [palettesManager importedSounds]]; 87 en = [list objectEnumerator]; 88 while((obj = [en nextObject]) != nil) 89 { 90 GormSound *sound = [GormSound soundForPath: obj]; 91 [sound setSystemResource: YES]; 92 [self addObject: sound]; 93 } 94} 95 96/* 97 * Initialisation - register to receive DnD with our own types. 98 */ 99- (id) initWithObject: (id)anObject inDocument: (id<IBDocuments>)aDocument 100{ 101 id old = NSMapGet(docMap, (void*)aDocument); 102 103 if (old != nil) 104 { 105 RELEASE(self); 106 self = RETAIN(old); 107 [self addObject: anObject]; 108 return self; 109 } 110 111 if ((self = [super initWithObject: anObject inDocument: aDocument]) != nil) 112 { 113 NSMapInsert(docMap, (void*)aDocument, (void*)self); 114 } 115 116 return self; 117} 118 119- (void) willCloseDocument: (NSNotification *)aNotification 120{ 121 NSMapRemove(docMap,document); 122 [super willCloseDocument: aNotification]; 123} 124 125- (void) close 126{ 127 [super close]; 128 NSMapRemove(docMap,document); 129} 130@end 131