More data link implementation details.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@20850 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2005-03-05 15:50:32 +00:00
parent 288beea76f
commit 45f40695b6
8 changed files with 329 additions and 93 deletions

View file

@ -1,3 +1,15 @@
2005-03-05 10:53 Gregory John Casamento <greg_casamento@yahoo.com>
* Headers/AppKit/NSDataLink.h
* Headers/AppKit/NSDataLinkManager.h: Added some ivars
* Source/Functions.m: Changed the NSLinkFrameThickness() function to
return 1 instead of 1.5.
* Source/NSDataLink.m: Implemented several methods.
* Source/NSDataLinkManager.m: Implemented several methods.
* Source/NSDataLinkPanel.m: Change version from 1 to 0.
* Source/NSSelection.m: Change version from 1 to 0, corrected
but in initWithCoder:.
2005-03-03 Adam Fedor <fedor@gnu.org>
* configure.ac: Disable gsnd on darwin

View file

@ -65,19 +65,32 @@ APPKIT_EXPORT NSString *NSDataLinkFileNameExtension;
NSDataLinkNumber linkNumber;
NSDataLinkDisposition disposition;
NSDataLinkUpdateMode updateMode;
NSDataLinkManager *manager;
// info about the source.
NSDate *lastUpdateTime;
NSString *sourceApplicationName;
NSString *sourceFilename;
NSSelection *sourceSelection;
NSArray *types;
NSDate *lastUpdateTime;
NSString *sourceApplicationName;
NSString *sourceFilename;
NSSelection *sourceSelection;
id sourceManager;
// info about the destination
NSString *destinationApplicationName;
NSString *destinationFilename;
NSSelection *destinationSelection;
NSString *destinationApplicationName;
NSString *destinationFilename;
NSSelection *destinationSelection;
id destinationManager;
// types.
NSArray *types;
// other flags
struct __linkFlags {
unsigned appVerifies:1;
unsigned broken:1;
unsigned canUpdateContinuously:1;
unsigned isDirty:1;
unsigned willOpenSource:1;
unsigned willUpdate:1;
} _flags;
}
//
@ -131,5 +144,8 @@ APPKIT_EXPORT NSString *NSDataLinkFileNameExtension;
- (NSDataLinkUpdateMode)updateMode;
@end
APPKIT_EXPORT NSString *NSDataLinkFilenameExtension;
APPKIT_EXPORT NSString *NSDataLinkPboardType;
#endif // _GNUstep_H_NSDataLink

View file

