| 1 |
#import "MainController.h" |
| 2 |
#import "MailBoxOutlineDataSource.h" |
| 3 |
#import "MainToolbarSource.h" |
| 4 |
#import "IconedCell.h" |
| 5 |
#import "ComposeToolbarSource.h" |
| 6 |
#import "PreferenceController.h" |
| 7 |
#import "DUMMailBoxManager.h" |
| 8 |
#import "MailBoxTableDataSource.h" |
| 9 |
#import "DUMMail.h" |
| 10 |
#import "DUMMailBox.h" |
| 11 |
#import "AddressBookController.h" |
| 12 |
#import "ComposeController.h" |
| 13 |
#import "TextFormatter.h" |
| 14 |
#import "LineTextFormatter.h" |
| 15 |
#import "MailTextFormatManager.h" |
| 16 |
#import "AttachmentBrowserDelegate.h" |
| 17 |
|
| 18 |
@implementation MainController |
| 19 |
-(void)setupToolbar{ |
| 20 |
NSToolbar *toolbar; |
| 21 |
MainToolbarSource *mainToolbarSource; |
| 22 |
toolbar = [[NSToolbar alloc] initWithIdentifier:@"MainToolBar"]; |
| 23 |
mainToolbarSource = [[MainToolbarSource alloc] initWithController:self]; |
| 24 |
[toolbar setDelegate:mainToolbarSource]; |
| 25 |
[window setToolbar:toolbar]; |
| 26 |
[toolbar release]; |
| 27 |
|
| 28 |
} |
| 29 |
-(void)awakeFromNib{ |
| 30 |
MailBoxOutlineDataSource *ds; |
| 31 |
|
| 32 |
[window center]; |
| 33 |
mailBoxManager = [[DUMMailBoxManager alloc] init]; |
| 34 |
ds = [[MailBoxOutlineDataSource alloc] |
| 35 |
initWithMailBoxManager:mailBoxManager]; |
| 36 |
[folderTree setDataSource:ds]; |
| 37 |
[self setupToolbar]; |
| 38 |
composeControllers = [[NSMutableArray alloc] init]; |
| 39 |
myAddressBookController = [[self createAddressBookController] retain]; |
| 40 |
[myAddressBookController setWindowController:self]; |
| 41 |
|
| 42 |
[[mailContents textStorage] setDelegate:self]; |
| 43 |
mailTextFormatManager = [[MailTextFormatManager sharedMailTextFormatManager] retain]; |
| 44 |
|
| 45 |
attachmentBrowserDelegate |
| 46 |
= [[AttachmentBrowserDelegate alloc] initWithBrowser:attachmentBrowser]; |
| 47 |
[attachmentBrowserDelegate setBrowserElements: |
| 48 |
[NSArray arrayWithObjects:@"abc", @"def", @"ghi", @"jkl", nil]]; |
| 49 |
[attachmentBrowser setDelegate:attachmentBrowserDelegate]; |
| 50 |
|
| 51 |
[drawer setContentView:attachmentView]; |
| 52 |
|
| 53 |
} |
| 54 |
-(void)dealloc{ |
| 55 |
[window release]; |
| 56 |
[searchWindow release]; |
| 57 |
[mailList release]; |
| 58 |
[folderTree release]; |
| 59 |
[mailContents release]; |
| 60 |
[mailBoxManager release]; |
| 61 |
[prefController release]; |
| 62 |
[myAddressBookController release]; |
| 63 |
[mailTextFormatManager release]; |
| 64 |
[super dealloc]; |
| 65 |
} |
| 66 |
// ���C���E�B���h�E��NSWindowController�������O�������[�u |
| 67 |
-(NSWindow *)window{ |
| 68 |
return window; |
| 69 |
} |
| 70 |
-(BOOL)windowShouldClose:(id)sender{ |
| 71 |
[composeControllers removeObject:[sender windowController]]; |
| 72 |
return YES; |
| 73 |
} |
| 74 |
- (void)applicationDidFinishLaunching:(NSNotification*)notif |
| 75 |
{ |
| 76 |
NSTableColumn* tableColumn; |
| 77 |
IconedCell* iconedCell; |
| 78 |
|
| 79 |
// �t�H���_�c���[���A�A�C�R��+�������\���������������ACell�����X���s���B |
| 80 |
// HMDT���Q�l�������������Bf |
| 81 |
tableColumn = [folderTree tableColumnWithIdentifier:@"folderview"]; |
| 82 |
iconedCell = [[[IconedCell alloc] init] autorelease]; |
| 83 |
[tableColumn setDataCell:iconedCell]; |
| 84 |
} |
| 85 |
|
| 86 |
// �V�K���b�Z�[�W�����E�B���h�E���\�������B |
| 87 |
-(IBAction)createNewMessage:(id)sender{ |
| 88 |
AddressBookController *anAddressBookController = [self createAddressBookController]; |
| 89 |
ComposeController *aComposeController = [[ComposeController alloc] init]; |
| 90 |
|
| 91 |
[aComposeController setAddressBookController:anAddressBookController]; |
| 92 |
[anAddressBookController setWindowController:aComposeController]; |
| 93 |
[aComposeController createNewMessageWithHeader:nil contents:nil]; |
| 94 |
[composeControllers addObject:aComposeController]; |
| 95 |
[aComposeController release]; |
| 96 |
} |
| 97 |
|
| 98 |
// ���������p�l�����\�������B |
| 99 |
-(IBAction)showPreference:(id)sender{ |
| 100 |
if(prefController == nil){ |
| 101 |
prefController = [[PreferenceController alloc] init]; |
| 102 |
} |
| 103 |
[prefController showWindow:self]; |
| 104 |
} |
| 105 |
|
| 106 |
// ���[�������������\������ |
| 107 |
-(IBAction)createRule:(id)sender{ |
| 108 |
[self showPreference:self]; |
| 109 |
[prefController selectPreferenceTabWithName:@"rule_tab"]; |
| 110 |
} |
| 111 |
|
| 112 |
// �A�h���X�����\������ |
| 113 |
-(IBAction)showAddressBook:(id)sender{ |
| 114 |
[myAddressBookController showAddressBookWindow]; |
| 115 |
} |
| 116 |
|
| 117 |
// AddressBookController������ |
| 118 |
-(AddressBookController *)createAddressBookController{ |
| 119 |
AddressBookController *anAddressbookController; |
| 120 |
anAddressbookController |
| 121 |
= [[[AddressBookController alloc] init] autorelease]; |
| 122 |
[anAddressbookController window]; |
| 123 |
return anAddressbookController; |
| 124 |
} |
| 125 |
|
| 126 |
/******************* �����Adelegate���\�b�h *******************************/ |
| 127 |
// �t�H���_�c���[�pOutlineView��delegate���\�b�h |
| 128 |
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item{ |
| 129 |
MailBoxTableDataSource *ds; |
| 130 |
|
| 131 |
if([mailList dataSource] == nil){ |
| 132 |
ds = [[MailBoxTableDataSource alloc] initWithMailBox:item]; |
| 133 |
[mailList setDataSource:ds]; |
| 134 |
}else{ |
| 135 |
ds = [mailList dataSource]; |
| 136 |
[ds changeMailBox:item]; |
| 137 |
} |
| 138 |
[mailList reloadData]; |
| 139 |
return YES; |
| 140 |
} |
| 141 |
|
| 142 |
// ���[�����X�g�pTableView��delegate���\�b�h |
| 143 |
- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(int)rowIndex{ |
| 144 |
MailBoxTableDataSource *ds; |
| 145 |
DUMMailBox *selectedMailBox; |
| 146 |
DUMMail *mail; |
| 147 |
NSAttributedString *headerString; |
| 148 |
NSAttributedString *contentsString; |
| 149 |
NSTextStorage *textStorage; |
| 150 |
|
| 151 |
ds = [aTableView dataSource]; |
| 152 |
selectedMailBox = [ds mailBox]; |
| 153 |
mail = [selectedMailBox mailAtIndex:rowIndex]; |
| 154 |
headerString = [mailTextFormatManager formatHeader:[mail headerText]]; |
| 155 |
contentsString = [mailTextFormatManager formatContents:[mail content]]; |
| 156 |
textStorage = [mailContents textStorage]; |
| 157 |
[textStorage beginEditing]; |
| 158 |
[textStorage deleteCharactersInRange:NSMakeRange(0, [textStorage length])]; |
| 159 |
[textStorage appendAttributedString:headerString]; |
| 160 |
[textStorage appendAttributedString:contentsString]; |
| 161 |
[textStorage endEditing]; |
| 162 |
|
| 163 |
[mail setIsUnread:NO]; |
| 164 |
[folderTree reloadData]; |
| 165 |
[drawer setContentSize:[drawer minContentSize]]; |
| 166 |
[attachmentBrowser loadColumnZero]; |
| 167 |
[drawer toggle:self]; |
| 168 |
|
| 169 |
return YES; |
| 170 |
} |
| 171 |
|
| 172 |
// attachmentView��delegate���\�b�h |
| 173 |
- (void)textView:(NSTextView *)aTextView clickedOnCell:(id <NSTextAttachmentCell>)cell inRect:(NSRect)cellFrame atIndex:(unsigned)charIndex{ |
| 174 |
[aTextView setSelectedRange:NSMakeRange(charIndex, 1)]; |
| 175 |
} |
| 176 |
|
| 177 |
@end |