home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / MiscKit / Source / MiscTree.Browser.m < prev    next >
Encoding:
Text File  |  1994-03-27  |  2.6 KB  |  130 lines

  1. //
  2. // MiscTree.Browser.m -- Category of MiscTree that allows a MiscTree to be
  3. //         a delegate for an NXBrowser
  4. //        Written by Scott Anguish (c) 1994 by Scott Anguish.
  5. //                Version 1.0.  All rights reserved.
  6. //
  7. //        This notice may not be removed from this source code.
  8. //
  9. //    This program is included in the MiscKit by permission from the author
  10. //    and its use is governed by the MiscKit license, found in the file
  11. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  12. //    for a list of all applicable permissions and restrictions.
  13. //    
  14.  
  15. #import <misckit/misckit.h>
  16.  
  17. @implementation MiscTree(Browser)
  18.  
  19. - returnSelectedNode:theBrowser
  20.     {
  21.     
  22.         id    pathString;
  23.         id    theNode;
  24.         
  25.         
  26.         pathString=[self returnSelectedPath:theBrowser];
  27.         theNode=[self pathToChild:pathString];
  28.         [pathString free];
  29.         return theNode;
  30.     
  31.     }
  32.  
  33. - returnSelectedPath:theBrowser
  34.     {
  35.     
  36.         id    pathString;
  37.         char path[MAXPATHLEN+1];
  38.         const char *nodeName;
  39.         
  40.         
  41.         nodeName = [[[theBrowser matrixInColumn:[theBrowser lastColumn]] selectedCell] stringValue];
  42.         [theBrowser getPath:path toColumn:[theBrowser lastColumn]];
  43.         
  44.         pathString=[[MiscString alloc] initString:path];
  45.         if (nodeName)
  46.             {
  47.                 [pathString cat:"/"];
  48.                 [pathString cat:nodeName];
  49.             }
  50.         
  51.         return pathString;
  52.     
  53.     }
  54.  
  55.  
  56. - pathToChild:theString
  57.     {
  58.         return [self pathToChild:theString level:1];
  59.     }
  60.  
  61. - labelString 
  62.     { 
  63.         return label; 
  64.     }
  65.  
  66.     
  67. - pathToChild:theString level:(int)theLevel
  68.     {
  69.         id    pathPart;
  70.         id    leaf;
  71.         int    partCount;
  72.         int    i;
  73.             
  74.         pathPart=[theString extractPart:theLevel useAsDelimiter:'/'];
  75.         partCount=[theString numOfChar:'/'];
  76.         
  77.         for (i=0; i < [branches count]; i++)
  78.             {
  79.                 leaf=[branches objectAt:i];
  80.                 if ([pathPart compareTo:[leaf labelString]]==0)
  81.                     { // we found the string we are looking for
  82.                     if (theLevel==partCount) 
  83.                         {
  84.                             return leaf;
  85.                         }
  86.                         else
  87.                         {
  88.                             return ([leaf pathToChild:theString level:(theLevel+1)]);
  89.                         }
  90.                     }
  91.             }
  92.         return nil;
  93.     
  94.     
  95.     }
  96.  
  97.  
  98. - (int)browser:sender fillMatrix:matrix inColumn:(int)column
  99.     {
  100.         char    thePath[MAXPATHLEN+1];
  101.         id    pathString;
  102.         id    theNode,theLeaf;
  103.         int    count,i;
  104.         
  105.         if (column==0)
  106.             {
  107.                 theNode=self;
  108.             }
  109.                 else
  110.             {
  111.                 [sender getPath:thePath toColumn:column];
  112.                 pathString=[[MiscString alloc] initString:thePath];
  113.                 theNode=[self pathToChild:pathString];
  114.             }
  115.     
  116.         count=[[theNode branches] count];
  117.         [matrix renewRows:count+1 cols:1];
  118.     
  119.         for (i=0; i < count; i++)
  120.             {
  121.                 theLeaf=[[theNode branches] objectAt:i];
  122.                 [[matrix cellAt:i :0] setStringValue:[theLeaf label]];
  123.                 [[matrix cellAt:i :0] setLoaded:YES];
  124.                 [[matrix cellAt:i :0] setLeaf:([[theLeaf branches] count]==0)];
  125.             }
  126.         return count;
  127.     }
  128.  
  129. @end
  130.