William Bowling is sharing code with you

Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.

Don't show this again

wbowling / adium (fork of adium / adium)

Fork of Adium for patches/improvements

Clone this repository (size: 338.7 MB): HTTPS / SSH
hg clone https://bitbucket.org/wbowling/adium
hg clone ssh://hg@bitbucket.org/wbowling/adium

adium / Source / AIXtrasManager.m

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
/* 
 * Adium is the legal property of its developers, whose names are listed in the copyright file included
 * with this source distribution.
 * 
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
 * Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program; if not,
 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#import "AIXtrasManager.h"
#import "AIXtraInfo.h"
#import "AIXtraPreviewController.h"
#import <Adium/AIDockControllerProtocol.h>
#import <Adium/AIPathUtilities.h>
#import <Adium/KNShelfSplitView.h>
#import <AIUtilities/AIArrayAdditions.h>
#import <AIUtilities/AIFileManagerAdditions.h>
#import <AIUtilities/AIImageTextCell.h>
#import <AIUtilities/AIImageAdditions.h>
#import <AIUtilities/AIToolbarUtilities.h>

#define ADIUM_XTRAS_PAGE                AILocalizedString(@"http://www.adiumxtras.com/","Adium xtras page. Localized only if a translated version exists.")
#define DELETE                                  AILocalizedStringFromTable(@"Delete", @"Buttons", nil)
#define GET_MORE_XTRAS                  AILocalizedStringFromTable(@"Get More Xtras", @"Buttons", "Button in the Xtras Manager to go to adiumxtras.com to get more adiumxtras")

#define MINIMUM_SOURCE_LIST_WIDTH 40

@interface AIXtrasManager ()
- (void)installToolbar;
- (void)updateForSelectedCategory;
@end

@implementation AIXtrasManager

static AIXtrasManager *manager;

+ (AIXtrasManager *) sharedManager
{
        return manager;
}

- (void)installPlugin
{
        manager = self;
}

- (void)windowDidLoad
{
        [window setTitle:AILocalizedString(@"Xtras Manager", "Xtras Manager window title")];

        [self installToolbar];

        [tableView_categories setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleSourceList];
        
        AIImageTextCell                 *cell;
        //Configure our tableViews
        cell = [[AIImageTextCell alloc] init];
        [cell setFont:[NSFont systemFontOfSize:12]];
        [[tableView_categories tableColumnWithIdentifier:@"name"] setDataCell:cell];
        [cell release];
        
        cell = [[AIImageTextCell alloc] init];
        [cell setFont:[NSFont systemFontOfSize:12]];
        [[xtraList tableColumnWithIdentifier:@"xtras"] setDataCell:cell];
        [cell release];

        //XXX ???
        [previewContainerView setHasVerticalScroller:YES];
        [previewContainerView setAutohidesScrollers:YES];
        [previewContainerView setBorderType:NSBezelBorder];

        [tableView_categories selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO];
}

- (void)showXtras
{
        if (!window) {
                [self loadXtras];
                
                showInfo = NO;
                
                [[NSNotificationCenter defaultCenter] addObserver:self
                                                                           selector:@selector(xtrasChanged:)
                                                                                   name:AIXtrasDidChangeNotification
                                                                                 object:nil];
                [NSBundle loadNibNamed:@"XtrasManager" owner:self];
                [self windowDidLoad];
        }
                
        [window makeKeyAndOrderFront:nil];
}

- (void)windowWillClose:(NSNotification *)aNotification
{
        [[NSNotificationCenter defaultCenter] removeObserver:self
                                                                                  name:AIXtrasDidChangeNotification
                                                                                object:nil];
        
        [categories release]; categories = nil;
        [toolbarItems release]; toolbarItems = nil;

        //Release top-level nib objects besides the window
        [view_content release]; view_content = nil;
        [view_shelf release]; view_shelf = nil; 

        //XXX don't need to do this when this is a window controller
        window = nil;
}


- (void)xtrasChanged:(NSNotification *)not
{
        //Clear our cache of loaded Xtras
        [self loadXtras];
        
        //Now redisplay our current category, in case it changed
        [self updateForSelectedCategory];
}

NSInteger categorySort(id categoryA, id categoryB, void * context)
{
        return [[categoryA objectForKey:@"Name"] caseInsensitiveCompare:[categoryB objectForKey:@"Name"]];
}

- (void)loadXtras
{
        [categories release];
        categories = [[NSMutableArray alloc] init];
        
        [categories addObject:[NSDictionary dictionaryWithObjectsAndKeys:
                [NSNumber numberWithInteger:AIMessageStylesDirectory], @"Directory",
                AILocalizedString(@"Message Styles", "AdiumXtras category name"), @"Name",
                [NSImage imageNamed:@"AdiumMessageStyle"], @"Image", nil]];

        [categories addObject:[NSDictionary dictionaryWithObjectsAndKeys:
                [NSNumber numberWithInteger:AIContactListDirectory], @"Directory",
                AILocalizedString(@"Contact List Themes", "AdiumXtras category name"), @"Name",
                [NSImage imageNamed:@"AdiumListTheme"], @"Image", nil]];
        

        [categories addObject:[NSDictionary dictionaryWithObjectsAndKeys:
                [NSNumber numberWithInteger:AIStatusIconsDirectory], @"Directory",
                AILocalizedString(@"Status Icons", "AdiumXtras category name"), @"Name",
                [NSImage imageNamed:@"AdiumStatusIcons"], @"Image", nil]];
        
        [categories addObject:[NSDictionary dictionaryWithObjectsAndKeys:
                [NSNumber numberWithInteger:AISoundsDirectory], @"Directory",
                AILocalizedString(@"Sound Sets", "AdiumXtras category name"), @"Name",
                [NSImage imageNamed:@"AdiumSoundset"], @"Image", nil]];
        
        [categories addObject:[NSDictionary dictionaryWithObjectsAndKeys:
                [NSNumber numberWithInteger:AIDockIconsDirectory], @"Directory",
                AILocalizedString(@"Dock Icons", "AdiumXtras category name"), @"Name",
                [NSImage imageNamed:@"AdiumIcon"], @"Image", nil]];
        
        [categories addObject:[NSDictionary dictionaryWithObjectsAndKeys:
                [NSNumber numberWithInteger:AIEmoticonsDirectory], @"Directory",
                AILocalizedString(@"Emoticons", "AdiumXtras category name"), @"Name",
                [NSImage imageNamed:@"AdiumEmoticonset"], @"Image", nil]];
        
        [categories addObject:[NSDictionary dictionaryWithObjectsAndKeys:
                [NSNumber numberWithInteger:AIScriptsDirectory], @"Directory",
                AILocalizedString(@"Scripts", "AdiumXtras category name"), @"Name",
                [NSImage imageNamed:@"AdiumScripts"], @"Image", nil]];

        [categories addObject:[NSDictionary dictionaryWithObjectsAndKeys:
                [NSNumber numberWithInteger:AIServiceIconsDirectory], @"Directory",
                AILocalizedString(@"Service Icons", "AdiumXtras category name"), @"Name",
                [NSImage imageNamed:@"AdiumServiceIcons"], @"Image", nil]];
        
        [categories addObject:[NSDictionary dictionaryWithObjectsAndKeys:
                [NSNumber numberWithInteger:AIMenuBarIconsDirectory], @"Directory",
                AILocalizedString(@"Menu Bar Icons", "AdiumXtras category name"), @"Name",
                [NSImage imageNamed:@"AdiumMenuBarIcons"], @"Image", nil]];

        [categories addObject:[NSDictionary dictionaryWithObjectsAndKeys:
                                                   [NSNumber numberWithInteger:AIPluginsDirectory], @"Directory",
                                                   AILocalizedString(@"Plugins", "AdiumXtras category name"), @"Name",
                                                   [NSImage imageNamed:@"AdiumPlugin"], @"Image", nil]];

        
        [categories sortUsingFunction:categorySort context:NULL];
}

- (NSArray *)arrayOfXtrasAtPaths:(NSArray *)paths
{
        NSMutableArray  *contents = [NSMutableArray array];
        NSFileManager   *manager = [NSFileManager defaultManager];

        for (NSString *path in paths) {
                for (NSString *xtraName in [manager contentsOfDirectoryAtPath:path error:NULL]) {
                        if (![xtraName hasPrefix:@"."]) {
                                [contents addObject:[AIXtraInfo infoWithURL:[NSURL fileURLWithPath:[path stringByAppendingPathComponent:xtraName]]]];
                        }
                }
                
                NSString *disabledPath = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:
                                                                  [[path lastPathComponent] stringByAppendingString:@" (Disabled)"]];
                for (NSString *xtraName in [manager contentsOfDirectoryAtPath:disabledPath error:NULL]) {
                        if (![xtraName hasPrefix:@"."]) {
                                AIXtraInfo *xtraInfo = [AIXtraInfo infoWithURL:[NSURL fileURLWithPath:[disabledPath stringByAppendingPathComponent:xtraName]]];
                                [xtraInfo setEnabled:NO];
                                [contents addObject:xtraInfo];
                        }
                }               
        }

        return contents;
}

- (void)dealloc
{
        [categories release];

        [super dealloc];
}

- (NSArray *)xtrasForCategoryAtIndex:(NSInteger)inIndex
{
        if (inIndex == -1) return nil;

        NSDictionary    *xtrasDict = [categories objectAtIndex:inIndex];
        NSArray                 *xtras;
        
        if (!(xtras = [xtrasDict objectForKey:@"Xtras"])) {
                xtras = [self arrayOfXtrasAtPaths:AISearchPathForDirectories([[xtrasDict objectForKey:@"Directory"] integerValue])];
                NSMutableDictionary *newDictionary = [xtrasDict mutableCopy];
                [newDictionary setObject:xtras forKey:@"Xtras"];
                [categories replaceObjectAtIndex:inIndex
                                                          withObject:newDictionary];
                [newDictionary release];
        }
        
        return xtras;
}

- (void)updateForSelectedCategory
{
        [selectedCategory autorelease];
        selectedCategory = [[self xtrasForCategoryAtIndex:[tableView_categories selectedRow]] retain];

        [xtraList reloadData];
        if ([xtraList numberOfRows]) {
                [xtraList selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO];
        }

        [self updatePreview];
}

- (void)updatePreview
{
        AIXtraInfo *xtra = nil;

        if ([selectedCategory count] > 0 && [xtraList selectedRow] != -1) {
                xtra = [selectedCategory objectAtIndex:[xtraList selectedRow]];
        }

        if (xtra) {
                //[showInfoControl setHidden:NO];
                if(showInfo)
                        [NSBundle loadNibNamed:@"XtraInfoView" owner:self];
                else {
                        [NSBundle loadNibNamed:@"XtraPreviewImageView" owner:self];
                        /*      NSString * xtraType = [xtra type];
                        
                        if ([xtraType isEqualToString:AIXtraTypeEmoticons])
                        [NSBundle loadNibNamed:@"EmoticonPreviewView" owner:self];
                        else if ([xtraType isEqualToString:AIXtraTypeDockIcon])
                        [NSBundle loadNibNamed:@"DockIconPreviewView" owner:self];
                        else if ([xtraType isEqualToString:AIXtraTypeMessageStyle])
                        [NSBundle loadNibNamed:@"WebkitMessageStylePreviewView" owner:self];
                        else if ([xtraType isEqualToString:AIXtraTypeStatusIcons]) {
                                [NSBundle loadNibNamed:@"StatusIconPreviewView" owner:self];
                        }
                        else if ([xtraType isEqualToString:AIXtraTypeServiceIcons]) {
                                [NSBundle loadNibNamed:@"ServiceIconPreviewView" owner:self];
                        }
                        else { //catchall behavior is to just show the readme
                                [NSBundle loadNibNamed:@"XtraInfoView" owner:self];
                                [showInfoControl setHidden:YES];
                        }*/
                }
                if (previewController/* && previewContainerView*/) {
                        NSView *pv = [previewController previewView];
                        NSSize docSize = [previewContainerView documentVisibleRect].size;
                        NSRect viewFrame = [pv frame];
                        viewFrame.size.width = docSize.width;
                        if([pv respondsToSelector:@selector(image)]) viewFrame.size.height = [[(NSImageView *)pv image]size].height;
                        if(viewFrame.size.height < docSize.height) viewFrame.size.height = docSize.height;
                        [pv setFrameSize:viewFrame.size];
                        [previewContainerView setDocumentView:pv];
                        [previewController setXtra:xtra];
                        [previewContainerView setNeedsDisplay:YES];
                }               
        }
}

