home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / eText5 / Source / eTFileLink.subproj / eTFileLinkUI.m < prev    next >
Encoding:
Text File  |  1994-10-24  |  4.1 KB  |  155 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //    FILENAME:    eTFileLinkUI.m 
  3. //    SUMMARY:    Implementation of the FileLink UI
  4. //    SUPERCLASS:    Object
  5. //    INTERFACE:    None
  6. //    PROTOCOLS:    <Inspectable>
  7. //    AUTHOR:        Rohit Khare
  8. //    COPYRIGHT:    (c) 1994 California Institure of Technology, eText Project
  9. ///////////////////////////////////////////////////////////////////////////////
  10. //    IMPLEMENTATION COMMENTS
  11. //        Read-only display of the filename and the link state.
  12. //    Normally disabled exec string field (not editable, grayed-out, stringValue=
  13. //    "open \"%s\""). When execSwitch fires, we setExec string, make the string
  14. //    editable (and first responder). If execSwitch goes off, we run an alert
  15. //    iff stringValue != default.
  16. ///////////////////////////////////////////////////////////////////////////////
  17. //    HISTORY
  18. //    08/06/94:    Added symbolic linking support.
  19. //  07/03/94:    Created. Mimics RTFD file inclusions.
  20. ///////////////////////////////////////////////////////////////////////////////
  21.  
  22. #import "eTFileLink.h"
  23. #define _defaultExecString "open \"%s\""
  24.  
  25. @implementation eTFileLinkUI
  26. //    id    execField;
  27. //    id    execSwitch;
  28. //    id    filenameField;
  29. //    id    filenameSwitch;
  30. //    id    linkPanel;
  31. //    id    linkView;
  32. //      id    theLink;
  33. //      id    symlinkSwitch;
  34.  
  35. - setAnnotation:newLink
  36. {    
  37.     if (newLink == theLink) return self;
  38.     [super setAnnotation:newLink];    // this is an awkward naming of the "chain" 
  39.     theLink = newLink;
  40.     [filenameField setStringValue:[theLink componentName]];
  41.     [filenameSwitch setState:[theLink isLinked]];
  42.     [symlinkSwitch setEnabled:[theLink isLinked]];
  43.     [symlinkSwitch setState:[theLink useSymlink]];
  44.     if ([theLink isExecEnabled]) {
  45.         // reset to reflect theLink's state
  46.         [execSwitch setState:1];
  47.         [execField setStringValue:[theLink execString]];
  48.         [execField setEditable:YES];
  49.         [execField setBackgroundGray:NX_WHITE];
  50.     } else {    // NULL exec string
  51.         // reset to baseline
  52.         [execSwitch setState:0];
  53.         [execField setStringValue:_defaultExecString];
  54.         [execField setEditable:NO];
  55.         [execField setBackgroundGray:NX_LTGRAY];
  56.     }
  57.     return self;
  58. }
  59. - enableExec:sender
  60. {
  61.     if ([sender state]) {    // up-transition
  62.         // enable the field; prepare theLink
  63.         [execField setEditable:YES];
  64.         [execField setBackgroundGray:NX_WHITE];
  65.         [theLink setExecString:_defaultExecString];
  66.     } else {                // down-transition
  67.         [theLink setExecEnabled:NO];
  68.         [execField setEditable:NO];
  69.         [execField setBackgroundGray:NX_LTGRAY];        
  70.     }
  71.     return self;
  72. }
  73. - setExec:sender
  74. {
  75.     [theLink setExecString:[sender stringValue]];
  76.     [[theLink etDoc] touch];
  77.     return self;
  78. }
  79. - forceSymlink:sender
  80. {
  81.     [theLink setSymlink:[sender state]];
  82.     [[theLink etDoc] touch];
  83.     return self;
  84. }
  85. ///////////////////////////////////
  86. + new
  87. {
  88.     static eTFileLinkUI *ui = nil;
  89.     
  90.     if (!ui) {
  91.         ui = [[eTFileLinkUI alloc] init];
  92.     }
  93.     return ui;
  94. }
  95. - init
  96. {
  97.     char        buf[MAXPATHLEN];
  98.     NXBundle   *bundle;
  99.  
  100.     [super init];
  101.     bundle = [NXBundle bundleForClass:[self class]];
  102.     if ( [bundle getPath:buf forResource:"eTFileLinkUI" ofType:"nib"] ) {
  103.         [NXApp loadNibFile:buf owner:self withNames:NO];
  104.     } else {
  105.         NXLogError("NIB not found: eTFileLinkUI");
  106.     }
  107.     linkView = [linkPanel contentView];
  108.     return self;
  109. }
  110. - free {return self;}
  111. ///////////////////////////////////
  112. #define PROP "File Properties"
  113.  
  114. - (const NXAtom *) types
  115. {
  116.     static NXAtom *types = NULL;
  117.     
  118.     if (!types) {
  119.         int i;
  120.         const NXAtom *superTypes = [super types];
  121.         
  122.         for(i=0;superTypes[i];i++);
  123.         i++; // make room for terminating NULL
  124.         i++; // make room for our type
  125.         types = malloc(i * sizeof(NXAtom));
  126.         types[0] = NXUniqueString(PROP);
  127.         for(i=0;superTypes[i];i++) types[i+1] = superTypes[i];
  128.         types[i+1] = NULL;
  129.     }
  130.     return types;
  131. }
  132. - (const char *) inspectorTitle
  133. {
  134.     return NXUniqueString("File");
  135. }
  136. - resignInspector: (View *) oldInspector ofType: (const char *) type
  137. {
  138.     if (oldInspector != linkView)
  139.         [super resignInspector:oldInspector ofType:type];
  140.     return self;
  141. }
  142. - activateInspector: (View *) newInspector ofType: (const char *) type
  143. {
  144.     if (newInspector != linkView)
  145.         [super activateInspector:newInspector ofType:type];
  146.     return self;
  147. }
  148. - inspectorForType:(const char *) type
  149. {
  150.     if(!strcmp(type,NXUniqueString(PROP)))
  151.         return linkView;
  152.     return [super inspectorForType:type];
  153. }
  154. @end
  155.