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

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //    FILENAME:    eTURLinkUI.m
  3. //    SUMMARY:    Implementation for a UI for setting an URLRep
  4. //    SUPERCLASS:    eTURLinkUI:eTImageUI:Object
  5. //    INTERFACE:    eTURLinkUI.nib
  6. //    PROTOCOLS:    <Inspectable>
  7. //    AUTHOR:        Rohit Khare
  8. //    COPYRIGHT:    (c) 1994 California Institure of Technology, eText Project
  9. ///////////////////////////////////////////////////////////////////////////////
  10. //    IMPLEMENTATION COMMENTS
  11. //        String handling for the text object is stolen from eTImage.
  12. //    Funny that, stealing code from your own superclass :)
  13. ///////////////////////////////////////////////////////////////////////////////
  14. //    HISTORY
  15. //    07/24/94:    Added support for dragging OmniWeb squiggles onto linkView.
  16. //  07/22/94:    Minimal Creation.
  17. ///////////////////////////////////////////////////////////////////////////////
  18.  
  19. #import "eTURLink.h"
  20.  
  21. @implementation eTURLinkUI
  22. //  id    theeTURLink;
  23. //  id    urlField;
  24. //  id    urlPanel;
  25. //  id    urlView;
  26.  
  27. + new
  28. {
  29.     static eTURLinkUI *ui = nil;
  30.     
  31.     if (!ui) {
  32.         ui = [[eTURLinkUI alloc] init];
  33.     }
  34.     return ui;
  35. }
  36. - init
  37. {
  38.     char        buf[MAXPATHLEN];
  39.     NXBundle   *bundle;
  40.  
  41.     [super init];
  42.     bundle = [NXBundle bundleForClass:[eTURLinkUI class]];
  43.     if ( [bundle getPath:buf forResource:"eTURLinkUI" ofType:"nib"] ) {
  44.         [NXApp loadNibFile:buf owner:self withNames:NO];
  45.     } else {
  46.         NXLogError("NIB not found: eTURLinkUI");
  47.     }
  48.     urlView = [urlPanel contentView];
  49.     [urlField setDelegate:self];
  50.     [urlField setCharFilter:(NXCharFilterFunc)NXFieldFilter];
  51.     [omniWell initOmniWell];
  52.     return self;
  53. }
  54. - free {return self;}
  55. ///////////////////////////////////
  56. #define PROP "URL Properties"
  57. - (const NXAtom *) types
  58. {
  59.     static NXAtom *types = NULL;
  60.     
  61.     if (!types) {
  62.         int i;
  63.         const NXAtom *superTypes = [super types];
  64.         
  65.         for(i=0;superTypes[i];i++);
  66.         i++; // make room for terminating NULL
  67.         i++; // make room for our type
  68.         types = malloc(i * sizeof(NXAtom));
  69.         types[0] = NXUniqueString(PROP);
  70.         for(i=0;superTypes[i];i++) types[i+1] = superTypes[i];
  71.         types[i+1] = NULL;
  72.     }
  73.     return types;
  74. }
  75. - (const char *) inspectorTitle
  76. {
  77.     return NXUniqueString("eTURLink");
  78. }
  79. - resignInspector: (View *) oldInspector ofType: (const char *) type
  80. {
  81.     if (oldInspector != urlView)
  82.         [super resignInspector:oldInspector ofType:type];
  83.     return self;
  84. }
  85. - activateInspector: (View *) newInspector ofType: (const char *) type
  86. {
  87.     if (newInspector != urlView)
  88.         [super activateInspector:newInspector ofType:type];
  89.     return self;
  90. }
  91. - inspectorForType:(const char *) type
  92. {
  93.     if(!strcmp(type,NXUniqueString(PROP)))
  94.         return urlView;
  95.     return [super inspectorForType:type];
  96. }
  97. ////////////////////
  98. - setAnnotation:sender
  99. {
  100.     [super setAnnotation:sender];    // this is an awkward naming of the "chain" 
  101.     theeTURLink = sender;
  102.     [urlField setText:[theeTURLink URL]];
  103.     return self;
  104. }
  105. - editURL:sender
  106. {
  107.     char        *buf;
  108.     int            length;
  109.  
  110.     length = [urlField textLength]+1;
  111.     buf = malloc(length * sizeof(char));
  112.     [urlField getSubstring:(buf) start:0 length:length];
  113.     (buf)[length]=0;
  114.     [theeTURLink setURL:buf];
  115.     free(buf);
  116.     return self;
  117. }
  118. - textDidEnd:sender endChar:(unsigned short)whyEnd
  119. {    // should this be checked programatically on setAnnotation:?
  120.     if(urlField==sender){ 
  121.         return [self editURL:sender];
  122.     } else {
  123.         return [super textDidEnd:sender endChar:whyEnd];
  124.     }
  125.     return self;
  126. }
  127. @end