Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add implementation for NSFilePromise*.[hm] #270

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2024-05-07 Gregory John Casamento <[email protected]>

* Headers/AppKit/AppKit.h: Add headers
* Headers/AppKit/NSFilePromiseProvider.h
* Headers/AppKit/NSFilePromiseReceiver.h: Declarations.
* Source/GNUmakefile: Add to build
* Source/NSFilePromiseProvider.m
* Source/NSFilePromiseReceiver.m: Implementation

2024-03-18 Fred Kiefer <[email protected]>

* Source/NSTextView.m: Add support for NSFilenamenPboardType.
Expand Down
2 changes: 2 additions & 0 deletions Headers/AppKit/AppKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@
#import <AppKit/NSDocumentController.h>
#import <AppKit/NSDictionaryController.h>
#import <AppKit/NSDrawer.h>
#import <AppKit/NSFilePromiseProvider.h>
#import <AppKit/NSFilePromiseReceiver.h>
#import <AppKit/NSFileWrapperExtensions.h>
#import <AppKit/NSFontAssetRequest.h>
#import <AppKit/NSFontCollection.h>
Expand Down
83 changes: 83 additions & 0 deletions Headers/AppKit/NSFilePromiseProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* Interface of class NSFilePromiseProvider
Copyright (C) 2024 Free Software Foundation, Inc.

By: Gregory John Casamento
Date: 05-05-2024

This file is part of the GNUstep Library.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/

#ifndef _NSFilePromiseProvider_h_GNUSTEP_GUI_INCLUDE
#define _NSFilePromiseProvider_h_GNUSTEP_GUI_INCLUDE

#import <Foundation/NSObject.h>
#import <AppKit/AppKitDefines.h>
#import <AppKit/NSPasteboard.h>

#if OS_API_VERSION(MAC_OS_X_VERSION_10_12, GS_API_LATEST)

#if defined(__cplusplus)
extern "C" {
#endif

@class NSError;
@class NSFilePromiseProvider;
@class NSOperationQueue;
@class NSString;
@class NSURL;

DEFINE_BLOCK_TYPE_NO_ARGS(GSFilePromiseProviderCompletionHandler, NSError*);

@protocol NSFilePromiseProviderDelegate
- (NSString *) filePromiseProvider: (NSFilePromiseProvider *)filePromiseProvider filenameForType: (NSString *)fileType;

- (void)filePromiseProvider: (NSFilePromiseProvider *)filePromiseProvider
writePromiseToURL: (NSURL *)url
completionHandler: (GSFilePromiseProviderCompletionHandler)completionHandler;

- (NSOperationQueue *)operationQueueForFilePromiseProvider: (NSFilePromiseProvider *)filePromiseProvider;
@end

APPKIT_EXPORT_CLASS
@interface NSFilePromiseProvider : NSObject <NSPasteboardWriting>
{
NSString *_fileType;
id<NSFilePromiseProviderDelegate> _delegate;
id _userInfo;
}

- (instancetype) initWithFileType: (NSString *)fileType delegate: (id<NSFilePromiseProviderDelegate>)delegate;

- (id<NSFilePromiseProviderDelegate>) delegate;
- (void) setDelegate: (id<NSFilePromiseProviderDelegate>) delegate;

- (NSString *) fileType;
- (void) setFileType: (NSString *)fileType;

- (id) userInfo;
- (void) setUserInfo: (id)userInfo;

@end

#if defined(__cplusplus)
}
#endif

#endif /* GS_API_MACOSX */

#endif /* _NSFilePromiseProvider_h_GNUSTEP_GUI_INCLUDE */
75 changes: 75 additions & 0 deletions Headers/AppKit/NSFilePromiseReceiver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* Interface of class NSFilePromiseReceiver
Copyright (C) 2024 Free Software Foundation, Inc.

By: Gregory John Casamento
Date: 05-05-2024

This file is part of the GNUstep Library.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/

#ifndef _NSFilePromiseReceiver_h_GNUSTEP_GUI_INCLUDE
#define _NSFilePromiseReceiver_h_GNUSTEP_GUI_INCLUDE

#import <Foundation/NSObject.h>

#import <AppKit/AppKitDefines.h>
#import <AppKit/NSPasteboard.h>

#if OS_API_VERSION(MAC_OS_X_VERSION_10_12, GS_API_LATEST)

#if defined(__cplusplus)
extern "C" {
#endif

@class NSArray;
@class NSError;
@class NSOperationQueue;
@class NSURL;

DEFINE_BLOCK_TYPE(GSFilePromiseReceiverReaderHandler, void, NSURL*, NSError*);

APPKIT_EXPORT_CLASS
@interface NSFilePromiseReceiver : NSObject <NSPasteboardReading>
{
NSArray *_fileNames;
NSArray *_fileTypes;
NSArray *_readableDraggedTypes;
}

- (NSArray *) fileNames;
- (void) setFileNames: (NSArray *)fileNames;

- (NSArray *) fileTypes;
- (void) setFileTypes: (NSArray *)fileTypes;

- (NSArray *) readableDraggedTypes;

- (void) receivePromisedFilesAtDestination: (NSURL *)destinationDir
options: (NSDictionary *)options
operationQueue: (NSOperationQueue *)operationQueue
reader: (GSFilePromiseReceiverReaderHandler)reader;

@end

#if defined(__cplusplus)
}
#endif

#endif /* GS_API_MACOSX */

#endif /* _NSFilePromiseReceiver_h_GNUSTEP_GUI_INCLUDE */
4 changes: 4 additions & 0 deletions Source/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ NSDocumentController.m \
NSDrawer.m \
NSEPSImageRep.m \
NSEvent.m \
NSFilePromiseProvider.m \
NSFilePromiseReceiver.m \
NSFileWrapperExtensions.m \
NSFont.m \
NSFontAssetRequest.m \
Expand Down Expand Up @@ -457,6 +459,8 @@ NSDrawer.h \
NSEPSImageRep.h \
NSErrors.h \
NSEvent.h \
NSFilePromiseProvider.h \
NSFilePromiseReceiver.h \
NSFileWrapper.h \
NSFileWrapperExtensions.h \
NSFont.h \
Expand Down
91 changes: 91 additions & 0 deletions Source/NSFilePromiseProvider.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* Implementation of class NSFilePromiseProvider
Copyright (C) 2024 Free Software Foundation, Inc.

By: Gregory John Casamento
Date: 05-05-2024

This file is part of the GNUstep Library.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/

#import <Foundation/NSError.h>
#import <Foundation/NSString.h>

#import "AppKit/NSFilePromiseProvider.h"

@implementation NSFilePromiseProvider

- (instancetype) initWithFileType: (NSString *)fileType delegate: (id<NSFilePromiseProviderDelegate>)delegate
{
self = [super init];

if (self != nil)
{
ASSIGN(_fileType, fileType);
_delegate = delegate;
}

return self;
}

- (void) dealloc
{
RELEASE(_fileType);
[super dealloc];
}

- (id<NSFilePromiseProviderDelegate>) delegate
{
return _delegate;
}

- (void) setDelegate: (id<NSFilePromiseProviderDelegate>)delegate
{
_delegate = delegate; // retained by caller...
}

- (NSString *) fileType
{
return _fileType;
}

- (void) setFileType: (NSString *)fileType
{
ASSIGN(_fileType, fileType);
}

- (id) userInfo
{
return _userInfo;
}

- (void) setUserInfo: (id)userInfo
{
ASSIGN(_userInfo, userInfo);
}

- (NSArray *) writableTypesForPasteboard: (NSPasteboard *)pasteboard
{
return nil;
}

- (id) pasteboardPropertyListForType: (NSString *)type
{
return nil;
}

@end
95 changes: 95 additions & 0 deletions Source/NSFilePromiseReceiver.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* Implementation of class NSFilePromiseReceiver
Copyright (C) 2024 Free Software Foundation, Inc.

By: Gregory John Casamento
Date: 05-05-2024

This file is part of the GNUstep Library.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/

#import "AppKit/NSFilePromiseReceiver.h"

#import <Foundation/NSString.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSOperation.h>

#import "GSFastEnumeration.h"

@implementation NSFilePromiseReceiver

// NSPasteboardReading protocol -- start

- (id)initWithPasteboardPropertyList: (id)propertyList ofType: (NSString *)type
{
self = [super init];

if (self != nil)
{
}

return self;
}

+ (NSArray *) readableTypesForPasteboard: (NSPasteboard *)pasteboard
{
return nil;
}

// NSPasteboardReading protocol -- end

- (void) dealloc
{
RELEASE(_fileNames);
RELEASE(_fileTypes);
RELEASE(_readableDraggedTypes);
[super dealloc];
}

- (NSArray *) fileNames
{
return _fileNames;
}

- (void) setFileNames: (NSArray *)fileNames
{
ASSIGN(_fileNames, fileNames);
}

- (NSArray *) fileTypes
{
return _fileTypes;
}

- (void) setFileTypes: (NSArray *)fileTypes
{
ASSIGN(_fileTypes, fileTypes);
}

- (NSArray *) readableDraggedTypes
{
return _readableDraggedTypes;
}

- (void) receivePromisedFilesAtDestination: (NSURL *)destinationDir
options: (NSDictionary *)options
operationQueue: (NSOperationQueue *)operationQueue
reader: (GSFilePromiseReceiverReaderHandler)reader
{
}

@end
Loading