Adium

Changeset 16240

Show
Ignore:
Timestamp:
06/15/2006 02:32:11 PM (2 years ago)
Author:
evands
Message:
  • Paste now leaves bold/italics/underline/font/size etc. but strips colors, alignment, images, etc.
  • Added a new paste item, Paste with Colors and Images, which does a traditional paste with rich text operation.

Closes #2880

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Frameworks/Adium Framework/AIMessageEntryTextView.m

    r15751 r16240  
    5757- (void)addAttachmentOfImage:(NSImage *)inImage; 
    5858- (void)addAttachmentsFromPasteboard:(NSPasteboard *)pasteboard; 
     59@end 
     60 
     61@interface NSMutableAttributedString (AIMessageEntryTextViewAdditions) 
     62- (void)convertForPasteWithTraits; 
    5963@end 
    6064 
     
    371375} 
    372376 
    373 - (BOOL)handledPasteAsRichText 
     377#pragma mark Pasting 
     378 
     379- (BOOL)handlePasteAsRichText 
    374380{ 
    375381        NSPasteboard *generalPasteboard = [NSPasteboard generalPasteboard]; 
     
    404410        NSDictionary    *attributes = [[self typingAttributes] copy]; 
    405411 
    406         if (![self handledPasteAsRichText]) { 
     412        if (![self handlePasteAsRichText]) { 
    407413                [super paste:sender]; 
    408414        } 
     
    414420        [attributes release]; 
    415421} 
     422 
     423- (void)pasteAsPlainTextWithTraits:(id)sender 
     424{ 
     425        NSDictionary    *attributes = [[self typingAttributes] copy]; 
     426         
     427        NSPasteboard *generalPasteboard = [NSPasteboard generalPasteboard]; 
     428        NSEnumerator *enumerator = [[generalPasteboard types] objectEnumerator]; 
     429        NSString         *type; 
     430        BOOL             handledPaste = NO; 
     431         
     432        //Types is ordered by the preference for handling of the data; enumerating it lets us allow the sending application's hints to be followed. 
     433        while ((type = [enumerator nextObject]) && !handledPaste) { 
     434                NSLog(@"Looking at type %@",type); 
     435                if ([type isEqualToString:NSRTFPboardType] || 
     436                        [type isEqualToString:NSRTFDPboardType] || 
     437                        [type isEqualToString:NSHTMLPboardType]) { 
     438                        NSData *data = [generalPasteboard dataForType:type]; 
     439                        NSMutableAttributedString *attributedString; 
     440                         
     441                        if ([type isEqualToString:NSRTFPboardType]) { 
     442                                attributedString = [[NSMutableAttributedString alloc] initWithRTF:data 
     443                                                                                                                           documentAttributes:NULL]; 
     444                        } else if ([type isEqualToString:NSRTFDPboardType]) { 
     445                                attributedString = [[NSMutableAttributedString alloc] initWithRTFD:data 
     446                                                                                                                                documentAttributes:NULL]; 
     447                        } else /* NSHTMLPboardType */ { 
     448                                attributedString = [[NSMutableAttributedString alloc] initWithHTML:data 
     449                                                                                                                                documentAttributes:NULL]; 
     450                        } 
     451 
     452                        [attributedString convertForPasteWithTraits]; 
     453                        [[self textStorage] replaceCharactersInRange:[self selectedRange] 
     454                                                                        withAttributedString:attributedString]; 
     455                        [attributedString release]; 
     456                         
     457                        handledPaste = YES; 
     458                         
     459                } else if ([type isEqualToString:NSStringPboardType]) { 
     460                        //Paste a plain text string directly 
     461                        [super paste:sender]; 
     462                        handledPaste = YES; 
     463                         
     464                } else if ([type isEqualToString:NSFilenamesPboardType]) { 
     465                        [self addAttachmentsFromPasteboard:generalPasteboard]; 
     466                        handledPaste = YES; 
     467 
     468                } else if ([type isEqualToString:NSURLPboardType]) { 
     469                        //Paste a URL directly 
     470                        [super paste:sender]; 
     471                        handledPaste = YES; 
     472                } 
     473        } 
     474         
     475        //If we didn't handle it yet, let super try to deal with it 
     476        if (!handledPaste) { 
     477                [super paste:sender]; 
     478        } 
     479         
     480        if (attributes) { 
     481                [self setTypingAttributes:attributes]; 
     482        } 
     483         
     484        [attributes release];    
     485} 
     486 
     487#pragma mark Deletion 
    416488 
    417489- (void)deleteBackward:(id)sender 
     
    10041076 
    10051077@end 
     1078 
     1079@implementation NSMutableAttributedString (AIMessageEntryTextViewAdditions) 
     1080- (void)convertForPasteWithTraits 
     1081{ 
     1082        NSRange fullRange = NSMakeRange(0, [self length]); 
     1083         
     1084        //Remove non-trait attributes 
     1085        [self removeAttribute:NSBackgroundColorAttributeName range:fullRange]; 
     1086        [self removeAttribute:NSBaselineOffsetAttributeName range:fullRange]; 
     1087        [self removeAttribute:NSCursorAttributeName range:fullRange]; 
     1088        [self removeAttribute:NSExpansionAttributeName range:fullRange]; 
     1089        [self removeAttribute:NSForegroundColorAttributeName range:fullRange]; 
     1090        [self removeAttribute:NSKernAttributeName range:fullRange]; 
     1091        [self removeAttribute:NSLigatureAttributeName range:fullRange]; 
     1092        [self removeAttribute:NSObliquenessAttributeName range:fullRange]; 
     1093        [self removeAttribute:NSParagraphStyleAttributeName range:fullRange]; 
     1094        [self removeAttribute:NSShadowAttributeName range:fullRange]; 
     1095        [self removeAttribute:NSStrokeWidthAttributeName range:fullRange]; 
     1096         
     1097        //Replace attachments with nothing! Absolutely nothing! 
     1098        [self convertAttachmentsToStringsUsingPlaceholder:@""]; 
     1099} 
     1100@end 
  • trunk/Resources/MainMenu.nib/classes.nib

    r16194 r16240  
    3030                paste = id;  
    3131                pasteAndMatchStyle = id;  
     32                pasteWithImagesAndColors = id;  
    3233                previousMessage = id;  
    3334                runToolbarCustomizationPalette = id;  
     
    103104                "menuItem_pasteAndMatchStyle" = NSMenuItem;  
    104105                "menuItem_pasteStyle" = NSMenuItem;  
     106                "menuItem_pasteWithImagesAndColors" = NSMenuItem;  
    105107                "menuItem_preferences" = NSMenuItem;  
    106108                "menuItem_print" = NSMenuItem;  
  • trunk/Source/AIInterfaceController.h

    r16222 r16240  
    253253- (IBAction)paste:(id)sender; 
    254254- (IBAction)pasteAndMatchStyle:(id)sender; 
     255- (IBAction)pasteWithImagesAndColors:(id)sender; 
    255256 
    256257//Custom printing 
  • trunk/Source/AIInterfaceController.m

    r16221 r16240  
    12231223- (IBAction)paste:(id)sender 
    12241224{ 
    1225         [self _pasteWithPreferredSelector:@selector(pasteAsRichText:) sender:sender]; 
     1225        [self _pasteWithPreferredSelector:@selector(pasteAsPlainTextWithTraits:) sender:sender]; 
    12261226} 
    12271227 
     
    12301230{ 
    12311231        [self _pasteWithPreferredSelector:@selector(pasteAsPlainText:) sender:sender]; 
     1232} 
     1233 
     1234- (IBAction)pasteWithImagesAndColors:(id)sender 
     1235{ 
     1236        [self _pasteWithPreferredSelector:@selector(pasteAsRichText:) sender:sender];    
    12321237} 
    12331238 
  • trunk/Source/AIMenuController.h

    r15752 r16240  
    118118        IBOutlet        NSMenuItem      *menuItem_copy; 
    119119        IBOutlet        NSMenuItem      *menuItem_paste; 
     120        IBOutlet        NSMenuItem      *menuItem_pasteWithImagesAndColors; 
    120121        IBOutlet        NSMenuItem      *menuItem_pasteAndMatchStyle; 
    121122        IBOutlet        NSMenuItem      *menuItem_clear; 
  • trunk/Source/AIMenuController.m

    r15752 r16240  
    340340        [menuItem_copy setTitle:AILocalizedString(@"Copy",nil)]; 
    341341        [menuItem_paste setTitle:AILocalizedString(@"Paste",nil)]; 
     342        [menuItem_pasteWithImagesAndColors setTitle:AILocalizedString(@"Paste with Images and Colors",nil)]; 
    342343        [menuItem_pasteAndMatchStyle setTitle:AILocalizedString(@"Paste and Match Style",nil)]; 
    343344        [menuItem_clear setTitle:AILocalizedString(@"Clear",nil)];