home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Apps / ArchiveUtils / Freeze / FreezeControl.m < prev    next >
Encoding:
Text File  |  1992-12-20  |  3.3 KB  |  159 lines

  1. /*
  2.  *    Filename:    FreezeControl.m 
  3.  *    Created :    Sat Dec 21 00:24:10 1991 
  4.  *    Author  :    Vince DeMarco
  5.  *        <vince@whatnxt.cuc.ab.ca>
  6.  */
  7.  
  8.  
  9. /* Generated by Interface Builder */
  10.  
  11. #import <appkit/Application.h>
  12. #import <appkit/OpenPanel.h>
  13. #import <appkit/Panel.h>
  14.  
  15. #import <appkit/Matrix.h>
  16. #import <appkit/Menu.h>
  17. #import <appkit/MenuCell.h>
  18.  
  19. #import <appkit/Pasteboard.h>
  20. #import <appkit/Listener.h>
  21.  
  22. #import <mach.h>
  23. #import <mach_interface.h>
  24.  
  25. #import <strings.h>
  26. #import "FreezeControl.h"
  27. #import "ProcessControl.h"
  28. #import "isdir.h"
  29.  
  30. @implementation FreezeControl
  31.  
  32. - init
  33. {
  34.     self = [super init];
  35.     openPanel = [OpenPanel new];
  36.     [openPanel setTitle:"Process File"];
  37.     [openPanel allowMultipleFiles:YES];
  38.     return self;
  39. }
  40.  
  41. - free
  42. {
  43.     [openPanel free];
  44.     return [super free];
  45. }
  46.  
  47. - processFile:sender
  48. {
  49.     int i=0;
  50.     char pathname[1024];
  51.     const char *directory;
  52.  
  53.     if ([openPanel runModal]){
  54.     while ([openPanel filenames][i]){
  55.         directory = [openPanel directory];
  56.         sprintf(pathname,"%s/%s",directory,[openPanel filenames][i++]);
  57.         if (isdir(pathname)){
  58.         [processControl addDirectory:pathname];
  59.         }else{
  60.         [processControl addFile:pathname];
  61.         }
  62.     }
  63.     }
  64.     return self;
  65. }
  66.  
  67. - appDidInit:sender
  68. {
  69.     /* Set up services stuff */
  70.     [[NXApp appListener] setServicesDelegate:self];
  71.     return self;
  72. }
  73.  
  74. - appWillTerminate:sender
  75. {
  76.     int alert_return = 1;
  77.  
  78.     /* Check if buffer is actually empty before exiting */
  79.     if ([processControl backgroundjobs]) {
  80.     alert_return = NXRunAlertPanel("Quit",
  81.                        "Background processes active, Quit anyways?",
  82.                        "Quit","Cancel",NULL);
  83.     switch (alert_return){
  84.         case NX_ALERTDEFAULT  :
  85.         [processControl killBackground:sender];
  86.         return self;
  87.         case NX_ALERTALTERNATE:
  88.         case NX_ALERTOTHER    :
  89.         case NX_ALERTERROR    : 
  90.         break;
  91.         }
  92.     return nil;  /* Return nil to tell Application Object that it shouldn't quit */
  93.     }else{
  94.     return self; /* Return non-nill if it is okay to quit */
  95.     }
  96. }
  97.  
  98. - (int)appOpenFile:(const char *)path type:(const char *)type
  99. {
  100.     [processControl addFile:(char *)path];    
  101.     return YES;
  102. }
  103.  
  104. - (BOOL)appAcceptsAnotherFile:sender
  105. {
  106.     return YES;
  107. }
  108.  
  109. /* Services stuff */
  110. - processDocument:myPasteboard userData:(const char*)userData error:(char**)message
  111. {
  112.     char         *data  = NULL;
  113.     int           length= 0;
  114.     char         *temp  = NULL;
  115.     char         *temp2 = NULL;
  116.  
  117.     const NXAtom *myTypes;
  118.     
  119.  
  120.     myTypes = [myPasteboard types]; // You need this for some stupid idiotic reason
  121.  
  122.     if ([myPasteboard readType:NXFilenamePboardType data:&data length:&length]){
  123.     if (length && data){
  124.         data[length]= '\000';
  125.         if ((temp = index(data,'\t')) == NULL){  /* Check if multiple files selected */
  126.         if (isdir(data)){
  127.             [processControl addDirectory:data];
  128.         }else{
  129.             [processControl addFile:data];
  130.         }        
  131.         }else{
  132.         temp2 = data;
  133.         while(temp != NULL){
  134.             *temp = '\000';
  135.             temp = temp+1;
  136.             if (isdir(temp2)){
  137.             [processControl addDirectory:temp2];
  138.             }else{
  139.             [processControl addFile:temp2];
  140.             }
  141.             temp2 = temp;
  142.             temp = index(temp2,'\t');
  143.         }
  144.         if (isdir(temp2)){
  145.             [processControl addDirectory:temp2];
  146.         }else{
  147.             [processControl addFile:temp2];
  148.         }
  149.         }
  150.         vm_deallocate(task_self(),(vm_address_t)data,(vm_size_t)length);
  151.     }else{
  152.         *message = "Selection is empty.";
  153.     }
  154.     }
  155.     return(self);
  156. }
  157.  
  158. @end
  159.