* Source/NSTextView.m: Rewrite

writeSelectionToPasteboard:... methods.
        Based on patch by Adam Fox <adam.fox@testplant.com>


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@38871 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2015-08-11 21:46:11 +00:00
parent 5568c3f60e
commit a3ca885ec8
2 changed files with 99 additions and 75 deletions

View file

@ -1,3 +1,14 @@
2015-08-11 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSTextView.m: Rewrite
writeSelectionToPasteboard:... methods.
Based on patch by Adam Fox <adam.fox@testplant.com>
2015-07-26 Riccardo Mottola <rm@gnu.org>
* Headers/AppKit/NSView.h,
* Source/NSView.m: Add alphaValue property.
2015-07-24 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSFont.m: Look for xib font property IBIsSystemFont.

View file

@ -2546,7 +2546,7 @@ Move to NSTextView_actions.m?
NSPasteboard *pb = [NSPasteboard pasteboardWithName: NSFontPboard];
[self writeSelectionToPasteboard: pb
type: NSFontPboardType];
types: [NSArray arrayWithObject: NSFontPboardType]];
}
/* Copy the current ruler settings to the ruler pasteboard */
@ -2555,7 +2555,7 @@ Move to NSTextView_actions.m?
NSPasteboard *pb = [NSPasteboard pasteboardWithName: NSRulerPboard];
[self writeSelectionToPasteboard: pb
type: NSRulerPboardType];
types: [NSArray arrayWithObject: NSRulerPboardType]];
}
@ -3171,21 +3171,36 @@ Scroll so that the beginning of the range is visible.
if ([self isEditable])
{
NSArray *types = nil;
NSPasteboard *pb = nil;
NSString *available;
if (sel_isEqual(action, @selector(paste:)))
types = [self readablePasteboardTypes];
{
types = [self readablePasteboardTypes];
pb = [NSPasteboard generalPasteboard];
}
else if (sel_isEqual(action, @selector(pasteAsPlainText:)))
types = [NSArray arrayWithObject: NSStringPboardType];
{
types = [NSArray arrayWithObject: NSStringPboardType];
pb = [NSPasteboard generalPasteboard];
}
else if (sel_isEqual(action, @selector(pasteAsRichText:)))
types = [NSArray arrayWithObject: NSRTFPboardType];
{
types = [NSArray arrayWithObject: NSRTFPboardType];
pb = [NSPasteboard generalPasteboard];
}
else if (sel_isEqual(action, @selector(pasteFont:)))
types = [NSArray arrayWithObject: NSFontPboardType];
{
types = [NSArray arrayWithObject: NSFontPboardType];
pb = [NSPasteboard pasteboardWithName: NSFontPboard];
}
else if (sel_isEqual(action, @selector(pasteRuler:)))
types = [NSArray arrayWithObject: NSRulerPboard];
{
types = [NSArray arrayWithObject: NSRulerPboard];
pb = [NSPasteboard pasteboardWithName: NSRulerPboard];
}
available = [[NSPasteboard generalPasteboard]
availableTypeFromArray: types];
available = [pb availableTypeFromArray: types];
return available != nil;
}
else
@ -5111,9 +5126,67 @@ support for writing new types of data to the pasteboard. You should invoke
super's implementation of the method to handle any types of data your
overridden version does not.
*/
BOOL ret = NO;
return [self writeSelectionToPasteboard: pboard
types: [NSArray arrayWithObject: type]];
if ([type isEqualToString: NSStringPboardType])
{
ret = [pboard setString: [[self string] substringWithRange: _layoutManager->_selected_range]
forType: NSStringPboardType] || ret;
}
else if ([type isEqualToString: NSRTFPboardType])
{
ret = [pboard setData: [self RTFFromRange: _layoutManager->_selected_range]
forType: NSRTFPboardType] || ret;
}
else if ([type isEqualToString: NSRTFDPboardType])
{
ret = [pboard setData: [self RTFDFromRange: _layoutManager->_selected_range]
forType: NSRTFDPboardType] || ret;
}
else if ([type isEqualToString: NSSmartPastePboardType] &&
[self selectionGranularity] == NSSelectByWord)
{
ret = [pboard setData: [NSData data]
forType: NSSmartPastePboardType] || ret;
}
else if ([type isEqualToString: NSColorPboardType])
{
NSColor *color;
color = [_textStorage attribute: NSForegroundColorAttributeName
atIndex: _layoutManager->_selected_range.location
effectiveRange: 0];
if (color != nil)
{
[color writeToPasteboard: pboard];
ret = YES;
}
}
else if ([type isEqualToString: NSFontPboardType])
{
NSDictionary *dict;
dict = [_textStorage fontAttributesInRange: _layoutManager->_selected_range];
if (dict != nil)
{
[pboard setData: [NSArchiver archivedDataWithRootObject: dict]
forType: NSFontPboardType];
ret = YES;
}
}
else if ([type isEqualToString: NSRulerPboardType])
{
NSDictionary *dict;
dict = [_textStorage rulerAttributesInRange: _layoutManager->_selected_range];
if (dict != nil)
{
[pboard setData: [NSArchiver archivedDataWithRootObject: dict]
forType: NSRulerPboardType];
ret = YES;
}
}
return ret;
}
- (BOOL) writeSelectionToPasteboard: (NSPasteboard *)pboard
@ -5146,70 +5219,10 @@ other than copy/paste or dragging. */
enumerator = [types objectEnumerator];
while ((type = [enumerator nextObject]) != nil)
{
if ([type isEqualToString: NSStringPboardType])
if ([self writeSelectionToPasteboard: pboard type: type])
{
ret = [pboard setString: [[self string] substringWithRange: _layoutManager->_selected_range]
forType: NSStringPboardType] || ret;
}
if ([type isEqualToString: NSRTFPboardType])
{
ret = [pboard setData: [self RTFFromRange: _layoutManager->_selected_range]
forType: NSRTFPboardType] || ret;
}
if ([type isEqualToString: NSRTFDPboardType])
{
ret = [pboard setData: [self RTFDFromRange: _layoutManager->_selected_range]
forType: NSRTFDPboardType] || ret;
}
if ([type isEqualToString: NSSmartPastePboardType] &&
[self selectionGranularity] == NSSelectByWord)
{
ret = [pboard setData: [NSData data]
forType: NSSmartPastePboardType] || ret;
}
if ([type isEqualToString: NSColorPboardType])
{
NSColor *color;
color = [_textStorage attribute: NSForegroundColorAttributeName
atIndex: _layoutManager->_selected_range.location
effectiveRange: 0];
if (color != nil)
{
[color writeToPasteboard: pboard];
ret = YES;
}
}
if ([type isEqualToString: NSFontPboardType])
{
NSDictionary *dict;
dict = [_textStorage fontAttributesInRange: _layoutManager->_selected_range];
if (dict != nil)
{
[pboard setData: [NSArchiver archivedDataWithRootObject: dict]
forType: NSFontPboardType];
ret = YES;
}
}
if ([type isEqualToString: NSRulerPboardType])
{
NSDictionary *dict;
dict = [_textStorage rulerAttributesInRange: _layoutManager->_selected_range];
if (dict != nil)
{
[pboard setData: [NSArchiver archivedDataWithRootObject: dict]
forType: NSRulerPboardType];
ret = YES;
}
}
ret = YES;
}
}
return ret;
@ -6210,7 +6223,7 @@ or add guards
[self writeSelectionToPasteboard:
[NSPasteboard pasteboardWithName: @"Selection"]
type: NSStringPboardType];
types: [NSArray arrayWithObject: NSStringPboardType]];
}
/** Extension method that pastes the current selected text from the