mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 20:31:56 +00:00
Add some OSX 10.6 methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@37247 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6ba92fb344
commit
e00ae378c2
3 changed files with 174 additions and 16 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2013-10-17 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Headers/AppKit/NSFileWrapper.h,
|
||||||
|
* Source/NSFileWrapper.m: Add some OSX 10.6 methods.
|
||||||
|
|
||||||
2013-10-15 Eric Wasylishen <ewasylishen@gmail.com>
|
2013-10-15 Eric Wasylishen <ewasylishen@gmail.com>
|
||||||
|
|
||||||
* Source/GSThemeDrawing.m:
|
* Source/GSThemeDrawing.m:
|
||||||
|
|
|
@ -32,12 +32,13 @@
|
||||||
#import <GNUstepBase/GSVersionMacros.h>
|
#import <GNUstepBase/GSVersionMacros.h>
|
||||||
|
|
||||||
#import <Foundation/NSObject.h>
|
#import <Foundation/NSObject.h>
|
||||||
#import <AppKit/NSImage.h>
|
|
||||||
|
|
||||||
@class NSData;
|
@class NSData;
|
||||||
@class NSDictionary;
|
@class NSDictionary;
|
||||||
|
@class NSError;
|
||||||
@class NSMutableDictionary;
|
@class NSMutableDictionary;
|
||||||
@class NSString;
|
@class NSString;
|
||||||
|
@class NSURL;
|
||||||
@class NSImage;
|
@class NSImage;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
|
@ -46,7 +47,21 @@ typedef enum
|
||||||
GSFileWrapperRegularFileType,
|
GSFileWrapperRegularFileType,
|
||||||
GSFileWrapperSymbolicLinkType
|
GSFileWrapperSymbolicLinkType
|
||||||
} GSFileWrapperType;
|
} GSFileWrapperType;
|
||||||
|
|
||||||
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
|
||||||
|
enum {
|
||||||
|
NSFileWrapperReadingImmediate = 1,
|
||||||
|
NSFileWrapperReadingWithoutMapping = 2,
|
||||||
|
};
|
||||||
|
typedef NSUInteger NSFileWrapperReadingOptions;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
NSFileWrapperWritingAtomic = 1,
|
||||||
|
NSFileWrapperWritingWithNameUpdating = 2,
|
||||||
|
};
|
||||||
|
typedef NSUInteger NSFileWrapperWritingOptions;
|
||||||
|
#endif
|
||||||
|
|
||||||
@interface NSFileWrapper : NSObject
|
@interface NSFileWrapper : NSObject
|
||||||
{
|
{
|
||||||
NSString *_filename;
|
NSString *_filename;
|
||||||
|
@ -138,6 +153,22 @@ typedef enum
|
||||||
|
|
||||||
- (NSString *)symbolicLinkDestination;
|
- (NSString *)symbolicLinkDestination;
|
||||||
|
|
||||||
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
|
||||||
|
- (id)initSymbolicLinkWithDestinationURL:(NSURL *)url;
|
||||||
|
- (id)initWithURL:(NSURL *)url
|
||||||
|
options:(NSFileWrapperReadingOptions)options
|
||||||
|
error:(NSError **)outError;
|
||||||
|
- (BOOL)matchesContentsOfURL:(NSURL *)url;
|
||||||
|
- (BOOL)readFromURL:(NSURL *)url
|
||||||
|
options:(NSFileWrapperReadingOptions)options
|
||||||
|
error:(NSError **)outError;
|
||||||
|
- (NSURL *)symbolicLinkDestinationURL;
|
||||||
|
- (BOOL)writeToURL:(NSURL *)url
|
||||||
|
options:(NSFileWrapperWritingOptions)options
|
||||||
|
originalContentsURL:(NSURL *)originalContentsURL
|
||||||
|
error:(NSError **)outError;
|
||||||
|
#endif
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif // _GNUstep_H_NSFileWrapper
|
#endif // _GNUstep_H_NSFileWrapper
|
||||||
|
|
|
@ -37,9 +37,11 @@
|
||||||
#import <Foundation/NSDebug.h>
|
#import <Foundation/NSDebug.h>
|
||||||
#import <Foundation/NSException.h>
|
#import <Foundation/NSException.h>
|
||||||
#import <Foundation/NSFileManager.h>
|
#import <Foundation/NSFileManager.h>
|
||||||
|
#import <Foundation/NSURL.h>
|
||||||
#import <Foundation/NSValue.h>
|
#import <Foundation/NSValue.h>
|
||||||
#import "AppKit/NSFileWrapper.h"
|
#import "AppKit/NSFileWrapper.h"
|
||||||
#import "AppKit/NSFont.h"
|
#import "AppKit/NSFont.h"
|
||||||
|
#import "AppKit/NSImage.h"
|
||||||
#import "AppKit/NSWorkspace.h"
|
#import "AppKit/NSWorkspace.h"
|
||||||
|
|
||||||
@implementation NSFileWrapper
|
@implementation NSFileWrapper
|
||||||
|
@ -101,6 +103,12 @@
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id) initSymbolicLinkWithDestinationURL: (NSURL*)url
|
||||||
|
{
|
||||||
|
// FIXME
|
||||||
|
return [self initSymbolicLinkWithDestination: [url path]];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init an instance from the file, directory, or symbolic link at path.<br />
|
* Init an instance from the file, directory, or symbolic link at path.<br />
|
||||||
* This can create a tree of instances with a directory instance at the top
|
* This can create a tree of instances with a directory instance at the top
|
||||||
|
@ -109,17 +117,14 @@
|
||||||
{
|
{
|
||||||
CREATE_AUTORELEASE_POOL(arp);
|
CREATE_AUTORELEASE_POOL(arp);
|
||||||
NSFileManager *fm = [NSFileManager defaultManager];
|
NSFileManager *fm = [NSFileManager defaultManager];
|
||||||
NSString *fileType;
|
NSDictionary *fileAttributes;
|
||||||
|
NSString *fileType;
|
||||||
|
|
||||||
NSDebugLLog(@"NSFileWrapper", @"initWithPath: %@", path);
|
NSDebugLLog(@"NSFileWrapper", @"initWithPath: %@", path);
|
||||||
|
|
||||||
// Store the full path in filename, the specification is unclear in this point
|
fileAttributes = [fm fileAttributesAtPath: path traverseLink: NO];
|
||||||
[self setFilename: path];
|
fileType = [fileAttributes fileType];
|
||||||
[self setPreferredFilename: [path lastPathComponent]];
|
if ([fileType isEqualToString: NSFileTypeDirectory])
|
||||||
[self setFileAttributes: [fm fileAttributesAtPath: path traverseLink: NO]];
|
|
||||||
|
|
||||||
fileType = [[self fileAttributes] fileType];
|
|
||||||
if ([fileType isEqualToString: @"NSFileTypeDirectory"])
|
|
||||||
{
|
{
|
||||||
NSString *filename;
|
NSString *filename;
|
||||||
NSMutableArray *fileWrappers = [NSMutableArray array];
|
NSMutableArray *fileWrappers = [NSMutableArray array];
|
||||||
|
@ -138,20 +143,44 @@
|
||||||
self = [self initDirectoryWithFileWrappers:
|
self = [self initDirectoryWithFileWrappers:
|
||||||
[NSDictionary dictionaryWithObjects: fileWrappers forKeys: filenames]];
|
[NSDictionary dictionaryWithObjects: fileWrappers forKeys: filenames]];
|
||||||
}
|
}
|
||||||
else if ([fileType isEqualToString: @"NSFileTypeRegular"])
|
else if ([fileType isEqualToString: NSFileTypeRegular])
|
||||||
{
|
{
|
||||||
self = [self initRegularFileWithContents:
|
self = [self initRegularFileWithContents:
|
||||||
AUTORELEASE([[NSData alloc] initWithContentsOfFile: path])];
|
AUTORELEASE([[NSData alloc] initWithContentsOfFile: path])];
|
||||||
}
|
}
|
||||||
else if ([fileType isEqualToString: @"NSFileTypeSymbolicLink"])
|
else if ([fileType isEqualToString: NSFileTypeSymbolicLink])
|
||||||
{
|
{
|
||||||
self = [self initSymbolicLinkWithDestination:
|
self = [self initSymbolicLinkWithDestination:
|
||||||
[fm pathContentOfSymbolicLinkAtPath: path]];
|
[fm pathContentOfSymbolicLinkAtPath: path]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store the full path in filename, the specification is unclear in this point
|
||||||
|
[self setFilename: path];
|
||||||
|
[self setPreferredFilename: [path lastPathComponent]];
|
||||||
|
[self setFileAttributes: fileAttributes];
|
||||||
|
|
||||||
[arp drain];
|
[arp drain];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id) initWithURL: (NSURL*)url
|
||||||
|
options: (NSFileWrapperReadingOptions)options
|
||||||
|
error: (NSError**)outError
|
||||||
|
{
|
||||||
|
// FIXME
|
||||||
|
if ([self readFromURL: url
|
||||||
|
options: options
|
||||||
|
error: outError])
|
||||||
|
{
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DESTROY(self);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Init an instance from data in std serial format. Serial format is the
|
// Init an instance from data in std serial format. Serial format is the
|
||||||
// same as that used by NSText's RTFDFromRange: method. This can
|
// same as that used by NSText's RTFDFromRange: method. This can
|
||||||
// create a tree of instances with a directory instance at the top
|
// create a tree of instances with a directory instance at the top
|
||||||
|
@ -435,10 +464,10 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#define GSFileWrapperDirectoryTypeCheck() \
|
#define GSFileWrapperDirectoryTypeCheck() \
|
||||||
if (_wrapperType != GSFileWrapperDirectoryType) \
|
if (![self isDirectory]) \
|
||||||
[NSException raise: NSInternalInconsistencyException \
|
[NSException raise: NSInternalInconsistencyException \
|
||||||
format: @"Can't invoke %@ on a file wrapper that" \
|
format: @"Can't invoke %@ on a file wrapper that" \
|
||||||
@" does not wrap a directory!", _cmd];
|
@" does not wrap a directory!", NSStringFromSelector(_cmd)];
|
||||||
|
|
||||||
- (NSString*) addFileWrapper: (NSFileWrapper*)doc
|
- (NSString*) addFileWrapper: (NSFileWrapper*)doc
|
||||||
{
|
{
|
||||||
|
@ -544,7 +573,7 @@
|
||||||
|
|
||||||
- (NSData*) regularFileContents
|
- (NSData*) regularFileContents
|
||||||
{
|
{
|
||||||
if (_wrapperType == GSFileWrapperRegularFileType)
|
if ([self isRegularFile])
|
||||||
{
|
{
|
||||||
return _wrapperData;
|
return _wrapperData;
|
||||||
}
|
}
|
||||||
|
@ -563,7 +592,7 @@
|
||||||
|
|
||||||
- (NSString*) symbolicLinkDestination
|
- (NSString*) symbolicLinkDestination
|
||||||
{
|
{
|
||||||
if (_wrapperType == GSFileWrapperSymbolicLinkType)
|
if ([self isSymbolicLink])
|
||||||
{
|
{
|
||||||
return _wrapperData;
|
return _wrapperData;
|
||||||
}
|
}
|
||||||
|
@ -576,6 +605,99 @@
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSURL *)symbolicLinkDestinationURL
|
||||||
|
{
|
||||||
|
// FIXME
|
||||||
|
return [NSURL fileURLWithPath: [self symbolicLinkDestination]];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) matchesContentsOfURL: (NSURL*)url
|
||||||
|
{
|
||||||
|
// FIXME
|
||||||
|
// For
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) readFromURL: (NSURL*)url
|
||||||
|
options: (NSFileWrapperReadingOptions)options
|
||||||
|
error: (NSError**)outError
|
||||||
|
{
|
||||||
|
// FIXME
|
||||||
|
NSFileManager *fm = [NSFileManager defaultManager];
|
||||||
|
NSString *path = [url path];
|
||||||
|
NSDictionary *fileAttributes;
|
||||||
|
NSString *fileType;
|
||||||
|
|
||||||
|
NSDebugLLog(@"NSFileWrapper", @"readFromURL: %@", path);
|
||||||
|
|
||||||
|
fileAttributes = [fm fileAttributesAtPath: path traverseLink: NO];
|
||||||
|
fileType = [fileAttributes fileType];
|
||||||
|
if ([fileType isEqualToString: NSFileTypeDirectory])
|
||||||
|
{
|
||||||
|
if (options & NSFileWrapperReadingImmediate)
|
||||||
|
{
|
||||||
|
NSString *filename;
|
||||||
|
NSMutableArray *fileWrappers = [NSMutableArray array];
|
||||||
|
NSArray *filenames = [fm directoryContentsAtPath: path];
|
||||||
|
NSEnumerator *enumerator = [filenames objectEnumerator];
|
||||||
|
|
||||||
|
while ((filename = [enumerator nextObject]) != nil)
|
||||||
|
{
|
||||||
|
NSFileWrapper *w;
|
||||||
|
|
||||||
|
w = [[NSFileWrapper alloc] initWithPath:
|
||||||
|
[path stringByAppendingPathComponent: filename]];
|
||||||
|
[fileWrappers addObject: w];
|
||||||
|
RELEASE(w);
|
||||||
|
}
|
||||||
|
self = [self initDirectoryWithFileWrappers:
|
||||||
|
[NSDictionary dictionaryWithObjects: fileWrappers
|
||||||
|
forKeys: filenames]];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self = [self initDirectoryWithFileWrappers: nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ([fileType isEqualToString: NSFileTypeRegular])
|
||||||
|
{
|
||||||
|
if (options & NSFileWrapperReadingWithoutMapping)
|
||||||
|
{
|
||||||
|
self = [self initRegularFileWithContents:
|
||||||
|
AUTORELEASE([[NSData alloc] initWithContentsOfFile: path])];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self = [self initRegularFileWithContents:
|
||||||
|
AUTORELEASE([[NSData alloc] initWithContentsOfMappedFile: path])];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ([fileType isEqualToString: NSFileTypeSymbolicLink])
|
||||||
|
{
|
||||||
|
self = [self initSymbolicLinkWithDestination:
|
||||||
|
[fm pathContentOfSymbolicLinkAtPath: path]];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store the full path in filename, the specification is unclear in this point
|
||||||
|
[self setFilename: path];
|
||||||
|
[self setPreferredFilename: [path lastPathComponent]];
|
||||||
|
[self setFileAttributes: [fm fileAttributesAtPath: path traverseLink: NO]];
|
||||||
|
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) writeToURL: (NSURL*)url
|
||||||
|
options: (NSFileWrapperWritingOptions)options
|
||||||
|
originalContentsURL: (NSURL*)originalContentsURL
|
||||||
|
error: (NSError**)outError
|
||||||
|
{
|
||||||
|
// FIXME
|
||||||
|
return [self writeToFile: [url path]
|
||||||
|
atomically: options & NSFileWrapperWritingAtomic
|
||||||
|
updateFilenames: options & NSFileWrapperWritingWithNameUpdating];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Archiving
|
// Archiving
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue