home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Misc / RZToDoList / Source / FileImage.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  1.8 KB  |  79 lines

  1. /* 
  2.  * FileImage
  3.  *
  4.  * A GraphicImage subclass that represents a file
  5.  *
  6.  * You may freely copy, distribute and reuse the code in this example.
  7.  * This code is provided AS IS without warranty of any kind, expressed 
  8.  * or implied, as to its fitness for any particular use.
  9.  *
  10.  * Copyright 1995 Ralph Zazula (rzazula@next.com).  All Rights Reserved.
  11.  *
  12.  */
  13.  
  14. #import <libc.h>            // for free()
  15. #import <sys/param.h>            // for MAXPATHLEN
  16. #import <appkit/NXImage.h>
  17. #import <appkit/Speaker.h>
  18. #import <appkit/Listener.h>
  19. #import <appkit/Panel.h>        // for NXRunAlertPanel()
  20. #import <appkit/Application.h>
  21. #import "FileImage.h"
  22.  
  23. @implementation FileImage
  24.  
  25.  
  26. - initForImage:anImage fileName:(const char *)name
  27. {
  28.     [super init];
  29.     
  30.   /* save our graphic image and the file we represent */
  31.     image = anImage;
  32.     fileName = NXCopyStringBuffer(name);
  33.     
  34.     return self;
  35. }
  36.  
  37. - free
  38. {
  39.     free(fileName);
  40.     return [super free];
  41. }
  42.  
  43. - readRichText:(NXStream *)stream forView:view
  44. {
  45.     char    stringBuffer[MAXPATHLEN], *currentPosition, nextChar;
  46.          
  47.   /* get and remember the file name */
  48.     currentPosition = stringBuffer;
  49.     while ((nextChar = NXGetc(stream)) != '\n') {
  50.         *(currentPosition++) = nextChar;
  51.     }
  52.     *currentPosition = '\0';
  53.     fileName = NXCopyStringBuffer(stringBuffer);
  54.  
  55.     image = [[Application workspace] getIconForFile:fileName];
  56.     
  57.     return self;
  58. }
  59.  
  60. - writeRichText:(NXStream *)stream forView:view
  61. {
  62.   /* 
  63.    * for files, we write the file name;  this isn't a robust solution since
  64.    * the file may not be present when the user reopens the RTF file
  65.    */
  66.     NXPrintf(stream, "%s\n", fileName);
  67.     
  68.     return self;
  69. }
  70.  
  71. - performDoubleClickAction
  72. {
  73.     if(![[Application workspace] openFile:fileName])
  74.        NXRunAlertPanel(NULL, "Couldn't open %s", NULL, NULL, NULL, fileName);
  75.     return self;
  76. }
  77.  
  78. @end
  79.