- (IBAction) setShowsInfo:(id)sender
{
        showInfo = ([sender selectedSegment] != 0);

        [self updatePreview];
}

- (void)deleteXtrasAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
        if (returnCode == NSAlertDefaultReturn) {
                NSFileManager * manager = [NSFileManager defaultManager];
                NSIndexSet * indices = [xtraList selectedRowIndexes];
                NSMutableSet * pathExtensions = [NSMutableSet set];
                NSString * path;
                for (NSInteger i = [indices lastIndex]; i >= 0; i--) {
                        if ([indices containsIndex:i]) {
                                path = [[selectedCategory objectAtIndex:i] path];
                                [pathExtensions addObject:[path pathExtension]];
                                [manager trashFileAtPath:path];
                        }
                }
                [xtraList selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO];
                [selectedCategory removeObjectsAtIndexes:indices];
                [xtraList reloadData];
                /*
                 XXX this is ugly. We should use the AIXtraInfo's type instead of the path extension
                */
                for (path in pathExtensions) { //usually this will only run once
                        [[NSNotificationCenter defaultCenter] postNotificationName:AIXtrasDidChangeNotification
                                                                                                          object:path];
                }
        }
}

- (IBAction) deleteXtra:(id)sender
{
        NSUInteger selectionCount = [[xtraList selectedRowIndexes] count];

        NSAlert * warning = [NSAlert alertWithMessageText:((selectionCount > 1) ?
                                                                                                           [NSString stringWithFormat:AILocalizedString(@"Delete %lu Xtras?", nil), selectionCount] :
                                                                                                           AILocalizedString(@"Delete Xtra?", nil))
                                                                                defaultButton:AILocalizedString(@"Delete", nil)
                                                                          alternateButton:AILocalizedString(@"Cancel", nil)
                                                                                  otherButton:nil
                                                        informativeTextWithFormat:((selectionCount > 1) ?
                                                                                                           AILocalizedString(@"The selected Xtras will be moved to the Trash.", nil) :
                                                                                                           AILocalizedString(@"The selected Xtra will be moved to the Trash.", nil))];
        [warning beginSheetModalForWindow:window
                                                modalDelegate:self
                                           didEndSelector:@selector(deleteXtrasAlertDidEnd:returnCode:contextInfo:)
                                                  contextInfo:nil];
}

- (IBAction)browseXtras:(id)sender
{
        [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:ADIUM_XTRAS_PAGE]];
}

- (IBAction)checkForUpdates:(id)sender
{
        
}

+ (BOOL)createXtraBundleAtPath:(NSString *)path 
{
        NSString *contentsPath  = [path stringByAppendingPathComponent:@"Contents"];
        NSString *resourcesPath = [contentsPath stringByAppendingPathComponent:@"Resources"];
        NSString *infoPlistPath = [contentsPath stringByAppendingPathComponent:@"Info.plist"];

        NSFileManager * manager = [NSFileManager defaultManager];
        NSString * name = [[path lastPathComponent] stringByDeletingPathExtension];
        if (![manager fileExistsAtPath:path]) {
                [manager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:NULL];
                [manager createDirectoryAtPath:contentsPath withIntermediateDirectories:YES attributes:nil error:NULL];

                //Info.plist
                [[NSDictionary dictionaryWithObjectsAndKeys:
                        @"English", kCFBundleDevelopmentRegionKey,
                        name, kCFBundleNameKey,
                        @"AdIM", @"CFBundlePackageType",
                        [@"com.adiumx." stringByAppendingString:name], kCFBundleIdentifierKey,
                        [NSNumber numberWithInteger:1], @"XtraBundleVersion",
                        @"1.0", kCFBundleInfoDictionaryVersionKey,
                        nil] writeToFile:infoPlistPath atomically:YES];

                //Resources
                [manager createDirectoryAtPath:resourcesPath withIntermediateDirectories:YES attributes:nil error:NULL];
        }

        BOOL isDir = NO, success;
        success = [manager fileExistsAtPath:resourcesPath isDirectory:&isDir] && isDir;
        if (success)
                success = [manager fileExistsAtPath:infoPlistPath isDirectory:&isDir] && !isDir;
        return success;
}

- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
        if (tableView == tableView_categories) {
                [cell setImage:[[categories objectAtIndex:row] objectForKey:@"Image"]];
                [cell setSubString:nil];
        }
        else {
                AIXtraInfo *xtraInfo = [selectedCategory objectAtIndex:row];
                [cell setImage:[xtraInfo icon]];
                [cell setSubString:nil];
                [cell setEnabled:[xtraInfo enabled]];
        }
}

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
        if (tableView == tableView_categories) {
                return [categories count];
        }
        else {
                return [selectedCategory count];
        }
}

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
        if (tableView == tableView_categories) {
                return [[categories objectAtIndex:row] objectForKey:@"Name"];
        } else {
                NSString * name = [[selectedCategory objectAtIndex:row] name];
                return (name != nil) ? name : @"";
        }
}

- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{
        if ([aNotification object] == xtraList) {
                //int   selectedRow = [xtraList selectedRow];
                //if ((selectedRow >= 0) && (selectedRow < [selectedCategory count])) {
                        //AIXtraInfo *xtraInfo  = [AIXtraInfo infoWithURL:[NSURL fileURLWithPath:[[selectedCategory objectAtIndex:selectedRow] path]]];
                //      if ([[xtraList selectedRowIndexes] count] == 1)
                //              [previewController setXtra:xtraInfo];
                //}
                
        } else if ([aNotification object] == tableView_categories) {
                [self updateForSelectedCategory];
        }
}

