Improvements to existing NSDataLink code

This commit is contained in:
Gregory John Casamento 2023-03-17 06:11:50 -04:00
parent e79bdc5fda
commit 0a533772b2
4 changed files with 280 additions and 251 deletions

View file

@ -64,25 +64,25 @@ APPKIT_EXPORT_CLASS
// Attributes
@private
// link info.
NSDataLinkNumber linkNumber;
NSDataLinkDisposition disposition;
NSDataLinkUpdateMode updateMode;
NSDataLinkNumber _linkNumber;
NSDataLinkDisposition _disposition;
NSDataLinkUpdateMode _updateMode;
// info about the source.
NSDate *lastUpdateTime;
NSString *sourceApplicationName;
NSString *sourceFilename;
NSSelection *sourceSelection;
id sourceManager;
NSDate *_lastUpdateTime;
NSString *_sourceApplicationName;
NSString *_sourceFilename;
NSSelection *_sourceSelection;
id _sourceManager;
// info about the destination
NSString *destinationApplicationName;
NSString *destinationFilename;
NSSelection *destinationSelection;
id destinationManager;
NSString *_destinationApplicationName;
NSString *_destinationFilename;
NSSelection *_destinationSelection;
id _destinationManager;
// types.
NSArray *types;
NSArray *_types;
// other flags
struct __linkFlags {

View file

@ -45,10 +45,10 @@ APPKIT_EXPORT_CLASS
@interface NSDataLinkManager : NSObject <NSCoding>
{
// Attributes
id delegate;
NSString *filename;
NSMutableArray *sourceLinks;
NSMutableArray *destinationLinks;
id _delegate;
NSString *_filename;
NSMutableArray *_sourceLinks;
NSMutableArray *_destinationLinks;
struct __dlmFlags {
unsigned areLinkOutlinesVisible:1;
@ -62,22 +62,22 @@ APPKIT_EXPORT_CLASS
//
// Initializing and Freeing a Link Manager
//
- (id)initWithDelegate:(id)anObject;
- (id)initWithDelegate:(id)anObject
fromFile:(NSString *)path;
- (id) initWithDelegate: (id)anObject;
- (id) initWithDelegate: (id)anObject
fromFile: (NSString *)path;
//
// Adding and Removing Links
//
- (BOOL)addLink:(NSDataLink *)link
at:(NSSelection *)selection;
- (BOOL)addLinkAsMarker:(NSDataLink *)link
at:(NSSelection *)selection;
- (NSDataLink *)addLinkPreviouslyAt:(NSSelection *)oldSelection
fromPasteboard:(NSPasteboard *)pasteboard
at:(NSSelection *)selection;
- (BOOL)addLink: (NSDataLink *)link
at: (NSSelection *)selection;
- (BOOL)addLinkAsMarker: (NSDataLink *)link
at: (NSSelection *)selection;
- (NSDataLink *)addLinkPreviouslyAt: (NSSelection *)oldSelection
fromPasteboard: (NSPasteboard *)pasteboard
at: (NSSelection *)selection;
- (void)breakAllLinks;
- (void)writeLinksToPasteboard:(NSPasteboard *)pasteboard;
- (void)writeLinksToPasteboard: (NSPasteboard *)pasteboard;
//
// Informing the Link Manager of Document Status
@ -86,8 +86,8 @@ APPKIT_EXPORT_CLASS
- (void)noteDocumentEdited;
- (void)noteDocumentReverted;
- (void)noteDocumentSaved;
- (void)noteDocumentSavedAs:(NSString *)path;
- (void)noteDocumentSavedTo:(NSString *)path;
- (void)noteDocumentSavedAs: (NSString *)path;
- (void)noteDocumentSavedTo: (NSString *)path;
//
// Getting and Setting Information about the Link Manager
@ -97,16 +97,16 @@ APPKIT_EXPORT_CLASS
- (NSString *)filename;
- (BOOL)interactsWithUser;
- (BOOL)isEdited;
- (void)setDelegateVerifiesLinks:(BOOL)flag;
- (void)setInteractsWithUser:(BOOL)flag;
- (void)setDelegateVerifiesLinks: (BOOL)flag;
- (void)setInteractsWithUser: (BOOL)flag;
//
// Getting and Setting Information about the Manager's Links
//
- (BOOL)areLinkOutlinesVisible;
- (NSEnumerator *)destinationLinkEnumerator;
- (NSDataLink *)destinationLinkWithSelection:(NSSelection *)destSel;
- (void)setLinkOutlinesVisible:(BOOL)flag;
- (NSDataLink *)destinationLinkWithSelection: (NSSelection *)destSel;
- (void)setLinkOutlinesVisible: (BOOL)flag;
- (NSEnumerator *)sourceLinkEnumerator;
@end
@ -116,29 +116,29 @@ APPKIT_EXPORT_CLASS
//
@interface NSObject (NSDataLinkManagerDelegate)
// data link management methods.
- (void)dataLinkManager:(NSDataLinkManager *)sender
didBreakLink:(NSDataLink *)link;
- (BOOL)dataLinkManager:(NSDataLinkManager *)sender
isUpdateNeededForLink:(NSDataLink *)link;
- (void)dataLinkManager:(NSDataLinkManager *)sender
startTrackingLink:(NSDataLink *)link;
- (void)dataLinkManager:(NSDataLinkManager *)sender
stopTrackingLink:(NSDataLink *)link;
- (void)dataLinkManagerCloseDocument:(NSDataLinkManager *)sender;
- (void)dataLinkManagerDidEditLinks:(NSDataLinkManager *)sender;
- (void)dataLinkManagerRedrawLinkOutlines:(NSDataLinkManager *)sender;
- (BOOL)dataLinkManagerTracksLinksIndividually:(NSDataLinkManager *)sender;
- (void)dataLinkManager: (NSDataLinkManager *)sender
didBreakLink: (NSDataLink *)link;
- (BOOL)dataLinkManager: (NSDataLinkManager *)sender
isUpdateNeededForLink: (NSDataLink *)link;
- (void)dataLinkManager: (NSDataLinkManager *)sender
startTrackingLink: (NSDataLink *)link;
- (void)dataLinkManager: (NSDataLinkManager *)sender
stopTrackingLink: (NSDataLink *)link;
- (void)dataLinkManagerCloseDocument: (NSDataLinkManager *)sender;
- (void)dataLinkManagerDidEditLinks: (NSDataLinkManager *)sender;
- (void)dataLinkManagerRedrawLinkOutlines: (NSDataLinkManager *)sender;
- (BOOL)dataLinkManagerTracksLinksIndividually: (NSDataLinkManager *)sender;
// selection management methods.
- (BOOL)copyToPasteboard:(NSPasteboard *)pasteboard
at:(NSSelection *)selection
cheapCopyAllowed:(BOOL)flag;
- (BOOL)importFile:(NSString *)filename
at:(NSSelection *)selection;
- (BOOL)pasteFromPasteboard:(NSPasteboard *)pasteboard
at:(NSSelection *)selection;
- (BOOL)showSelection:(NSSelection *)selection;
- (NSWindow *)windowForSelection:(NSSelection *)selection;
- (BOOL)copyToPasteboard: (NSPasteboard *)pasteboard
at: (NSSelection *)selection
cheapCopyAllowed: (BOOL)flag;
- (BOOL)importFile: (NSString *)filename
at: (NSSelection *)selection;
- (BOOL)pasteFromPasteboard: (NSPasteboard *)pasteboard
at: (NSSelection *)selection;
- (BOOL)showSelection: (NSSelection *)selection;
- (NSWindow *)windowForSelection: (NSSelection *)selection;
@end

View file

@ -6,7 +6,7 @@
Date: 2005
Author: Scott Christley <scottc@net-community.com>
Date: 1996
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
@ -21,10 +21,10 @@
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
*/
#include "config.h"
#import <Foundation/NSFileManager.h>
@ -56,31 +56,31 @@
//
// Initializing a Link
//
- (id)initLinkedToFile:(NSString *)filename
- (id)initLinkedToFile: (NSString *)filename
{
if ((self = [self init]) != nil)
{
NSData *data = [NSData dataWithBytes: [filename cString] length: [filename cStringLength]];
NSSelection *selection = [NSSelection selectionWithDescriptionData: data];
ASSIGN(sourceSelection, selection);
ASSIGN(_sourceSelection, selection);
}
return self;
}
- (id)initLinkedToSourceSelection:(NSSelection *)selection
managedBy:(NSDataLinkManager *)linkManager
supportingTypes:(NSArray *)newTypes
- (id)initLinkedToSourceSelection: (NSSelection *)selection
managedBy: (NSDataLinkManager *)linkManager
supportingTypes: (NSArray *)newTypes
{
if ((self = [self init]) != nil)
{
ASSIGN(sourceSelection,selection);
ASSIGN(sourceManager,linkManager);
ASSIGN(types,newTypes);
ASSIGN(_sourceSelection,selection);
ASSIGN(_sourceManager,linkManager);
ASSIGN(_types,newTypes);
}
return self;
}
- (id)initWithContentsOfFile:(NSString *)filename
- (id)initWithContentsOfFile: (NSString *)filename
{
NSData *data = [[NSData alloc] initWithContentsOfFile: filename];
id object = [NSUnarchiver unarchiveObjectWithData: data];
@ -90,7 +90,7 @@
return RETAIN(object);
}
- (id)initWithPasteboard:(NSPasteboard *)pasteboard
- (id)initWithPasteboard: (NSPasteboard *)pasteboard
{
NSData *data = [pasteboard dataForType: NSDataLinkPboardType];
id object = [NSUnarchiver unarchiveObjectWithData: data];
@ -99,10 +99,31 @@
return RETAIN(object);
}
- (void) dealloc
{
[self break];
RELEASE(_lastUpdateTime);
RELEASE(_sourceApplicationName);
RELEASE(_sourceFilename);
RELEASE(_sourceSelection);
_sourceManager = nil; // manager retains us...
RELEASE(_destinationApplicationName);
RELEASE(_destinationFilename);
RELEASE(_destinationSelection);
_destinationManager = nil; // manager retains us...
RELEASE(_types);
[super dealloc];
}
//
// Exporting a Link
//
- (BOOL)saveLinkIn:(NSString *)directoryName
- (BOOL)saveLinkIn: (NSString *)directoryName
{
NSSavePanel *sp;
int result;
@ -119,7 +140,7 @@
{
/* NSSavePanel has already asked if it's ok to replace */
NSString *bPath = [path stringByAppendingString: @"~"];
[mgr removeFileAtPath: bPath handler: nil];
[mgr movePath: path toPath: bPath handler: nil];
}
@ -127,10 +148,11 @@
// save it.
return [self writeToFile: path];
}
return NO;
}
- (BOOL)writeToFile:(NSString *)filename
- (BOOL)writeToFile: (NSString *)filename
{
NSString *path = filename;
@ -142,7 +164,7 @@
return [NSArchiver archiveRootObject: self toFile: path];
}
- (void)writeToPasteboard:(NSPasteboard *)pasteboard
- (void)writeToPasteboard: (NSPasteboard *)pasteboard
{
NSData *data = [NSArchiver archivedDataWithRootObject: self];
[pasteboard setData: data forType: NSDataLinkPboardType];
@ -153,17 +175,17 @@
//
- (NSDataLinkDisposition)disposition
{
return disposition;
return _disposition;
}
- (NSDataLinkNumber)linkNumber
{
return linkNumber;
return _linkNumber;
}
- (NSDataLinkManager *)manager
{
return sourceManager;
return _sourceManager;
}
//
@ -171,7 +193,7 @@
//
- (NSDate *)lastUpdateTime
{
return lastUpdateTime;
return _lastUpdateTime;
}
- (BOOL)openSource
@ -181,22 +203,22 @@
- (NSString *)sourceApplicationName
{
return sourceApplicationName;
return _sourceApplicationName;
}
- (NSString *)sourceFilename
{
return sourceFilename;
return _sourceFilename;
}
- (NSSelection *)sourceSelection
{
return sourceSelection;
return _sourceSelection;
}
- (NSArray *)types
{
return types;
return _types;
}
//
@ -204,17 +226,17 @@
//
- (NSString *)destinationApplicationName
{
return destinationApplicationName;
return _destinationApplicationName;
}
- (NSString *)destinationFilename
{
return destinationFilename;
return _destinationFilename;
}
- (NSSelection *)destinationSelection
{
return destinationSelection;
return _destinationSelection;
}
//
@ -222,21 +244,23 @@
//
- (BOOL)break
{
id srcDelegate = [sourceManager delegate];
id dstDelegate = [destinationManager delegate];
id srcDelegate = [_sourceManager delegate];
id dstDelegate = [_destinationManager delegate];
// The spec is quite vague here. I don't know under what
// circumstances a link cannot be broken, so this method
// The spec is quite vague here. I don't know under what
// circumstances a link cannot be broken, so this method
// always returns YES.
_disposition = NSLinkBroken;
if ([srcDelegate respondsToSelector: @selector(dataLinkManager:didBreakLink:)])
{
[srcDelegate dataLinkManager: sourceManager didBreakLink: self];
[srcDelegate dataLinkManager: _sourceManager didBreakLink: self];
}
if ([dstDelegate respondsToSelector: @selector(dataLinkManager:didBreakLink:)])
{
[dstDelegate dataLinkManager: destinationManager didBreakLink: self];
[dstDelegate dataLinkManager: _destinationManager didBreakLink: self];
}
return (_flags.broken = YES);
@ -246,15 +270,20 @@
{
_flags.isDirty = YES;
if (updateMode != NSUpdateNever)
if (_updateMode != NSUpdateNever)
{
[sourceManager noteDocumentEdited];
[_sourceManager noteDocumentEdited];
}
}
- (void)setUpdateMode:(NSDataLinkUpdateMode)mode
- (NSDataLinkUpdateMode)updateMode
{
updateMode = mode;
return _updateMode;
}
- (void)setUpdateMode: (NSDataLinkUpdateMode)mode
{
_updateMode = mode;
}
- (BOOL)updateDestination
@ -262,38 +291,33 @@
return NO;
}
- (NSDataLinkUpdateMode)updateMode
{
return updateMode;
}
//
// NSCoding protocol
//
- (void) encodeWithCoder: (NSCoder*)aCoder
{
BOOL flag = NO;
if ([aCoder allowsKeyedCoding])
{
[aCoder encodeInt: linkNumber forKey: @"GSLinkNumber"];
[aCoder encodeInt: disposition forKey: @"GSUpdateMode"];
[aCoder encodeInt: updateMode forKey: @"GSLastUpdateMode"];
[aCoder encodeInt: _linkNumber forKey: @"GSLinkNumber"];
[aCoder encodeInt: _disposition forKey: @"GSUpdateMode"];
[aCoder encodeInt: _updateMode forKey: @"GSLastUpdateMode"];
[aCoder encodeObject: lastUpdateTime forKey: @"GSLastUpdateTime"];
[aCoder encodeObject: _lastUpdateTime forKey: @"GSLastUpdateTime"];
[aCoder encodeObject: sourceApplicationName forKey: @"GSSourceApplicationName"];
[aCoder encodeObject: sourceFilename forKey: @"GSSourceFilename"];
[aCoder encodeObject: sourceSelection forKey: @"GSSourceSelection"];
[aCoder encodeObject: sourceManager forKey: @"GSSourceManager"];
[aCoder encodeObject: _sourceApplicationName forKey: @"GSSourceApplicationName"];
[aCoder encodeObject: _sourceFilename forKey: @"GSSourceFilename"];
[aCoder encodeObject: _sourceSelection forKey: @"GSSourceSelection"];
[aCoder encodeObject: _sourceManager forKey: @"GSSourceManager"];
[aCoder encodeObject: _destinationApplicationName forKey: @"GSDestinationApplicationName"];
[aCoder encodeObject: _destinationFilename forKey: @"GSDestinationFilename"];
[aCoder encodeObject: _destinationSelection forKey: @"GSDestinationSelection"];
[aCoder encodeObject: _destinationManager forKey: @"GSDestinationManager"];
[aCoder encodeObject: _types forKey: @"GSTypes"];
[aCoder encodeObject: destinationApplicationName forKey: @"GSDestinationApplicationName"];
[aCoder encodeObject: destinationFilename forKey: @"GSDestinationFilename"];
[aCoder encodeObject: destinationSelection forKey: @"GSDestinationSelection"];
[aCoder encodeObject: destinationManager forKey: @"GSDestinationManager"];
[aCoder encodeObject: types forKey: @"GSTypes"];
// flags...
flag = _flags.appVerifies;
[aCoder encodeBool: flag forKey: @"GSAppVerifies"];
@ -308,23 +332,23 @@
}
else
{
[aCoder encodeValueOfObjCType: @encode(int) at: &linkNumber];
[aCoder encodeValueOfObjCType: @encode(int) at: &disposition];
[aCoder encodeValueOfObjCType: @encode(int) at: &updateMode];
[aCoder encodeValueOfObjCType: @encode(id) at: &lastUpdateTime];
[aCoder encodeValueOfObjCType: @encode(id) at: &sourceApplicationName];
[aCoder encodeValueOfObjCType: @encode(id) at: &sourceFilename];
[aCoder encodeValueOfObjCType: @encode(id) at: &sourceSelection];
[aCoder encodeValueOfObjCType: @encode(id) at: &sourceManager];
[aCoder encodeValueOfObjCType: @encode(id) at: &destinationApplicationName];
[aCoder encodeValueOfObjCType: @encode(id) at: &destinationFilename];
[aCoder encodeValueOfObjCType: @encode(id) at: &destinationSelection];
[aCoder encodeValueOfObjCType: @encode(id) at: &destinationManager];
[aCoder encodeValueOfObjCType: @encode(id) at: &types];
[aCoder encodeValueOfObjCType: @encode(int) at: &_linkNumber];
[aCoder encodeValueOfObjCType: @encode(int) at: &_disposition];
[aCoder encodeValueOfObjCType: @encode(int) at: &_updateMode];
[aCoder encodeValueOfObjCType: @encode(id) at: &_lastUpdateTime];
[aCoder encodeValueOfObjCType: @encode(id) at: &_sourceApplicationName];
[aCoder encodeValueOfObjCType: @encode(id) at: &_sourceFilename];
[aCoder encodeValueOfObjCType: @encode(id) at: &_sourceSelection];
[aCoder encodeValueOfObjCType: @encode(id) at: &_sourceManager];
[aCoder encodeValueOfObjCType: @encode(id) at: &_destinationApplicationName];
[aCoder encodeValueOfObjCType: @encode(id) at: &_destinationFilename];
[aCoder encodeValueOfObjCType: @encode(id) at: &_destinationSelection];
[aCoder encodeValueOfObjCType: @encode(id) at: &_destinationManager];
[aCoder encodeValueOfObjCType: @encode(id) at: &_types];
// flags...
flag = _flags.appVerifies;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
@ -345,34 +369,34 @@
{
id obj;
linkNumber = [aCoder decodeIntForKey: @"GSLinkNumber"];
disposition = [aCoder decodeIntForKey: @"GSDisposition"];
updateMode = [aCoder decodeIntForKey: @"GSUpdateMode"];
_linkNumber = [aCoder decodeIntForKey: @"GSLinkNumber"];
_disposition = [aCoder decodeIntForKey: @"GSDisposition"];
_updateMode = [aCoder decodeIntForKey: @"GSUpdateMode"];
obj = [aCoder decodeObjectForKey: @"GSSourceManager"];
ASSIGN(sourceManager,obj);
ASSIGN(_sourceManager,obj);
obj = [aCoder decodeObjectForKey: @"GSDestinationManager"];
ASSIGN(destinationManager,obj);
ASSIGN(_destinationManager,obj);
obj = [aCoder decodeObjectForKey: @"GSLastUpdateTime"];
ASSIGN(lastUpdateTime, obj);
ASSIGN(_lastUpdateTime, obj);
obj = [aCoder decodeObjectForKey: @"GSSourceApplicationName"];
ASSIGN(sourceApplicationName,obj);
ASSIGN(_sourceApplicationName,obj);
obj = [aCoder decodeObjectForKey: @"GSSourceFilename"];
ASSIGN(sourceFilename,obj);
ASSIGN(_sourceFilename,obj);
obj = [aCoder decodeObjectForKey: @"GSSourceSelection"];
ASSIGN(sourceSelection,obj);
ASSIGN(_sourceSelection,obj);
obj = [aCoder decodeObjectForKey: @"GSSourceManager"];
ASSIGN(sourceManager,obj);
ASSIGN(_sourceManager,obj);
obj = [aCoder decodeObjectForKey: @"GSDestinationApplicationName"];
ASSIGN(destinationApplicationName,obj);
ASSIGN(_destinationApplicationName,obj);
obj = [aCoder decodeObjectForKey: @"GSDestinationFilename"];
ASSIGN(destinationFilename,obj);
ASSIGN(_destinationFilename,obj);
obj = [aCoder decodeObjectForKey: @"GSDestinationSelection"];
ASSIGN(destinationSelection,obj);
ASSIGN(_destinationSelection,obj);
obj = [aCoder decodeObjectForKey: @"GSDestinationManager"];
ASSIGN(destinationManager,obj);
ASSIGN(_destinationManager,obj);
obj = [aCoder decodeObjectForKey: @"GSTypes"];
ASSIGN(types,obj);
ASSIGN(_types,obj);
// flags...
_flags.appVerifies = [aCoder decodeBoolForKey: @"GSAppVerifies"];
@ -387,26 +411,26 @@
if (version == 0)
{
BOOL flag = NO;
[aCoder decodeValueOfObjCType: @encode(int) at: &linkNumber];
[aCoder decodeValueOfObjCType: @encode(int) at: &disposition];
[aCoder decodeValueOfObjCType: @encode(int) at: &updateMode];
[aCoder decodeValueOfObjCType: @encode(id) at: &sourceManager];
[aCoder decodeValueOfObjCType: @encode(id) at: &destinationManager];
[aCoder decodeValueOfObjCType: @encode(id) at: &lastUpdateTime];
[aCoder decodeValueOfObjCType: @encode(id) at: &sourceApplicationName];
[aCoder decodeValueOfObjCType: @encode(id) at: &sourceFilename];
[aCoder decodeValueOfObjCType: @encode(id) at: &sourceSelection];
[aCoder decodeValueOfObjCType: @encode(id) at: &sourceManager];
[aCoder decodeValueOfObjCType: @encode(id) at: &destinationApplicationName];
[aCoder decodeValueOfObjCType: @encode(id) at: &destinationFilename];
[aCoder decodeValueOfObjCType: @encode(id) at: &destinationSelection];
[aCoder decodeValueOfObjCType: @encode(id) at: &destinationManager];
[aCoder decodeValueOfObjCType: @encode(id) at: &types];
[aCoder decodeValueOfObjCType: @encode(int) at: &_linkNumber];
[aCoder decodeValueOfObjCType: @encode(int) at: &_disposition];
[aCoder decodeValueOfObjCType: @encode(int) at: &_updateMode];
[aCoder decodeValueOfObjCType: @encode(id) at: &_sourceManager];
[aCoder decodeValueOfObjCType: @encode(id) at: &_destinationManager];
[aCoder decodeValueOfObjCType: @encode(id) at: &_lastUpdateTime];
[aCoder decodeValueOfObjCType: @encode(id) at: &_sourceApplicationName];
[aCoder decodeValueOfObjCType: @encode(id) at: &_sourceFilename];
[aCoder decodeValueOfObjCType: @encode(id) at: &_sourceSelection];
[aCoder decodeValueOfObjCType: @encode(id) at: &_sourceManager];
[aCoder decodeValueOfObjCType: @encode(id) at: &_destinationApplicationName];
[aCoder decodeValueOfObjCType: @encode(id) at: &_destinationFilename];
[aCoder decodeValueOfObjCType: @encode(id) at: &_destinationSelection];
[aCoder decodeValueOfObjCType: @encode(id) at: &_destinationManager];
[aCoder decodeValueOfObjCType: @encode(id) at: &_types];
// flags...
[aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.appVerifies = flag;

View file

@ -6,7 +6,7 @@
Date: 2005
Author: Scott Christley <scottc@net-community.com>
Date: 1996
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
@ -21,20 +21,24 @@
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
*/
#include "config.h"
#import <Foundation/NSDictionary.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSArchiver.h>
#import "AppKit/NSDataLinkManager.h"
#import "AppKit/NSDataLink.h"
#import "AppKit/NSPasteboard.h"
#import "GSFastEnumeration.h"
// Private setters/getters for links...
@interface NSDataLink (Private)
- (void) setLastUpdateTime: (NSDate *)date;
- (void) setSourceFilename: (NSString *)src;
@ -48,37 +52,37 @@
@implementation NSDataLink (Private)
- (void) setLastUpdateTime: (NSDate *)date
{
ASSIGN(lastUpdateTime, date);
ASSIGN(_lastUpdateTime, date);
}
- (void) setSourceFilename: (NSString *)src
{
ASSIGN(sourceFilename,src);
ASSIGN(_sourceFilename,src);
}
- (void) setDestinationFilename: (NSString *)dst
{
ASSIGN(destinationFilename, dst);
ASSIGN(_destinationFilename, dst);
}
- (void) setSourceManager: (id)src
{
ASSIGN(sourceManager,src);
ASSIGN(_sourceManager,src);
}
- (void) setDestinationManager: (id)dst
{
ASSIGN(destinationManager,dst);
ASSIGN(_destinationManager,dst);
}
- (void) setSourceSelection: (id)src
{
ASSIGN(sourceSelection,src);
ASSIGN(_sourceSelection,src);
}
- (void) setDestinationSelection: (id)dst
{
ASSIGN(destinationSelection,dst);
ASSIGN(_destinationSelection,dst);
}
- (void) setIsMarker: (BOOL)flag
@ -108,14 +112,14 @@
//
// Initializing and Freeing a Link Manager
//
- (id)initWithDelegate:(id)anObject
- (id)initWithDelegate: (id)anObject
{
self = [super init];
if (self != nil)
{
ASSIGN(delegate,anObject);
filename = nil;
_delegate = anObject; // don't retain...
_filename = nil;
_flags.delegateVerifiesLinks = NO;
_flags.interactsWithUser = NO;
_flags.isEdited = NO;
@ -125,15 +129,15 @@
return self;
}
- (id)initWithDelegate:(id)anObject
fromFile:(NSString *)path
- (id) initWithDelegate: (id)anObject
fromFile: (NSString *)path
{
self = [super init];
if (self != nil)
{
ASSIGN(delegate,anObject);
ASSIGN(filename,path);
_delegate = anObject; // don't retain...
ASSIGN(_filename,path);
_flags.delegateVerifiesLinks = NO;
_flags.interactsWithUser = NO;
_flags.isEdited = NO;
@ -146,33 +150,33 @@
//
// Adding and Removing Links
//
- (BOOL)addLink:(NSDataLink *)link
at:(NSSelection *)selection
- (BOOL) addLink: (NSDataLink *)link
at: (NSSelection *)selection
{
BOOL result = NO;
[link setDestinationSelection: selection];
[link setDestinationManager: self];
if ([destinationLinks containsObject: link] == NO)
if ([_destinationLinks containsObject: link] == NO)
{
[destinationLinks addObject: link];
[_destinationLinks addObject: link];
result = YES;
}
return result;
}
- (BOOL)addLinkAsMarker:(NSDataLink *)link
at:(NSSelection *)selection
- (BOOL) addLinkAsMarker: (NSDataLink *)link
at: (NSSelection *)selection
{
[link setIsMarker: YES];
return [self addLink: link at: selection];
}
- (NSDataLink *)addLinkPreviouslyAt:(NSSelection *)oldSelection
fromPasteboard:(NSPasteboard *)pasteboard
at:(NSSelection *)selection
- (NSDataLink *) addLinkPreviouslyAt: (NSSelection *)oldSelection
fromPasteboard: (NSPasteboard *)pasteboard
at: (NSSelection *)selection
{
NSData *data = [pasteboard dataForType: NSDataLinkPboardType];
NSArray *links = [NSUnarchiver unarchiveObjectWithData: data];
@ -181,86 +185,86 @@
while ((link = [en nextObject]) != nil)
{
if ([link destinationSelection] == oldSelection)
{
if ([link destinationSelection] == oldSelection)
{
}
}
return nil;
}
- (void)breakAllLinks
- (void) breakAllLinks
{
NSArray *allLinks = [sourceLinks arrayByAddingObjectsFromArray: destinationLinks];
NSEnumerator *en = [allLinks objectEnumerator];
id obj = nil;
while ((obj = [en nextObject]) != nil)
FOR_IN(NSDataLink*, src, _sourceLinks)
{
[obj break];
[src break];
}
END_FOR_IN(_sourceLinks);
FOR_IN(NSDataLink*, dst, _destinationLinks)
{
[dst break];
}
END_FOR_IN(_destinationLinks);
}
- (void)writeLinksToPasteboard:(NSPasteboard *)pasteboard
- (void) writeLinksToPasteboard: (NSPasteboard *)pasteboard
{
NSArray *allLinks = [sourceLinks arrayByAddingObjectsFromArray: destinationLinks];
NSEnumerator *en = [allLinks objectEnumerator];
id obj = nil;
while ((obj = [en nextObject]) != nil)
FOR_IN(NSDataLink*, obj, _sourceLinks)
{
[obj writeToPasteboard: pasteboard];
}
END_FOR_IN(_sourceLinks);
}
//
// Informing the Link Manager of Document Status
//
- (void)noteDocumentClosed
- (void) noteDocumentClosed
{
if ([delegate respondsToSelector: @selector(dataLinkManagerCloseDocument:)])
if ([_delegate respondsToSelector: @selector(dataLinkManagerCloseDocument:)])
{
[delegate dataLinkManagerCloseDocument: self];
[_delegate dataLinkManagerCloseDocument: self];
}
}
- (void)noteDocumentEdited
- (void) noteDocumentEdited
{
if ([delegate respondsToSelector: @selector(dataLinkManagerDidEditLinks:)])
if ([_delegate respondsToSelector: @selector(dataLinkManagerDidEditLinks:)])
{
[delegate dataLinkManagerDidEditLinks: self];
[_delegate dataLinkManagerDidEditLinks: self];
}
}
- (void)noteDocumentReverted
- (void) noteDocumentReverted
{
if ([delegate respondsToSelector: @selector(dataLinkManagerDidEditLinks:)])
if ([_delegate respondsToSelector: @selector(dataLinkManagerDidEditLinks:)])
{
[delegate dataLinkManagerDidEditLinks: self];
[_delegate dataLinkManagerDidEditLinks: self];
}
}
- (void)noteDocumentSaved
- (void) noteDocumentSaved
{
// implemented by subclass
// implemented by subclass
}
- (void)noteDocumentSavedAs:(NSString *)path
- (void) noteDocumentSavedAs:(NSString *)path
{
// implemented by subclass
// implemented by subclass
}
- (void)noteDocumentSavedTo:(NSString *)path
{
// implemented by subclass
// implemented by subclass
}
//
// Getting and Setting Information about the Link Manager
//
- (id)delegate
- (id) delegate
{
return delegate;
return _delegate;
}
- (BOOL)delegateVerifiesLinks
@ -270,7 +274,7 @@
- (NSString *)filename
{
return filename;
return _filename;
}
- (BOOL)interactsWithUser
@ -303,23 +307,24 @@
- (NSEnumerator *)destinationLinkEnumerator
{
return [destinationLinks objectEnumerator];
return [_destinationLinks objectEnumerator];
}
- (NSDataLink *)destinationLinkWithSelection:(NSSelection *)destSel
{
NSEnumerator *en = [self destinationLinkEnumerator];
id obj = nil;
id result = nil;
while ((obj = [en nextObject]) != nil)
FOR_IN(id, obj, _destinationLinks)
{
if ([obj destinationSelection] == destSel)
if ([[obj destinationSelection] isEqual: destSel])
{
result = obj;
break;
}
}
END_FOR_IN(_destinationLinks);
return obj;
return result;
}
- (void)setLinkOutlinesVisible:(BOOL)flag
@ -329,7 +334,7 @@
- (NSEnumerator *)sourceLinkEnumerator
{
return [sourceLinks objectEnumerator];
return [_sourceLinks objectEnumerator];
}
//
@ -341,10 +346,10 @@
if ([aCoder allowsKeyedCoding])
{
[aCoder encodeObject: filename forKey: @"GSFilename"];
[aCoder encodeObject: sourceLinks forKey: @"GSSourceLinks"];
[aCoder encodeObject: destinationLinks forKey: @"GSDestinationLinks"];
[aCoder encodeObject: _filename forKey: @"GSFilename"];
[aCoder encodeObject: _sourceLinks forKey: @"GSSourceLinks"];
[aCoder encodeObject: _destinationLinks forKey: @"GSDestinationLinks"];
flag = _flags.areLinkOutlinesVisible;
[aCoder encodeBool: flag forKey: @"GSAreLinkOutlinesVisible"];
flag = _flags.delegateVerifiesLinks;
@ -356,10 +361,10 @@
}
else
{
[aCoder encodeValueOfObjCType: @encode(id) at: &filename];
[aCoder encodeValueOfObjCType: @encode(id) at: &sourceLinks];
[aCoder encodeValueOfObjCType: @encode(id) at: &destinationLinks];
[aCoder encodeValueOfObjCType: @encode(id) at: &_filename];
[aCoder encodeValueOfObjCType: @encode(id) at: &_sourceLinks];
[aCoder encodeValueOfObjCType: @encode(id) at: &_destinationLinks];
flag = _flags.areLinkOutlinesVisible;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _flags.delegateVerifiesLinks;
@ -379,13 +384,13 @@
id obj;
obj = [aCoder decodeObjectForKey: @"GSFilename"];
ASSIGN(filename,obj);
ASSIGN(_filename,obj);
obj = [aCoder decodeObjectForKey: @"GSSourceLinks"];
ASSIGN(sourceLinks,obj);
ASSIGN(_sourceLinks,obj);
obj = [aCoder decodeObjectForKey: @"GSDestinationLinks"];
ASSIGN(destinationLinks,obj);
flag = [aCoder decodeBoolForKey: @"GSAreLinkOutlinesVisible"];
ASSIGN(_destinationLinks,obj);
flag = [aCoder decodeBoolForKey: @"GSAreLinkOutlinesVisible"];
_flags.areLinkOutlinesVisible = flag;
flag = [aCoder decodeBoolForKey: @"GSDelegateVerifiesLinks"];
_flags.delegateVerifiesLinks = flag;
@ -400,11 +405,11 @@
if (version == 0)
{
BOOL flag = NO;
[aCoder decodeValueOfObjCType: @encode(id) at: &filename];
[aCoder decodeValueOfObjCType: @encode(id) at: &sourceLinks];
[aCoder decodeValueOfObjCType: @encode(id) at: &destinationLinks];
[aCoder decodeValueOfObjCType: @encode(id) at: &_filename];
[aCoder decodeValueOfObjCType: @encode(id) at: &_sourceLinks];
[aCoder decodeValueOfObjCType: @encode(id) at: &_destinationLinks];
[aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.areLinkOutlinesVisible = flag;
[aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag];