home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / DynamicApp / Controller.m < prev    next >
Text File  |  1993-01-19  |  3KB  |  129 lines

  1. #import <appkit/Window.h>
  2. #import <appkit/TextField.h>
  3. #import <appkit/OpenPanel.h>
  4. #import <appkit/ScrollView.h>
  5. #import <appkit/Text.h>
  6.  
  7. #import <objc/List.h>
  8. #import <objc/objc.h>
  9.  
  10. #import <stdio.h>
  11. #import <string.h>
  12. #import <stdlib.h>
  13.  
  14. #import "DynamicApplication.h"
  15. #import "Controller.h"
  16. #import "MatrixScrollView.h"
  17.  
  18. @implementation Controller
  19.  
  20. BOOL getFullFileName( fullpath )
  21. char *fullpath;
  22. {
  23.     const char         *types[2] = { "o", NULL };
  24.     const char *const     *filename;
  25.     id            openReq;
  26.     
  27.     openReq = [OpenPanel new];
  28.     if([openReq runModalForTypes:types] && (filename = [openReq filenames]))
  29.     {
  30.         strcpy( fullpath, [openReq directory] );
  31.     strcat( fullpath, "/" );
  32.     strcat( fullpath, filename[0] );
  33.     
  34.         return YES;
  35.     }
  36.     else
  37.         return NO;
  38. }
  39.  
  40. - appDidInit:sender
  41. {    
  42.     [classesNumberField setIntValue:[NXApp classesNum]];
  43.     [loadedClasses setTarget:self action:@selector(classClick:)];  
  44.     return self;
  45. }
  46.  
  47. - loadAClass:sender
  48. {
  49.     char temp[1024];
  50.  
  51.     if( getFullFileName( &temp ) )
  52.     {
  53.         [NXApp loadClass:temp];
  54.     
  55.     if( [NXApp classLoaded] )
  56.     {
  57.         [loadedClasses insertName:[NXApp lastClassName] alphaOrder:NO select:NO];
  58.         [classesNumberField setIntValue:[NXApp classesNum]];
  59.         if([NXApp classesNum] == 1 )
  60.         [self classClick:self];
  61.     }
  62.     }
  63.     
  64.     return self;
  65. }
  66.  
  67. - classClick:sender
  68. {
  69.     id    tempObject;
  70.     
  71.     tempObject = [[NXApp classWithName:[loadedClasses selectedName]] alloc];
  72.     [self methodListForObject:tempObject];
  73.     [tempObject free];
  74.     
  75.     return self;
  76. }
  77.  
  78. - (int)printf:(id)scrollView string:(const char *)format, ...
  79. {
  80.     int result, length = [[scrollView docView] textLength];
  81.     char buffer[1024];
  82.     va_list ap;
  83.     
  84.     va_start( ap, format );
  85.     result = vsprintf( buffer, format, ap );
  86.     va_end( ap );
  87.     
  88.     [[[scrollView docView] setSel:length :length] replaceSel:buffer];
  89.     
  90.     return result;
  91. }
  92.  
  93. - methodListForObject:(Controller *)anObject
  94. {
  95.     struct objc_class         *c;
  96.     struct objc_method_list     *m;
  97.     struct objc_ivar_list    *v;
  98.     char            *n;
  99.     int                i;
  100.     
  101.     c = anObject->isa;
  102.     v = c->ivars;
  103.     m = c->methods;
  104.     
  105.     [[instanceVars docView] setText:""];
  106.     [[instanceMethods docView] setText:""];
  107.     [[instanceVars window] disableFlushWindow];
  108.  
  109.     if( v )
  110.         for( i = v->ivar_count-1 ; i >= 0 ; i-- )
  111.         [self printf:instanceVars string:"%s\n", v->ivar_list[i].ivar_name];
  112.  
  113.     if( m )
  114.         for( i = m->method_count-1 ; i >= 0 ; i-- )
  115.         {
  116.             n = sel_getName( m->method_list[i].method_name );
  117.         [self printf:instanceMethods string:"- %s\n", n];
  118.         }
  119.  
  120.     [[instanceVars window] reenableFlushWindow];
  121.     [[instanceVars window] flushWindow];
  122.     [instanceVars display];
  123.     [instanceMethods display];
  124.     
  125.     return self;
  126. }
  127.  
  128. @end
  129.