1/* 2 * Copyright (c) 2004-2007 Apple Inc. All rights reserved. 3 * 4 * IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in 5 * consideration of your agreement to the following terms, and your use, installation, 6 * modification or redistribution of this Apple software constitutes acceptance of these 7 * terms. If you do not agree with these terms, please do not use, install, modify or 8 * redistribute this Apple software. 9 * 10 * In consideration of your agreement to abide by the following terms, and subject to these 11 * terms, Apple grants you a personal, non exclusive license, under Apple�s copyrights in this 12 * original Apple software (the �Apple Software�), to use, reproduce, modify and redistribute 13 * the Apple Software, with or without modifications, in source and/or binary forms; provided 14 * that if you redistribute the Apple Software in its entirety and without modifications, you 15 * must retain this notice and the following text and disclaimers in all such redistributions 16 * of the Apple Software. Neither the name, trademarks, service marks or logos of Apple 17 * Computer, Inc. may be used to endorse or promote products derived from the Apple Software 18 * without specific prior written permission from Apple. Except as expressly stated in this 19 * notice, no other rights or licenses, express or implied, are granted by Apple herein, 20 * including but not limited to any patent rights that may be infringed by your derivative 21 * works or by other works in which the Apple Software may be incorporated. 22 * 23 * The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, 24 * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON- 25 * INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE 26 * SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 27 * 28 * IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 30 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, 31 * REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND 32 * WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR 33 * OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36//����������������������������������������������������������������������������� 37// Imports 38//����������������������������������������������������������������������������� 39 40#import "SCSITargetProberDocument.h" 41#import "SCSITargetProberKeys.h" 42#import <Foundation/NSKeyValueObserving.h> 43 44 45//����������������������������������������������������������������������������� 46// Constants 47//����������������������������������������������������������������������������� 48 49static NSString * SCSIDocToolbarIdentifier = @"com.apple.dts.SCSIDocToolbarIdentifier"; 50static NSString * SCSIDocInfoIdentifier = @"com.apple.dts.SCSIDocInfoIdentifier"; 51static NSString * SCSIDocPrefsIdentifier = @"com.apple.dts.SCSIDocPrefsIdentifier"; 52static NSString * SCSIDocNibName = @"SCSITargetProberDocument"; 53 54#define kNumTableColumns 5 55 56 57//����������������������������������������������������������������������������� 58// Implementation 59//����������������������������������������������������������������������������� 60 61@implementation SCSITargetProberDocument 62 63 64// Factory method to create a new SCSITargetProberDocument. 65 66+ ( id ) newDocument: ( NSArray * ) i 67{ 68 69 id doc = [ [ SCSITargetProberDocument alloc ] initWithInitiators: i ]; 70 [ NSBundle loadNibNamed: SCSIDocNibName owner: doc ]; 71 [ doc setupToolbar ]; 72 73 return doc; 74 75} 76 77 78- ( id ) initWithInitiators: ( NSArray * ) i 79{ 80 81 self = [ super init ]; 82 if ( self != nil ) 83 { 84 85 [ self setInvisibleTableColumns: [ [ [ NSMutableDictionary alloc ] initWithCapacity: kNumTableColumns ] autorelease ] ]; 86 [ self setInitiators: i ]; 87 [ controller setSelectionIndex: 0 ]; 88 89 } 90 91 return self; 92 93} 94 95 96- ( void ) dealloc 97{ 98 99 [ self setInvisibleTableColumns: nil ]; 100 [ self setInitiators: nil ]; 101 [ super dealloc ]; 102 103} 104 105 106- ( NSString * ) windowNibName 107{ 108 return SCSIDocNibName; 109} 110 111 112// Called when the SCSITargetProberDocument nib loads. 113 114- ( void ) awakeFromNib 115{ 116 117 id values = nil; 118 id column = nil; 119 120 // We use a clever caching scheme for the table columns. We save the 121 // NSTableColumn in an NSDictionary and use the column identifier as the 122 // dictionary key. This allows us to 1) retain the NSTableColumn 123 // and 2) allows us to easily look up the table column when it comes time to 124 // add it back into the NSTableView. Retaining the NSTableColumn is 125 // beneficial because it preserves the Cocoa Bindings we set up in 126 // InterfaceBuilder and it means we don't have to create an NSTableColumn 127 // on-the-fly AND establish bindings for it (which is a very tedious process). 128 // 129 // NB: This isn't always a win (it requires more memory), but it is a win in this 130 // case since the number of table columns maxes out at 5. 131 132 // Pull the initial user defaults to determine which columns to show. By 133 // default, we built the nib to have all 5 possible columns. 134 // We remove whichever ones aren't required, based on saved/default preferences. 135 values = [ [ NSUserDefaultsController sharedUserDefaultsController ] values ]; 136 137 // Does the user want the "ID" field visible? 138 if ( [ [ values valueForKey: kShowTargetIDString ] boolValue ] == NO ) 139 { 140 141 // No, remove the table column. 142 column = [ table tableColumnWithIdentifier: kTableColumnIDString ]; 143 [ invisibleTableColumns setObject: column forKey: kTableColumnIDString ]; 144 [ table removeTableColumn: column ]; 145 146 } 147 148 // Does the user want the "Description" field visible? 149 if ( [ [ values valueForKey: kShowDescriptionString ] boolValue ] == NO ) 150 { 151 152 // No, remove the table column. 153 column = [ table tableColumnWithIdentifier: kTableColumnDescriptionString ]; 154 [ invisibleTableColumns setObject: column forKey: kTableColumnDescriptionString ]; 155 [ table removeTableColumn: column ]; 156 157 } 158 159 // Does the user want the "Revision" field visible? 160 if ( [ [ values valueForKey: kShowRevisionString ] boolValue ] == NO ) 161 { 162 163 // No, remove the table column. 164 column = [ table tableColumnWithIdentifier: kTableColumnRevisionString ]; 165 [ invisibleTableColumns setObject: column forKey: kTableColumnRevisionString ]; 166 [ table removeTableColumn: column ]; 167 168 } 169 170 // Does the user want the "Features" field visible? 171 if ( [ [ values valueForKey: kShowFeaturesString ] boolValue ] == NO ) 172 { 173 174 // No, remove the table column. 175 column = [ table tableColumnWithIdentifier: kTableColumnFeaturesString ]; 176 [ invisibleTableColumns setObject: column forKey: kTableColumnFeaturesString ]; 177 [ table removeTableColumn: column ]; 178 179 } 180 181 // Does the user want the "PDT" field visible? 182 if ( [ [ values valueForKey: kShowPDTString ] boolValue ] == NO ) 183 { 184 185 // No, remove the table column. 186 column = [ table tableColumnWithIdentifier: kTableColumnPDTString ]; 187 [ invisibleTableColumns setObject: column forKey: kTableColumnPDTString ]; 188 [ table removeTableColumn: column ]; 189 190 } 191 192 // Observe any value changes to NSUserDefaultsController. This registers us 193 // for notifications when the prefs window checkboxes change. 194 [ [ NSUserDefaultsController sharedUserDefaultsController ] addObserver: self 195 forKeyPath: kShowTargetIDKeyPath options: NSKeyValueObservingOptionNew context: nil ]; 196 197 [ [ NSUserDefaultsController sharedUserDefaultsController ] addObserver: self 198 forKeyPath: kShowDescriptionKeyPath options: NSKeyValueObservingOptionNew context: nil ]; 199 200 [ [ NSUserDefaultsController sharedUserDefaultsController ] addObserver: self 201 forKeyPath: kShowRevisionKeyPath options: NSKeyValueObservingOptionNew context: nil ]; 202 203 [ [ NSUserDefaultsController sharedUserDefaultsController ] addObserver: self 204 forKeyPath: kShowFeaturesKeyPath options: NSKeyValueObservingOptionNew context: nil ]; 205 206 [ [ NSUserDefaultsController sharedUserDefaultsController ] addObserver: self 207 forKeyPath: kShowPDTKeyPath options: NSKeyValueObservingOptionNew context: nil ]; 208 209} 210 211 212// Called when values change for NSUserDefaultsController. 213// See NSKeyValueObserving.h for more information. 214 215- ( void ) observeValueForKeyPath: ( NSString * ) keyPath 216 ofObject: ( id ) object 217 change: ( NSDictionary * ) change 218 context: ( void * ) context 219{ 220 221#pragma unused ( change ) 222#pragma unused ( context ) 223 224 id column = nil; 225 BOOL showTargetID = NO; 226 BOOL showDescription = NO; 227 BOOL showRevision = NO; 228 BOOL showFeatures = NO; 229 BOOL showPDT = NO; 230 int numColumns = 0; 231 232 // Get the new defaults. 233 showTargetID = [ [ [ object values ] valueForKey: kShowTargetIDString ] boolValue ]; 234 showDescription = [ [ [ object values ] valueForKey: kShowDescriptionString ] boolValue ]; 235 showRevision = [ [ [ object values ] valueForKey: kShowRevisionString ] boolValue ]; 236 showFeatures = [ [ [ object values ] valueForKey: kShowFeaturesString ] boolValue ]; 237 showPDT = [ [ [ object values ] valueForKey: kShowPDTString ] boolValue ]; 238 numColumns = [ table numberOfColumns ]; 239 240 // Is the key path which changed "ID"? 241 if ( [ keyPath isEqual: kShowTargetIDKeyPath ] ) 242 { 243 244 // Yes, it changed. What is the value? 245 if ( showTargetID == NO ) 246 { 247 248 // "ID" column should not be visible. Remove it from the table column. 249 column = [ table tableColumnWithIdentifier: kTableColumnIDString ]; 250 [ invisibleTableColumns setObject: column forKey: kTableColumnIDString ]; 251 [ table removeTableColumn: column ]; 252 253 } 254 255 else 256 { 257 258 // "ID" column should be visible. Add the table column back into the table. 259 column = [ invisibleTableColumns objectForKey: kTableColumnIDString ]; 260 [ table addTableColumn: column ]; 261 262 // Since addTableColumn adds the column at the end, we have to 263 // readjust the table columns. Wish there were an 264 // addTableColumn: atIndex: method... 265 if ( numColumns > 0 ) 266 { 267 [ table moveColumn: numColumns toColumn: 0 ]; 268 } 269 [ invisibleTableColumns removeObjectForKey: kTableColumnIDString ]; 270 271 } 272 273 } 274 275 // Is the key path which changed "Description"? 276 if ( [ keyPath isEqual: kShowDescriptionKeyPath ] ) 277 { 278 279 // Yes, it changed. What is the value? 280 if ( showDescription == NO ) 281 { 282 283 // "Description" column should not be visible. Remove it from the table column. 284 column = [ table tableColumnWithIdentifier: kTableColumnDescriptionString ]; 285 [ invisibleTableColumns setObject: column forKey: kTableColumnDescriptionString ]; 286 [ table removeTableColumn: column ]; 287 288 } 289 290 else 291 { 292 293 int columnNumber = 0; 294 295 // "Description" column should be visible. Add the table column back into the table. 296 column = [ invisibleTableColumns objectForKey: kTableColumnDescriptionString ]; 297 [ table addTableColumn: column ]; 298 299 // Since addTableColumn adds the column at the end, we have to 300 // readjust the table columns. 301 if ( showTargetID == YES ) 302 { 303 columnNumber++; 304 } 305 306 if ( numColumns != columnNumber ) 307 { 308 [ table moveColumn: numColumns toColumn: columnNumber ]; 309 } 310 311 [ invisibleTableColumns removeObjectForKey: kTableColumnDescriptionString ]; 312 313 } 314 315 } 316 317 // Is the key path which changed "Revision"? 318 if ( [ keyPath isEqual: kShowRevisionKeyPath ] ) 319 { 320 321 // Yes, it changed. What is the value? 322 if ( showRevision == NO ) 323 { 324 325 // "Revision" column should not be visible. Remove it from the table column. 326 column = [ table tableColumnWithIdentifier: kTableColumnRevisionString ]; 327 [ invisibleTableColumns setObject: column forKey: kTableColumnRevisionString ]; 328 [ table removeTableColumn: column ]; 329 330 } 331 332 else 333 { 334 335 int columnNumber = 0; 336 337 // "Revision" column should be visible. Add the table column back into the table. 338 column = [ invisibleTableColumns objectForKey: kTableColumnRevisionString ]; 339 [ table addTableColumn: column ]; 340 341 // Since addTableColumn adds the column at the end, we have to 342 // readjust the table columns. 343 if ( showTargetID == YES ) 344 { 345 columnNumber++; 346 } 347 348 if ( showDescription == YES ) 349 { 350 columnNumber++; 351 } 352 353 if ( numColumns != columnNumber ) 354 { 355 [ table moveColumn: numColumns toColumn: columnNumber ]; 356 } 357 358 [ invisibleTableColumns removeObjectForKey: kTableColumnRevisionString ]; 359 360 } 361 362 } 363 364 // Is the key path which changed "Features"? 365 if ( [ keyPath isEqual: kShowFeaturesKeyPath ] ) 366 { 367 368 // Yes, it changed. What is the value? 369 if ( showFeatures == NO ) 370 { 371 372 // "Features" column should not be visible. Remove it from the table column. 373 column = [ table tableColumnWithIdentifier: kTableColumnFeaturesString ]; 374 [ invisibleTableColumns setObject: column forKey: kTableColumnFeaturesString ]; 375 [ table removeTableColumn: column ]; 376 377 } 378 379 else 380 { 381 382 int columnNumber = 0; 383 384 // "Revision" column should be visible. Add the table column back into the table. 385 column = [ invisibleTableColumns objectForKey: kTableColumnFeaturesString ]; 386 [ table addTableColumn: column ]; 387 388 // Since addTableColumn adds the column at the end, we have to 389 // readjust the table columns. 390 if ( showTargetID == YES ) 391 { 392 columnNumber++; 393 } 394 395 if ( showDescription == YES ) 396 { 397 columnNumber++; 398 } 399 400 if ( showRevision == YES ) 401 { 402 columnNumber++; 403 } 404 405 if ( numColumns != columnNumber ) 406 { 407 [ table moveColumn: numColumns toColumn: columnNumber ]; 408 } 409 410 [ invisibleTableColumns removeObjectForKey: kTableColumnFeaturesString ]; 411 412 } 413 414 } 415 416 // Is the key path which changed "PDT"? 417 if ( [ keyPath isEqual: kShowPDTKeyPath ] ) 418 { 419 420 // Yes, it changed. What is the value? 421 if ( showPDT == NO ) 422 { 423 424 // "PDT" column should not be visible. Remove it from the table column. 425 column = [ table tableColumnWithIdentifier: kTableColumnPDTString ]; 426 [ invisibleTableColumns setObject: column forKey: kTableColumnPDTString ]; 427 [ table removeTableColumn: column ]; 428 429 } 430 431 else 432 { 433 434 // int columnNumber = 0; 435 436 // "PDT" column should be visible. Add the table column back into the table. 437 column = [ invisibleTableColumns objectForKey: kTableColumnPDTString ]; 438 [ table addTableColumn: column ]; 439 440 // Since PDT is always the last column (for now), it will 441 // automatically be added as the last column by addTableColumn: 442 // so we don't need to do any moving around of the column... 443 444 /* 445 if ( showTargetID == YES ) 446 { 447 columnNumber++; 448 } 449 450 if ( showDescription == YES ) 451 { 452 columnNumber++; 453 } 454 455 if ( showRevision == YES ) 456 { 457 columnNumber++; 458 } 459 460 if ( showFeatures == YES ) 461 { 462 columnNumber++; 463 } 464 465 if ( numColumns != columnNumber ) 466 { 467 [ table moveColumn: numColumns toColumn: columnNumber ]; 468 } 469 */ 470 471 [ invisibleTableColumns removeObjectForKey: kTableColumnPDTString ]; 472 473 } 474 475 } 476 477} 478 479 480- ( void ) setInvisibleTableColumns: ( NSMutableDictionary * ) d 481{ 482 483 [ d retain ]; 484 [ invisibleTableColumns release ]; 485 invisibleTableColumns = d; 486 487} 488 489 490- ( void ) setInitiators: ( NSArray * ) i 491{ 492 493 [ i retain ]; 494 [ initiators release ]; 495 initiators = i; 496 497} 498 499 500- ( NSArray * ) initiators { return initiators; } 501 502 503- ( BOOL ) drawerVisible { return drawerVisible; } 504 505 506- ( void ) setDrawerVisible: ( BOOL ) visible 507{ 508 drawerVisible = visible; 509} 510 511 512// Action called to change the drawer state. This is hooked 513// up to the Get Info / Hide Info button in the Toolbar. 514 515- ( IBAction ) toggleDrawer: ( id ) sender 516{ 517 518#pragma unused ( sender ) 519 520 BOOL visible = NO; 521 NSToolbar * toolbar = nil; 522 523 visible = ![ self drawerVisible ]; 524 525 toolbar = [ proberWindow toolbar ]; 526 if ( toolbar != nil ) 527 { 528 529 NSArray * items = nil; 530 531 items = [ toolbar items ]; 532 if ( items != nil ) 533 { 534 535 int count = [ items count ]; 536 int index = 0; 537 NSToolbarItem * item = nil; 538 539 for ( index = 0; index < count; index++ ) 540 { 541 542 item = [ items objectAtIndex: index ]; 543 if ( [ [ item itemIdentifier ] isEqual: SCSIDocInfoIdentifier ] ) 544 { 545 546 NSString * localizedString = nil; 547 548 if ( visible ) 549 { 550 551 localizedString = [ [ NSBundle mainBundle ] localizedStringForKey: kHideInfoToolbarItemString 552 value: @"Hide Info (Not Localized)" 553 table: nil ]; 554 555 } 556 557 else 558 { 559 560 localizedString = [ [ NSBundle mainBundle ] localizedStringForKey: kGetInfoToolbarItemString 561 value: @"Get Info (Not Localized)" 562 table: nil ]; 563 564 } 565 566 // Set the text label to be displayed in the toolbar and customization palette 567 [ item setLabel: localizedString ]; 568 [ item setPaletteLabel: localizedString ]; 569 570 if ( visible ) 571 { 572 573 localizedString = [ [ NSBundle mainBundle ] localizedStringForKey: kHideInfoToolbarItemToolTipString 574 value: @"Hide Info (Not Localized)" 575 table: nil ]; 576 577 } 578 579 else 580 { 581 582 localizedString = [ [ NSBundle mainBundle ] localizedStringForKey: kGetInfoToolbarItemToolTipString 583 value: @"Get Info (Not Localized)" 584 table: nil ]; 585 586 } 587 588 [ item setToolTip: localizedString ]; 589 590 } 591 592 } 593 594 } 595 596 } 597 598 // NB: Must use accessor method to change the drawer's visiblity since 599 // the drawer's visiblity binding is bound to the "visible" ivar for this class. 600 // Bindings require that you use accessors. See the Cocoa Bindings 601 // documentation for more information. 602 [ self setDrawerVisible: visible ]; 603 604} 605 606 607#if 0 608#pragma mark - 609#pragma mark Toolbar Support 610#pragma mark - 611#endif 612 613 614- ( void ) setupToolbar 615{ 616 617 // Create a new toolbar instance, and attach it to our document window 618 NSToolbar * toolbar = [ [ [ NSToolbar alloc ] initWithIdentifier: SCSIDocToolbarIdentifier ] autorelease ]; 619 620 // Set up toolbar properties: Allow customization, give a default display mode, 621 // and remember state in user defaults. 622 [ toolbar setAllowsUserCustomization: YES ]; 623 [ toolbar setAutosavesConfiguration: YES ]; 624 [ toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel ]; 625 626 // We are the delegate. 627 [ toolbar setDelegate: self ]; 628 629 // Attach the toolbar to the document window. 630 [ proberWindow setToolbar: toolbar ]; 631 [ proberWindow makeKeyAndOrderFront: self ]; 632 633} 634 635 636- ( NSToolbarItem * ) toolbar: ( NSToolbar * ) toolbar 637 itemForItemIdentifier: ( NSString * ) itemIdent 638 willBeInsertedIntoToolbar: ( BOOL ) willBeInserted 639{ 640 641#pragma unused ( toolbar ) 642#pragma unused ( willBeInserted ) 643 644 // Required delegate method: Given an item identifier, this method returns an item. 645 // The toolbar will use this method to obtain toolbar items that can be displayed 646 // in the customization sheet, or in the toolbar itself. 647 NSToolbarItem * toolbarItem = [ [ [ NSToolbarItem alloc ] initWithItemIdentifier: itemIdent ] autorelease ]; 648 649 if ( [ itemIdent isEqual: SCSIDocInfoIdentifier ] ) 650 { 651 652 NSString * localizedString = nil; 653 654 localizedString = [ [ NSBundle mainBundle ] localizedStringForKey: kGetInfoToolbarItemString 655 value: @"Get Info (Not Localized)" 656 table: nil ]; 657 658 // Set the text label to be displayed in the toolbar and customization palette. 659 [ toolbarItem setLabel: localizedString ]; 660 [ toolbarItem setPaletteLabel: localizedString ]; 661 662 localizedString = [ [ NSBundle mainBundle ] localizedStringForKey: kGetInfoToolbarItemToolTipString 663 value: @"Get Info (Not Localized)" 664 table: nil ]; 665 666 // Set up a reasonable tooltip and image. 667 [ toolbarItem setToolTip: localizedString ]; 668 [ toolbarItem setImage: [ NSImage imageNamed: kInfoImageString ] ]; 669 670 // Tell the item what message to send when it is clicked. 671 [ toolbarItem setTarget: self ]; 672 [ toolbarItem setAction: @selector ( toggleDrawer: ) ]; 673 674 } 675 676 else if ( [ itemIdent isEqual: SCSIDocPrefsIdentifier ] ) 677 { 678 679 NSString * localizedString = nil; 680 681 localizedString = [ [ NSBundle mainBundle ] localizedStringForKey: kShowPrefsToolbarItemString 682 value: @"Show Preferences (Not Localized)" 683 table: nil ]; 684 685 // Set the text label to be displayed in the toolbar and customization palette. 686 [ toolbarItem setLabel: localizedString ]; 687 [ toolbarItem setPaletteLabel: localizedString ]; 688 689 localizedString = [ [ NSBundle mainBundle ] localizedStringForKey: kShowPrefsToolbarItemToolTipString 690 value: @"Show Preferences (Not Localized)" 691 table: nil ]; 692 693 // Set up a reasonable tooltip and image. 694 [ toolbarItem setToolTip: localizedString ]; 695 [ toolbarItem setImage: [ NSImage imageNamed: kPrefsImageString ] ]; 696 697 // Tell the item what message to send when it is clicked. 698 [ toolbarItem setTarget: [ [ NSApplication sharedApplication ] delegate ] ]; 699 [ toolbarItem setAction: @selector ( showPrefs: ) ]; 700 701 } 702 703 else 704 { 705 706 // itemIdent refered to a toolbar item that is not provided or supported by us or Cocoa. 707 // Returning nil will inform the toolbar this kind of item is not supported. 708 toolbarItem = nil; 709 710 } 711 712 return toolbarItem; 713 714} 715 716 717- ( void ) toolbarWillAddItem: ( NSNotification * ) notif 718{ 719 720 // Optional delegate method: Before an new item is added to the toolbar, this notification is posted. 721 // This is the best place to notice a new item is going into the toolbar. For instance, if you need to 722 // cache a reference to the toolbar item or need to set up some initial state, this is the best place 723 // to do it. The notification object is the toolbar to which the item is being added. The item being 724 // added is found by referencing the @"item" key in the userInfo. 725 726 NSToolbarItem * addedItem = [ [ notif userInfo ] objectForKey: @"item" ]; 727 if ( [ [ addedItem itemIdentifier ] isEqual: NSToolbarPrintItemIdentifier ] ) 728 { 729 730 // Make sure we set ourselves as the target for the "Print" item. 731 // This causes the button to be enabled (rather than disabled), and 732 // to send the -printDocument: action to use when the button is clicked. 733 [ addedItem setTarget: self ]; 734 735 } 736 737} 738 739 740- ( NSArray * ) toolbarDefaultItemIdentifiers: ( NSToolbar * ) toolbar 741{ 742 743#pragma unused ( toolbar ) 744 745 // Required delegate method: Returns the ordered list of items to be shown in the toolbar by default 746 // If during the toolbar's initialization, no overriding values are found in the user defaults, or if the 747 // user chooses to revert to the default items this set will be used. Make sure the array is terminated 748 // with a nil element! 749 return [ NSArray arrayWithObjects: SCSIDocInfoIdentifier, 750 SCSIDocPrefsIdentifier, 751 NSToolbarFlexibleSpaceItemIdentifier, 752 NSToolbarPrintItemIdentifier, 753 NSToolbarCustomizeToolbarItemIdentifier, 754 nil ]; 755 756} 757 758 759- ( NSArray * ) toolbarAllowedItemIdentifiers: ( NSToolbar * ) toolbar 760{ 761 762#pragma unused ( toolbar ) 763 764 // Required delegate method: Returns the list of all allowed items by identifier. By default, the toolbar 765 // does not assume any items are allowed, even the separator. So, every allowed item must be explicitly listed 766 // The set of allowed items is used to construct the customization palette. Make sure the array is terminated 767 // with a nil element! 768 return [ NSArray arrayWithObjects: SCSIDocInfoIdentifier, 769 SCSIDocPrefsIdentifier, 770 NSToolbarPrintItemIdentifier, 771 NSToolbarCustomizeToolbarItemIdentifier, 772 NSToolbarFlexibleSpaceItemIdentifier, 773 NSToolbarSpaceItemIdentifier, 774 NSToolbarSeparatorItemIdentifier, 775 nil ]; 776 777} 778 779 780- ( BOOL ) validateToolbarItem: ( NSToolbarItem * ) toolbarItem 781{ 782 783#pragma unused ( toolbarItem ) 784 785 return YES; 786 787} 788 789 790#if 0 791#pragma mark - 792#pragma mark Printing Support 793#pragma mark - 794#endif 795 796 797// Action called by the "Print" Toolbar button. 798 799- ( IBAction ) printDocument: ( id ) sender 800{ 801 802#pragma unused ( sender ) 803 804 // This message is sent by the print toolbar item. 805 NSPrintOperation * printOperation = nil; 806 807 printOperation = [ NSPrintOperation printOperationWithView: [ proberWindow contentView ] ]; 808 [ printOperation runOperationModalForWindow: proberWindow delegate: nil didRunSelector: NULL contextInfo: NULL ]; 809 810} 811 812 813@end