| 1 |
#import "ComposeController.h" |
| 2 |
#import "ComposeToolbarSource.h" |
| 3 |
#import "AddressBookController.h" |
| 4 |
#import "MailTextFormatManager.h" |
| 5 |
|
| 6 |
static const int DIALOG_OK = 128; |
| 7 |
static const int DIALOG_CANCEL = 129; |
| 8 |
|
| 9 |
@implementation ComposeController |
| 10 |
-(id)init{ |
| 11 |
NSToolbar *toolbar; |
| 12 |
ComposeToolbarSource *composeToolbarSource; |
| 13 |
|
| 14 |
[super initWithWindowNibName:@"Compose"]; |
| 15 |
toolbar = [[NSToolbar alloc] initWithIdentifier:@"ComposeToolBar"]; |
| 16 |
composeToolbarSource = [[ComposeToolbarSource alloc] initWithController:self]; |
| 17 |
[toolbar setDelegate:composeToolbarSource]; |
| 18 |
[[self window] setToolbar:toolbar]; |
| 19 |
[toolbar release]; |
| 20 |
return self; |
| 21 |
} |
| 22 |
-(void)windowDidLoad{ |
| 23 |
NSLog(@"window did load nib!"); |
| 24 |
[[contents textStorage] setDelegate:self]; |
| 25 |
|
| 26 |
} |
| 27 |
-(void)createNewMessageWithHeader:(NSDictionary *)headers contents:(NSString *)contents{ |
| 28 |
[[self window] setDelegate:self]; |
| 29 |
[self showWindow:self]; |
| 30 |
} |
| 31 |
-(id)showAddressBook:(id)sender{ |
| 32 |
if(addressBookController){ |
| 33 |
[addressBookController showAddressBookWindow]; |
| 34 |
} |
| 35 |
return self; |
| 36 |
} |
| 37 |
-(void)setAddressBookController:(AddressBookController *)controller{ |
| 38 |
if(!addressBookController){ |
| 39 |
[addressBookController release]; |
| 40 |
} |
| 41 |
addressBookController = controller; |
| 42 |
[addressBookController retain]; |
| 43 |
// ��������������������������������������������������� |
| 44 |
[toPopupButton setMenu:[addressBookController createAddressMenu:self |
| 45 |
action:@selector(addTo:) |
| 46 |
title:@"To: "]]; |
| 47 |
[ccPopupButton setMenu:[addressBookController createAddressMenu:self |
| 48 |
action:@selector(addCc:) |
| 49 |
title:@"Cc: "]]; |
| 50 |
[bccPopupButton setMenu:[addressBookController createAddressMenu:self |
| 51 |
action:@selector(addBcc:) |
| 52 |
title:@"Bcc: "]]; |
| 53 |
} |
| 54 |
- (void)addText:(NSString *)text toTextField:(NSTextField *)textField{ |
| 55 |
NSString *fieldString; |
| 56 |
if([textField stringValue] == nil || [[textField stringValue] isEqual:@""]){ |
| 57 |
fieldString = text; |
| 58 |
}else{ |
| 59 |
fieldString = [NSString stringWithFormat:@"%@ , %@", |
| 60 |
[textField stringValue], |
| 61 |
text]; |
| 62 |
} |
| 63 |
[textField setStringValue:fieldString]; |
| 64 |
} |
| 65 |
- (IBAction)addTo:(id)sender{ |
| 66 |
[self addText:[sender title] toTextField:toTextField]; |
| 67 |
} |
| 68 |
- (IBAction)addCc:(id)sender{ |
| 69 |
[self addText:[sender title] toTextField:ccTextField]; |
| 70 |
} |
| 71 |
- (IBAction)addBcc:(id)sender{ |
| 72 |
[self addText:[sender title] toTextField:bccTextField]; |
| 73 |
} |
| 74 |
// ���������������TextView���TextStorage���delegate |
| 75 |
- (void)textStorageDidProcessEditing:(NSNotification *)aNotification{ |
| 76 |
|
| 77 |
// ������������������������������������������������������������������������������������������������������ |
| 78 |
NSRange range; |
| 79 |
NSTextStorage *storage; |
| 80 |
MailTextFormatManager *formatManager; |
| 81 |
storage = [aNotification object]; |
| 82 |
formatManager = [MailTextFormatManager sharedMailTextFormatManager]; |
| 83 |
// range = NSMakeRange(0, NSMaxRange([storage editedRange])); |
| 84 |
// range = NSMakeRange([storage editedRange].location, |
| 85 |
// [storage length] - [storage editedRange].location); |
| 86 |
range = NSMakeRange(0, [storage length]); |
| 87 |
[storage replaceCharactersInRange:range |
| 88 |
withAttributedString:[formatManager formatContents: |
| 89 |
[[storage string] substringWithRange:range]]]; |
| 90 |
} |
| 91 |
|
| 92 |
// ���������������������Sheet��������������������� |
| 93 |
- (IBAction)showSheet:(id)sender |
| 94 |
{ |
| 95 |
// Display sheet dialog |
| 96 |
[[NSApplication sharedApplication] beginSheet:_sheetDialog modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:nil]; |
| 97 |
} |
| 98 |
- (void)sheetDidEnd:(NSWindow*)sheet returnCode:(int)returnCode contextInfo:(void*)contextInfo |
| 99 |
{ |
| 100 |
[_sheetDialog orderOut:self]; |
| 101 |
|
| 102 |
// Check return code |
| 103 |
if(returnCode == DIALOG_CANCEL) { |
| 104 |
// Cancel button was pushed |
| 105 |
return; |
| 106 |
} |
| 107 |
else if(returnCode == DIALOG_OK) { |
| 108 |
// OK button was pushed |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
- (IBAction)sheetOk:(id)sender |
| 113 |
{ |
| 114 |
// OK button is pushed |
| 115 |
[[NSApplication sharedApplication] endSheet:_sheetDialog returnCode:DIALOG_OK]; |
| 116 |
} |
| 117 |
|
| 118 |
- (IBAction)sheetCancel:(id)sender |
| 119 |
{ |
| 120 |
// Cancel button is pushed |
| 121 |
[[NSApplication sharedApplication] endSheet:_sheetDialog returnCode:DIALOG_CANCEL]; |
| 122 |
} |
| 123 |
|
| 124 |
@end |