French updates
[adiumx.git] / Source / ESDebugWindowController.m
blob86ea44915aea61cbc6982b51feffe48a40f509a2
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6  * General Public License as published by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
11  * Public License for more details.
12  * 
13  * You should have received a copy of the GNU General Public License along with this program; if not,
14  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15  */
17 #import "ESDebugController.h"
18 #import "ESDebugWindowController.h"
19 #import <AIUtilities/AIAutoScrollView.h>
21 #define KEY_DEBUG_WINDOW_FRAME  @"Debug Window Frame"
22 #define DEBUG_WINDOW_NIB                @"DebugWindow"
24 @implementation ESDebugWindowController
25 #ifdef DEBUG_BUILD
27 static ESDebugWindowController *sharedDebugWindowInstance = nil;
29 //Return the shared contact info window
30 + (id)showDebugWindow
32     //Create the window
33     if(!sharedDebugWindowInstance){
34         sharedDebugWindowInstance = [[self alloc] initWithWindowNibName:DEBUG_WINDOW_NIB];
35     }
36         
37         //Configure and show window
38         [sharedDebugWindowInstance showWindow:nil];
39         
40         return(sharedDebugWindowInstance);
43 + (BOOL)debugWindowIsOpen
45         return(sharedDebugWindowInstance != nil);
48 - (void)addedDebugMessage:(NSString *)aDebugString
50         [mutableDebugString appendString:aDebugString];
51         if ((![aDebugString hasSuffix:@"\n"]) && (![aDebugString hasSuffix:@"\r"])){
52                 [mutableDebugString appendString:@"\n"];
53         }
55 + (void)addedDebugMessage:(NSString *)aDebugString
57         if(sharedDebugWindowInstance) [sharedDebugWindowInstance addedDebugMessage:aDebugString];
60 - (NSString *)adiumFrameAutosaveName
62         return(KEY_DEBUG_WINDOW_FRAME);
65 //Setup the window before it is displayed
66 - (void)windowDidLoad
67 {    
68         NSEnumerator    *enumerator;
69         NSString                *aDebugString;
71         [super windowDidLoad];
73         //We store the reference to the mutableString of the textStore for efficiency
74         mutableDebugString = [[[textView_debug textStorage] mutableString] retain];
75         
76         [scrollView_debug setAutoScrollToBottom:YES];
78         //Load the logs which were added before the window was loaded
79         enumerator = [[[adium debugController] debugLogArray] objectEnumerator];
80         while(aDebugString = [enumerator nextObject]){
81                 [mutableDebugString appendString:aDebugString];
82                 if ((![aDebugString hasSuffix:@"\n"]) && (![aDebugString hasSuffix:@"\r"])){
83                         [mutableDebugString appendString:@"\n"];
84                 }
85         }
87         [[self window] setTitle:AILocalizedString(@"Adium Debug Log","Debug window title")];
89         //On the next run loop, scroll to the bottom
90         [scrollView_debug performSelector:@selector(scrollToBottom)
91                                                    withObject:nil
92                                                    afterDelay:0.001];
95 //Close the debug window
96 + (void)closeDebugWindow
98     if(sharedDebugWindowInstance){
99         [sharedDebugWindowInstance closeWindow:nil];
100     }
103 //called as the window closes
104 - (void)windowWillClose:(id)sender
106         [super windowWillClose:sender];
107         
108         //Close down
109         [mutableDebugString release]; mutableDebugString = nil;
110     [self autorelease]; sharedDebugWindowInstance = nil;
113 #endif
115 @end