home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2 / Openstep-4.2-Intel-Developer.iso / NextLibrary / Frameworks / AppKit.framework / Versions / B / Headers / NSFileWrapper.h < prev    next >
Text File  |  1996-10-17  |  8KB  |  108 lines

  1. /*
  2.         NSFileWrapper.h
  3.         Application Kit
  4.         Copyright (c) 1995-1996, NeXT Software, Inc.
  5.         All rights reserved.
  6. */
  7.  
  8. #import <Foundation/Foundation.h>
  9.  
  10. @class NSImage;
  11.  
  12. @interface NSFileWrapper : NSObject <NSCoding> {
  13.   @private
  14.     id _impl;
  15.     NSString *_fileName;
  16.     NSString *_preferredFileName;
  17.     NSDictionary *_fileAttributes;
  18.     NSImage *_image;
  19.     id _subdocuments;
  20. }
  21.  
  22. ////////////////////////////// Initialization //////////////////////////////
  23.  
  24. - (id)initDirectoryWithFileWrappers:(NSDictionary *)docs;
  25.     // Designated initializer. Inits new directory type instances.
  26.  
  27. - (id)initRegularFileWithContents:(NSData *)data;
  28.     // Designated initializer. Inits new regular file type instances.
  29.  
  30. - (id)initSymbolicLinkWithDestination:(NSString *)path;
  31.     // Designated initializer. Inits new symbolic link type instances.
  32.  
  33. - (id)initWithPath:(NSString *)path;
  34.     // Designated initializer. Inits the instance from the file, directory, or symbolic link at path.  This can end up creating a whole tree of instances with a directory type instance at the root.
  35.  
  36. - (id)initWithSerializedRepresentation:(NSData *)data;
  37.     // Designated initializer. Inits the instance from the data which is in the standard serialization format.  This standard format is the same format as the data returned by NSText's RTFDFromRange: method.  It is also the same format used for the NSFileContentsPasteboardType.  This can end up creating a whole tree of instances with a directory type instance at the root.
  38.  
  39. ////////////////////// General methods for all instance types //////////////////////
  40.  
  41. - (BOOL)writeToFile:(NSString *)path atomically:(BOOL)atomicFlag updateFilenames:(BOOL)updateFilenamesFlag;
  42.     // Writes the instance to disk at the path specified.  For a directory type instance these methods will recursively descend child fileWrappers.  If updateFilenamesFlag is YES then the filename of the wrapper (and all sub-wrappers for directory-type instances) will be updated with the file names used to write that wrapper(s).  Usually, "Save" and "Save As" operations would pass YES for this flag, while "Save To" operations would pass NO.
  43.  
  44. - (NSData *)serializedRepresentation;
  45.     // Returns an NSData containing a serialized representation of the instance in the standard format.  For a directory type instance these methods will recursively descend child fileWrappers.
  46.  
  47. - (void)setFilename:(NSString *)filename;
  48. - (NSString *)filename;
  49.     // The filename is best thought of as the last known actual file name of the wrapper.  Usually it will be the same as the preferredFilename, but may be different.  It is just a filename, not a full path.  Its extension indicates its type.  The filename is automatically set for instances initialized from the file system (via initWithPath:).  It is updated whenever updateFromPath: is sent.  It is also updated when writeToFile:atomically:updateFilenames: is called, but only if the last argument is YES. 
  50.  
  51. - (void)setPreferredFilename:(NSString *)filename;
  52. - (NSString *)preferredFilename;
  53.     // The preferredFilename is usually the original name.  It is just a filename, not a full path.  Its extension indicates its type.  Usually this will be the name used to save the document when it is a subdocument in some other directory type NSFileWrapper, but it might not be if there is more than one subdocument with the same preferred name.
  54.  
  55. - (void)setFileAttributes:(NSDictionary *)attributes;
  56. - (NSDictionary *)fileAttributes;
  57.     // The file attributes are initialized with the actual file's attributes when it is initialized from disk.  If the instance is initialized through the serialized data format the attributes are deserialized along with everything else.  When an instance is initialized from one of the designated initializers it initially has suitable default attributes for its type.  Some file attributes will be serialized as part of the serialized represenation and some will be set on the resulting file when the instance is written to the file system.  After saving to the file system, the attributes will be updated from the actual values on the disk (which might be different).  You should not attempt to change the file type through the setFileAttributes: method.
  58.  
  59. - (BOOL)isRegularFile;
  60. - (BOOL)isDirectory;
  61. - (BOOL)isSymbolicLink;
  62.     // Just covers on [[self fileAttributes] fileType].
  63.  
  64. - (void)setIcon:(NSImage *)icon;
  65. - (NSImage *)icon;
  66.     // This is the image that should be used to represent this file to the user if an image cannot be found by better means (ie by checking for a file or file type image with NSWorkspace).
  67.  
  68. - (BOOL)needsToBeUpdatedFromPath:(NSString *)path;
  69. - (BOOL)updateFromPath:(NSString *)path;
  70.     // These methods provide a way to keep the instance in sync with changes that might occur in the file system behind the instance's back.  For a directory type instance these methods will recursively descend child fileWrappers.  The contents, file attributes, and image are all updated as needed.  There is a convenience method in the text system that allows an even easier way to update text attachments from disk that makes use of these methods.  The path is a full path to the file to update from.  The update "needs" to be done for regular files if the mod time or mode of the file has changed.  For symlinks it "needs" to be done only if the link destination is now different.  For directories the file attributes and icon are always updated and then the children are updated.  Deleted children and new children are noticed and the directory's child fileWrappers are updated accordingly.
  71.  
  72. ///////////////////////// Directory type instance methods /////////////////////////
  73.  
  74. // The following methods work only for directory type instances.  For other types they raise.
  75.  
  76. - (NSString *)addFileWrapper:(NSFileWrapper *)doc;
  77.     // Adds a new subdocument.  If a subdocument already exists with this document's preferredFileName then this document's preferredFileName is uniqued to determine the key assigned to this document.  The key (whether modified from the preferredFileName or not) is returned.  The key used is always based on the preferredFileName (usually it is identical to it) so after a document is made a subdocument its preferredFileName should not be changed.
  78.  
  79. - (void)removeFileWrapper:(NSFileWrapper *)doc;
  80.     // Removes the given subdocument.
  81.  
  82. - (NSDictionary *)fileWrappers;
  83.     // Returns a dictionary with (possibly uniqued) preferredFileNames as keys and NSFileWrapper instances as values.
  84.  
  85. - (NSString *)keyForFileWrapper:(NSFileWrapper *)doc;
  86.     // Returns the key in the receiver's fileWrappers dictionary whose value is doc or nil if doc is not a subdocument of the receiver.
  87.  
  88. - (NSString *)addFileWithPath:(NSString *)path;
  89. - (NSString *)addRegularFileWithContents:(NSData *)data preferredFilename:(NSString *)filename;
  90. - (NSString *)addSymbolicLinkWithDestination:(NSString *)path preferredFilename:(NSString *)filename;
  91.     // Convenience methods which create new instnaces and add them as child fileWrappers of the receiver.
  92.  
  93. ///////////////////////// Regular file type instance methods /////////////////////////
  94.  
  95. // The following methods work only for regular file type instances.  For other types they raise.
  96.  
  97. - (NSData *)regularFileContents;
  98.     // Returns an NSData with the contents of the file.
  99.  
  100. //////////////////////// Symbolic link type instance methods ////////////////////////
  101.  
  102. // The following methods work only for symbolic link type instances.  For other types they raise.
  103.  
  104. - (NSString *)symbolicLinkDestination;
  105.     // Returns the path of the destination of the symbolic link.
  106.  
  107. @end
  108.