1.1 --- a/Plugins/Dual Window Interface/AIMessageWindowController.m Sun May 10 16:49:23 2009 -0400
1.2 +++ b/Plugins/Dual Window Interface/AIMessageWindowController.m Tue Jun 02 17:22:19 2009 -0400
1.3 @@ -237,8 +237,94 @@
1.4 - (IBAction)closeWindow:(id)sender
1.5 {
1.6 windowIsClosing = YES;
1.7 +
1.8 + [[self window] performClose:nil];
1.9 +}
1.10
1.11 - [[self window] performClose:nil];
1.12 +/*!
1.13 + * @brief Confirm if we should close the window.
1.14 + */
1.15 +- (BOOL)windowShouldClose:(id)window
1.16 +{
1.17 + if (!windowIsClosing
1.18 + && self.containedChats.count > 1
1.19 + && [[adium.preferenceController preferenceForKey:KEY_CONFIRM_MSG_CLOSE group:PREF_GROUP_CONFIRMATIONS] boolValue]) {
1.20 + NSString *suppressionText = nil;
1.21 +
1.22 + NSInteger unreadCount = 0;
1.23 +
1.24 + for (AIChat *chat in self.containedChats) {
1.25 + if (chat.unviewedContentCount) {
1.26 + unreadCount++;
1.27 + }
1.28 + }
1.29 +
1.30 + switch ([[adium.preferenceController preferenceForKey:KEY_CONFIRM_MSG_CLOSE_TYPE group:PREF_GROUP_CONFIRMATIONS] integerValue]) {
1.31 + case AIMessageCloseAlways:
1.32 + suppressionText = AILocalizedString(@"Do not warn when closing multiple chats", nil);
1.33 + break;
1.34 +
1.35 + case AIMessageCloseUnread:
1.36 + if (unreadCount) {
1.37 + suppressionText = AILocalizedString(@"Do not warn when closing unread chats", nil);
1.38 + }
1.39 + break;
1.40 + }
1.41 +
1.42 + NSString *question = nil;
1.43 + if (unreadCount) {
1.44 + if (unreadCount == 1) {
1.45 + question = [NSString stringWithFormat:AILocalizedString(@"%u chats are open in this window, 1 of which has unviewed messages. Do you want to close this window anyway?",nil),
1.46 + self.containedChats.count];
1.47 + } else {
1.48 + question = [NSString stringWithFormat:AILocalizedString(@"%u chats are open in this window, %u of which have unviewed messages. Do you want to close this window anyway?",nil),
1.49 + self.containedChats.count,
1.50 + unreadCount];
1.51 + }
1.52 + } else {
1.53 + question = [NSString stringWithFormat:AILocalizedString(@"%u chats are open in this window. Do you want to close this window anyway?",nil),
1.54 + self.containedChats.count];
1.55 + }
1.56 +
1.57 + if (suppressionText) {
1.58 + NSAlert *alert = [NSAlert alertWithMessageText:AILocalizedString(@"Are you sure you want to close this window?", nil)
1.59 + defaultButton:AILocalizedString(@"Close", nil)
1.60 + alternateButton:AILocalizedStringFromTable(@"Cancel", @"Buttons", nil)
1.61 + otherButton:nil
1.62 + informativeTextWithFormat:question];
1.63 +
1.64 + [alert setShowsSuppressionButton:YES];
1.65 + [[alert suppressionButton] setTitle:suppressionText];
1.66 +
1.67 + [alert beginSheetModalForWindow:self.window
1.68 + modalDelegate:self
1.69 + didEndSelector:@selector(closeAlertDidEnd:returnCode:contextInfo:)
1.70 + contextInfo:nil];
1.71 +
1.72 + return NO;
1.73 + }
1.74 + }
1.75 +
1.76 + return YES;
1.77 +}
1.78 +
1.79 +- (void)closeAlertDidEnd:(NSAlert *)alert returnCode:(int)result contextInfo:(void *)contextInfo;
1.80 +{
1.81 +
1.82 + if ([alert suppressionButton].state == NSOnState) {
1.83 + [adium.preferenceController setPreference:nil
1.84 + forKey:KEY_CONFIRM_MSG_CLOSE
1.85 + group:PREF_GROUP_CONFIRMATIONS];
1.86 + }
1.87 +
1.88 + if (result == NSAlertDefaultReturn) {
1.89 + // Dismiss the alert sheet.
1.90 + [self.window orderOut:nil];
1.91 + // Don't prompt again.
1.92 + windowIsClosing = YES;
1.93 + // Close the window.
1.94 + [self closeWindow:nil];
1.95 + }
1.96 }
1.97
1.98 /*!