home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.bin / SourceCode / Palettes / TTools / TToolsPalette / SwitchView.subproj / SwitchViewConnectInspector.m < prev    next >
Encoding:
Text File  |  1993-11-09  |  3.6 KB  |  151 lines

  1. /* SwitchViewConnectInspector.m
  2.  * Written By:  Thomas Burkholder
  3.  *
  4.  * You may freely copy, distribute, and reuse the code in this example.
  5.  * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  6.  * fitness for any particular use.
  7.  */
  8.  
  9.  
  10. #import "SwitchViewConnectInspector.h"
  11. #import "SVConnector.h"
  12. #import "../Utilities.subproj/SortedList.h"
  13. #import "../Utilities.subproj/ConnectorAgent.h"
  14.  
  15. static BOOL selecting;
  16.  
  17. @implementation SwitchView (ConnectionsInspector)
  18.  
  19. -(const char *)getConnectInspectorClassName
  20. {
  21.     NXEvent *ev = [NXApp currentEvent];
  22.  
  23.     // NOTE:  This doesn't work on PC's and most NextStations, due
  24.     // to the fact that control-alt is mapped to be a Help key!!!
  25.     // expect this to go away later with the more complete version of
  26.     // superclass-inspector access.
  27.     if (ev->flags & NX_ALTERNATEMASK)
  28.         return [super getConnectInspectorClassName];
  29.     else
  30.         return "SwitchViewConnectInspector";
  31. }
  32.  
  33. @end
  34.  
  35. @implementation SwitchViewConnectInspector
  36.  
  37. - init
  38. {
  39.     char buf[MAXPATHLEN + 1];
  40.     id bundle;
  41.     
  42.     [super init];
  43.     
  44.     bundle = [NXBundle bundleForClass:[SwitchView class]];
  45.     [bundle getPath:buf forResource:"SwitchViewConnectInspector" ofType:"nib"];
  46.     [NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];
  47.     [connectorList setAgent:[[ConnectorAgent alloc] init]];
  48.     [browser setEmptySelectionEnabled:YES];
  49.     [browser loadColumnZero];
  50.     
  51.     selecting = NO;
  52.     
  53.     return self;
  54. }
  55.  
  56. - free
  57. {
  58.     // should also be freeing the window, views.
  59.     [[connectorList agent] free];
  60.     [connectorList free];
  61.     return [self free];
  62. }
  63.  
  64. - selectConnection:sender
  65. {
  66.     id conn = [connectorList objectAt:[[sender matrixInColumn:0] selectedRow]];
  67.  
  68.     if (!conn) return self;
  69.  
  70.     selecting = YES;
  71.     // draw the connection
  72.     [NXApp displayConnectionBetween:[conn source] and:[conn destination]];
  73.     [connectButton setTitle:"Disconnect"];
  74.     [connectButton setTag:1];
  75.     [connectButton setEnabled:YES];
  76.     return self;
  77. }
  78.  
  79. - ok:sender
  80. {
  81.     int i;
  82.     id aConnector, b;
  83.  
  84.     if ([sender tag] == 0) {
  85.         aConnector = [[SVConnector alloc] init];
  86.         [aConnector setDestination:[NXApp connectDestination]];
  87.         [aConnector setSource:object];
  88.         [[NXApp activeDocument] addConnector:aConnector];
  89.         [connectorList addObject:aConnector];
  90.         [browser loadColumnZero];
  91.         b = [browser matrixInColumn:0];
  92.         [b selectCellAt:[b cellCount]-1 :0];
  93.         [connectButton setTitle:"Disconnect"];
  94.         [connectButton setTag:1];
  95.     } else if ([sender tag] ==1) {
  96.         i = [[browser matrixInColumn:0] selectedRow];
  97.         aConnector = [connectorList removeObjectAt:i];
  98.         
  99.         [[NXApp activeDocument] removeConnector:aConnector];
  100.         [aConnector free];
  101.         [browser loadColumnZero];
  102.         [[browser matrixInColumn:0] selectCellAt:-1 :-1];
  103.         [connectButton setTitle:"Connect"];
  104.         [connectButton setTag:0];
  105.     }
  106.     return [super ok:sender];
  107. }
  108.  
  109. - revert:sender
  110. {
  111.     int s;
  112.  
  113.     if (selecting) {
  114.         selecting = NO;
  115.         return self;
  116.     }
  117.  
  118.     [connectorList empty];
  119.     [[NXApp activeDocument] listConnectors:connectorList forSource:object];
  120.     [browser loadColumnZero];
  121.  
  122.     if ([NXApp isConnecting]) {
  123.         s = [connectorList indexOf:[NXApp connectDestination]];
  124.         if (s == NX_NOT_IN_LIST) {
  125.             [[browser matrixInColumn:0] selectCellAt:-1 :-1];
  126.             [connectButton setTitle:"Connect"];
  127.             [connectButton setTag:0];
  128.             [connectButton setEnabled:YES];
  129.         } else {
  130.             [[browser matrixInColumn:0] selectCellAt:s :0];
  131.             [connectButton setTitle:"Disconnect"];
  132.             [connectButton setTag:1];
  133.             [connectButton setEnabled:YES];
  134.         }
  135.     } else {
  136.         [[browser matrixInColumn:0] selectCellAt:-1 :-1];
  137.         [connectButton setTitle:"No Selection"];
  138.         [connectButton setEnabled:NO];
  139.         [connectButton setTag:2];
  140.     }
  141.  
  142.     return [super revert:sender];
  143. }
  144.  
  145. - (BOOL)wantsButtons
  146. {
  147.     return NO;
  148. }
  149.  
  150. @end
  151.