home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Examples / TreeView / SavePanelWithPopUp.subproj / SavePanelWithPopUp.m < prev   
Encoding:
Text File  |  1996-02-08  |  2.2 KB  |  100 lines

  1. //        Written by Aleksey Sudakov <zander@cnext.crec.mipt.ru>
  2. //          Copyright (c) 1995 by Aleksey Sudakov.
  3. //                Version 1.0.  All rights reserved.
  4. //
  5. //        This notice may not be removed from this source code.
  6. //
  7. //    This program is included in the MiscKit by permission from the author
  8. //    and its use is governed by the MiscKit license, found in the file
  9. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  10. //    for a list of all applicable permissions and restrictions.
  11. //    
  12.  
  13. #import <objc/List.h>
  14. #import <misckit/MiscString.h>
  15. #import "SavePanelWithPopUp.h"
  16.  
  17. @interface SavePanelWithPopUp(Private)
  18. + _factory;
  19.  
  20. - _init;
  21. - changeTypes;
  22. @end
  23.  
  24. @implementation SavePanelWithPopUp
  25. + _factory
  26. {
  27.     return [SavePanelWithPopUp class];
  28. }
  29.  
  30. + newContent:(const NXRect *)contentRect style:(int)aStyle
  31.     backing:(int)bufferingType buttonMask:(int)mask defer:(BOOL)flag
  32. {
  33.     SavePanelWithPopUp* panel;
  34.  
  35.     panel = [SavePanel newContent:contentRect style:aStyle
  36.             backing:bufferingType buttonMask:mask defer:flag];
  37.     return [panel _init];
  38. }
  39.  
  40. - _init
  41. {    
  42.     types = [[List alloc] init];
  43.     popUp = [[PopUpList alloc] init];
  44.     [popUp setTarget:self];
  45.     [popUp setAction:sel_getUid("changeTypes")];
  46.  
  47.     return self;
  48. }
  49.  
  50. - changeTypes
  51. {
  52.     [self setSelectedType:[[types objectAt:[[popUp itemList] selectedRow]] stringValue]];
  53.     [self setRequiredFileType:selectedType];
  54.     return self;
  55. }
  56.  
  57. - registerPopUp
  58. {
  59.     [super setAccessoryView:NXCreatePopUpListButton(popUp)];
  60.     return self;
  61. }
  62.  
  63. - addType:(char*)type withDescription:(char*)description
  64. {
  65.     MiscString* msType = [MiscString newWithString:type];
  66.     MiscString* msTitle = [[MiscString alloc] initFromFormat:
  67.                                 "%s - %s",type, description];
  68.  
  69.     [popUp addItem:[msTitle stringValue]];
  70.     [types addObject:msType];
  71.     if(!selectedType){
  72.         [self setSelectedType:[[types objectAt:0] stringValue]];
  73.         [self setRequiredFileType: selectedType];
  74.         }
  75.     return self;
  76. }
  77.  
  78. - (char*)selectedType
  79. {
  80.     return selectedType;
  81. }
  82.  
  83. - setSelectedType:(const char *)aString
  84. {
  85.     if (selectedType) free(selectedType);
  86.     selectedType = NXCopyStringBufferFromZone(aString, [self zone]);
  87.     return self;
  88. }
  89.  
  90. - free
  91. {
  92.     free(selectedType);
  93.     [types freeObjects];
  94.     [types free];
  95.     [popUp free];
  96.     return [super free];
  97. }
  98.  
  99.  
  100. @end