@ -33,7 +33,7 @@
@class NSString;
@class NSEnumerator;
@class NSMutableDictionary;
@class NSMutableArray;
@class NSDataLink;
@class NSSelection;
@class NSPasteboard;
@ -44,12 +44,16 @@
// Attributes
id delegate;
NSString *filename;
BOOL delegateVerifiesLinks;
BOOL interactsWithUser;
BOOL isEdited;
BOOL areLinkOutlinesVisible;
NSMutableDictionary *sourceLinks;
NSMutableDictionary *destinationLinks;
NSMutableArray *sourceLinks;
NSMutableArray *destinationLinks;
struct __dlmFlags {
unsigned areLinkOutlinesVisible:1;
unsigned delegateVerifiesLinks:1;
unsigned interactsWithUser:1;
unsigned isEdited:1;
} _flags;
}
//
@ -108,9 +112,7 @@
// Methods Implemented by the Delegate
//
@interface NSObject (NSDataLinkManagerDelegate)
- (BOOL)copyToPasteboard:(NSPasteboard *)pasteboard
at:(NSSelection *)selection
cheapCopyAllowed:(BOOL)flag;
// data link management methods.
- (void)dataLinkManager:(NSDataLinkManager *)sender
didBreakLink:(NSDataLink *)link;
- (BOOL)dataLinkManager:(NSDataLinkManager *)sender
@ -123,6 +125,11 @@
- (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

View file

@ -779,7 +779,7 @@ NSDrawWindowBackground(NSRect aRect)
float
NSLinkFrameThickness(void)
{
return 1.5;
return 1;
}
void

View file

@ -1,7 +1,9 @@
/** <title>NSDataLink</title>
Copyright (C) 1996 Free Software Foundation, Inc.
Copyright (C) 1996, 2005 Free Software Foundation, Inc.
Author: Gregory John Casamento <greg_casamento@yahoo.com>
Date: 2005
Author: Scott Christley <scottc@net-community.com>
Date: 1996
@ -24,29 +26,17 @@
*/
#include "config.h"
#include <Foundation/NSFileManager.h>
#include <Foundation/NSArchiver.h>
#include <Foundation/NSData.h>
#include "AppKit/NSDataLink.h"
#include "AppKit/NSDataLinkManager.h"
#include "AppKit/NSPasteboard.h"
#include "AppKit/NSSavePanel.h"
#include "AppKit/NSSelection.h"
@interface NSDataLink (Private)
- (void) setLastUpdateTime: (NSDate *)date;
- (void) setSourceFilename: (NSString *)src;
- (void) setDestinationFilename: (NSString *)src;
@end
@implementation NSDataLink (Private)
- (void) setLastUpdateTime: (NSDate *)date
{
ASSIGN(lastUpdateTime, date);
}
- (void) setSourceFilename: (NSString *)src
{
ASSIGN(sourceFilename,src);
}
- (void) setDestinationFilename: (NSString *)dst
{
ASSIGN(destinationFilename, dst);
}
@end
// constants
NSString *NSDataLinkFilenameExtension = @"dlink";
@implementation NSDataLink
@ -58,7 +48,7 @@
if (self == [NSDataLink class])
{
// Initial version
[self setVersion: 1];
[self setVersion: 0];
}
}
@ -70,6 +60,12 @@
//
- (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);
}
return nil;
}
@ -80,7 +76,7 @@
if((self = [self init]) != nil)
{
ASSIGN(sourceSelection,selection);
ASSIGN(manager,linkManager);
ASSIGN(sourceManager,linkManager);
ASSIGN(types,newTypes);
}
return self;
@ -88,12 +84,18 @@
- (id)initWithContentsOfFile:(NSString *)filename
{
return nil;
NSData *data = AUTORELEASE([[NSData alloc] initWithContentsOfFile: filename]);
id object = [NSUnarchiver unarchiveObjectWithData: data];
RELEASE(self);
return object;
}
- (id)initWithPasteboard:(NSPasteboard *)pasteboard
{
return nil;
NSData *data = [pasteboard dataForType: NSDataLinkPboardType];
id object = [NSUnarchiver unarchiveObjectWithData: data];
RELEASE(self);
return object;
}
//
@ -101,16 +103,48 @@
//
- (BOOL)saveLinkIn:(NSString *)directoryName
{
NSSavePanel *sp;
int result;
sp = [NSSavePanel savePanel];
[sp setRequiredFileType: NSDataLinkFilenameExtension];
result = [sp runModalForDirectory: directoryName file: @""];
if (result == NSOKButton)
{
NSFileManager *mgr = [NSFileManager defaultManager];
NSString *path = [sp filename];
if ([mgr fileExistsAtPath: path] == YES)
{
/* 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];
}
// save it.
return [self writeToFile: path];
}
return NO;
}
- (BOOL)writeToFile:(NSString *)filename
{
return NO;
NSString *path = filename;
if([[path pathExtension] isEqual: NSDataLinkFilenameExtension] == NO)
{
path = [filename stringByAppendingPathExtension: NSDataLinkFilenameExtension];
}
return [NSArchiver archiveRootObject: self toFile: path];
}
- (void)writeToPasteboard:(NSPasteboard *)pasteboard
{
NSData *data = [NSArchiver archivedDataWithRootObject: self];
[pasteboard setData: data forType: NSDataLinkPboardType];
}
//
@ -128,7 +162,7 @@
- (NSDataLinkManager *)manager
{
return manager;
return sourceManager;
}
//
@ -187,11 +221,34 @@
//
- (BOOL)break
{
return NO;
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
// always returns YES.
if([srcDelegate respondsToSelector: @selector(dataLinkManager:didBreakLink:)])
{
[srcDelegate dataLinkManager: sourceManager didBreakLink: self];
}
if([dstDelegate respondsToSelector: @selector(dataLinkManager:didBreakLink:)])
{
[dstDelegate dataLinkManager: destinationManager didBreakLink: self];
}
return (_flags.broken = YES);
}
- (void)noteSourceEdited
{
_flags.isDirty = YES;
if(updateMode != NSUpdateNever)
{
[sourceManager noteDocumentEdited];
}
}
- (void)setUpdateMode:(NSDataLinkUpdateMode)mode
@ -214,42 +271,80 @@
//
- (void) encodeWithCoder: (NSCoder*)aCoder
{
BOOL flag = NO;
[aCoder encodeValueOfObjCType: @encode(int) at: &linkNumber];
[aCoder encodeValueOfObjCType: @encode(int) at: &disposition];
[aCoder encodeValueOfObjCType: @encode(int) at: &updateMode];
[aCoder encodeValueOfObjCType: @encode(id) at: &manager];
[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: &types];
[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];
flag = _flags.canUpdateContinuously;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _flags.isDirty;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _flags.willOpenSource;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _flags.willUpdate;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
}
- (id) initWithCoder: (NSCoder*)aCoder
{
int version = [aCoder versionForClassName: @"NSDataLink"];
if(version == 1)
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: &manager];
[aCoder decodeValueOfObjCType: @encode(id) at: &sourceManager];
[aCoder encodeValueOfObjCType: @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: &types];
[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;
[aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.canUpdateContinuously = flag;
[aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.isDirty = flag;
[aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.willOpenSource = flag;
[aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.willUpdate = flag;
}
else
{
NSLog(@"No decoder for NSDataLink version #%d",version);
return nil;
}
return self;

View file

@ -1,7 +1,9 @@
/** <title>NSDataLinkManager</title>
Copyright (C) 1996 Free Software Foundation, Inc.
Copyright (C) 1996, 2005 Free Software Foundation, Inc.
Author: Gregory John Casamento <greg_casamento@yahoo.com>
Date: 2005
Author: Scott Christley <scottc@net-community.com>
Date: 1996
@ -26,9 +28,58 @@
#include "config.h"
#include <Foundation/NSDictionary.h>
#include <Foundation/NSEnumerator.h>
#include <Foundation/NSArray.h>
#include <AppKit/NSDataLinkManager.h>
#include <AppKit/NSDataLink.h>
@interface NSDataLink (Private)
- (void) setLastUpdateTime: (NSDate *)date;
- (void) setSourceFilename: (NSString *)src;
- (void) setDestinationFilename: (NSString *)dst;
- (void) setSourceManager: (id)src;
- (void) setDestinationManager: (id)dst;
- (void) setSourceSelection: (id)src;
- (void) setDestinationSelection: (id)dst;
@end
@implementation NSDataLink (Private)
- (void) setLastUpdateTime: (NSDate *)date
{
ASSIGN(lastUpdateTime, date);
}
- (void) setSourceFilename: (NSString *)src
{
ASSIGN(sourceFilename,src);
}
- (void) setDestinationFilename: (NSString *)dst
{
ASSIGN(destinationFilename, dst);
}
- (void) setSourceManager: (id)src
{
ASSIGN(sourceManager,src);
}
- (void) setDestinationManager: (id)dst
{
ASSIGN(destinationManager,dst);
}
- (void) setSourceSelection: (id)src
{
ASSIGN(sourceSelection,src);
}
- (void) setDestinationSelection: (id)dst
{
ASSIGN(destinationSelection,dst);
}
@end
@implementation NSDataLinkManager
//
@ -39,7 +90,7 @@
if (self == [NSDataLinkManager class])
{
// Initial version
[self setVersion:1];
[self setVersion: 0];
}
}
@ -53,12 +104,15 @@
{
self = [super init];
ASSIGN(delegate,anObject);
filename = nil;
delegateVerifiesLinks = NO;
interactsWithUser = NO;
isEdited = NO;
areLinkOutlinesVisible = NO;
if(self != nil)
{
ASSIGN(delegate,anObject);
filename = nil;
_flags.delegateVerifiesLinks = NO;
_flags.interactsWithUser = NO;
_flags.isEdited = NO;
_flags.areLinkOutlinesVisible = NO;
}
return self;
}
@ -68,12 +122,15 @@
{
self = [super init];
ASSIGN(delegate,anObject);
ASSIGN(filename,path);
delegateVerifiesLinks = NO;
interactsWithUser = NO;
isEdited = NO;
areLinkOutlinesVisible = NO;
if(self != nil)
{
ASSIGN(delegate,anObject);
ASSIGN(filename,path);
_flags.delegateVerifiesLinks = NO;
_flags.interactsWithUser = NO;
_flags.isEdited = NO;
_flags.areLinkOutlinesVisible = NO;
}
return self;
}
@ -84,7 +141,18 @@
- (BOOL)addLink:(NSDataLink *)link
at:(NSSelection *)selection
{
return NO;
BOOL result = NO;
[link setDestinationSelection: selection];
[link setDestinationManager: self];
if([destinationLinks containsObject: link] == NO)
{
[destinationLinks addObject: link];
result = YES;
}
return result;
}
- (BOOL)addLinkAsMarker:(NSDataLink *)link
@ -102,23 +170,26 @@
- (void)breakAllLinks
{
NSEnumerator *en = [self destinationLinkEnumerator];
NSArray *allLinks = [sourceLinks arrayByAddingObjectsFromArray: destinationLinks];
NSEnumerator *en = [allLinks objectEnumerator];
id obj = nil;
while((obj = [en nextObject]) != nil)
{
[obj break];
}
en = [self sourceLinkEnumerator];
while((obj = [en nextObject]) != nil)
{
[obj break];
}
}
- (void)writeLinksToPasteboard:(NSPasteboard *)pasteboard
{
NSArray *allLinks = [sourceLinks arrayByAddingObjectsFromArray: destinationLinks];
NSEnumerator *en = [allLinks objectEnumerator];
id obj = nil;
while((obj = [en nextObject]) != nil)
{
[obj writeToPasteboard: pasteboard];
}
}
//
@ -158,7 +229,7 @@
- (BOOL)delegateVerifiesLinks
{
return delegateVerifiesLinks;
return _flags.delegateVerifiesLinks;
}
- (NSString *)filename
@ -168,22 +239,22 @@
- (BOOL)interactsWithUser
{
return interactsWithUser;
return _flags.interactsWithUser;
}
- (BOOL)isEdited
{
return isEdited;
return _flags.isEdited;
}
- (void)setDelegateVerifiesLinks:(BOOL)flag
{
delegateVerifiesLinks = flag;
_flags.delegateVerifiesLinks = flag;
}
- (void)setInteractsWithUser:(BOOL)flag
{
interactsWithUser = flag;
_flags.interactsWithUser = flag;
}
//
@ -191,12 +262,12 @@
//
- (BOOL)areLinkOutlinesVisible
{
return areLinkOutlinesVisible;
return _flags.areLinkOutlinesVisible;
}
- (NSEnumerator *)destinationLinkEnumerator
{
return [destinationLinks keyEnumerator];
return [destinationLinks objectEnumerator];
}
- (NSDataLink *)destinationLinkWithSelection:(NSSelection *)destSel
@ -217,12 +288,12 @@
- (void)setLinkOutlinesVisible:(BOOL)flag
{
areLinkOutlinesVisible = flag;
_flags.areLinkOutlinesVisible = flag;
}
- (NSEnumerator *)sourceLinkEnumerator
{
return [sourceLinks keyEnumerator];
return [sourceLinks objectEnumerator];
}
//
@ -230,10 +301,48 @@
//
- (void) encodeWithCoder: (NSCoder*)aCoder
{
BOOL flag = NO;
[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;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _flags.interactsWithUser;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _flags.isEdited;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
}
- (id) initWithCoder: (NSCoder*)aDecoder
- (id) initWithCoder: (NSCoder*)aCoder
{
int version = [aCoder versionForClassName: @"NSDataLinkManager"];
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(BOOL) at: &flag];
_flags.areLinkOutlinesVisible = flag;
[aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.delegateVerifiesLinks = flag;
[aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.interactsWithUser = flag;
[aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.isEdited = flag;
}
else
{
return nil;
}
return self;
}

View file

@ -104,7 +104,7 @@ static NSDataLinkPanel *_sharedDataLinkPanel;
if (self == [NSDataLinkPanel class])
{
// Initial version
[self setVersion:1];
[self setVersion: 0];
}
}

View file

@ -96,7 +96,7 @@ typedef enum
if (self == [NSSelection class])
{
// Initial version
[self setVersion:1];
[self setVersion: 0];
}
}
@ -226,6 +226,8 @@ typedef enum
at: &_isWellKnownSelection];
[aDecoder decodeValueOfObjCType: @encode(int)
at: &_selectionType];
[aDecoder decodeValueOfObjCType: @encode(id)
at: _descriptionData];
// if it's a well known selection then determine which one it is.
if(_isWellKnownSelection)
@ -249,11 +251,6 @@ typedef enum
break;
}
}
else
{
[aDecoder decodeValueOfObjCType: @encode(id)
at: _descriptionData];
}
return self;
}