- (void)tableViewDeleteSelectedRows:(NSTableView *)tableView
{
        [self deleteXtra:tableView];
}

#pragma mark Placeholder until this is a window controller
- (NSWindow *)window
{
        return window;
}

#pragma mark Toolbar

- (void)installToolbar
{       
    NSToolbar           *toolbar = [[[NSToolbar alloc] initWithIdentifier:@"XtrasManager:Toolbar"] autorelease];
        
    [toolbar setDelegate:self];
    [toolbar setDisplayMode:NSToolbarDisplayModeIconAndLabel];
    [toolbar setSizeMode:NSToolbarSizeModeRegular];
    [toolbar setVisible:YES];
    [toolbar setAllowsUserCustomization:YES];
    [toolbar setAutosavesConfiguration:YES];
    toolbarItems = [[NSMutableDictionary alloc] init];
        
        //Delete Logs
        [AIToolbarUtilities addToolbarItemToDictionary:toolbarItems
                                                                        withIdentifier:@"delete"
                                                                                         label:DELETE
                                                                          paletteLabel:DELETE
                                                                                   toolTip:AILocalizedString(@"Delete the selection",nil)
                                                                                        target:self
                                                                   settingSelector:@selector(setImage:)
                                                                           itemContent:[NSImage imageNamed:@"remove" forClass:[self class]]
                                                                                        action:@selector(deleteXtra:)
                                                                                          menu:nil];

        [AIToolbarUtilities addToolbarItemToDictionary:toolbarItems
                                                                        withIdentifier:@"getmoreXtras"
                                                                                         label:GET_MORE_XTRAS
                                                                          paletteLabel:GET_MORE_XTRAS
                                                                                   toolTip:GET_MORE_XTRAS
                                                                                        target:self
                                                                   settingSelector:@selector(setImage:)
                                                                           itemContent:[NSImage imageNamed:@"xtras_duck" forClass:[self class]]
                                                                                        action:@selector(browseXtras:)
                                                                                          menu:nil];
        
        [[self window] setToolbar:toolbar];
}       

- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
{
    return [AIToolbarUtilities toolbarItemFromDictionary:toolbarItems withIdentifier:itemIdentifier];
}

- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
{
    return [NSArray arrayWithObjects:@"getmoreXtras", NSToolbarFlexibleSpaceItemIdentifier, @"delete", nil];
}

- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
{
    return [[toolbarItems allKeys] arrayByAddingObjectsFromArray:
                [NSArray arrayWithObjects:NSToolbarSeparatorItemIdentifier,
                        NSToolbarSpaceItemIdentifier,
                        NSToolbarFlexibleSpaceItemIdentifier,
                        NSToolbarCustomizeToolbarItemIdentifier, nil]];
}

- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
{
        if ([[theItem itemIdentifier] isEqualToString:@"delete"]) {
                return ([[xtraList selectedRowIndexes] count] > 0);

        } else {
                return YES;
        }
}

- (CGFloat)shelfSplitView:(KNShelfSplitView *)shelfSplitView validateWidth:(CGFloat)proposedWidth
{
        return ((proposedWidth > MINIMUM_SOURCE_LIST_WIDTH) ? proposedWidth : MINIMUM_SOURCE_LIST_WIDTH);
}

@end