2 Copyright (C) 2004 Marcus Mueller <znek@mulle-kybernetik.com>
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "SOPEXConsole.h"
26 @interface SOPEXConsole (PrivateAPI)
27 - (NSFont *)stdoutFont;
28 - (NSFont *)stderrFont;
29 - (NSColor *)stdoutFontColor;
30 - (NSColor *)stderrFontColor;
32 - (void)appendLogEvent:(NGLogEvent *)_event;
35 #include "SOPEXToolbarController.h"
38 @implementation SOPEXConsole
40 static NGLogEventFormatter *eventFormatter = nil;
43 static BOOL didInit = NO;
47 eventFormatter = [[NSClassFromString(@"SOPEXConsoleEventFormatter") alloc] init];
53 [NSBundle loadNibNamed:@"SOPEXConsole" owner:self];
54 NSAssert(self->window != nil, @"Problem loading SOPEXConsole.nib!");
56 self->toolbar = [[SOPEXToolbarController alloc] initWithIdentifier:@"SOPEXConsole" target:self];
57 [self->toolbar applyOnWindow:self->window];
59 self->stdoutAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:[self stdoutFont], NSFontAttributeName, [self stdoutFontColor], NSForegroundColorAttributeName, nil];
60 self->stderrAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:[self stderrFont], NSFontAttributeName, [self stderrFontColor], NSForegroundColorAttributeName, nil];
66 [self->window orderOut:self];
67 [self->stdoutAttributes release];
68 [self->stderrAttributes release];
73 /* console properties */
75 - (NSFont *)stdoutFont {
76 return [NSFont fontWithName:@"Courier" size:12];
78 - (NSFont *)stderrFont {
79 return [NSFont fontWithName:@"Courier" size:12];
81 - (NSColor *)stdoutFontColor {
82 return [NSColor blackColor];
84 - (NSColor *)stderrFontColor {
85 return [NSColor redColor];
89 /* window handling/delegate */
91 - (IBAction)orderFront:(id)sender {
92 [self->window makeKeyAndOrderFront:sender];
94 - (void)windowWillClose:(NSNotification *)_notif {
100 - (IBAction)clear:(id)sender {
101 NSTextStorage *storage;
103 storage = [self->text textStorage];
104 [storage beginEditing];
105 [storage deleteCharactersInRange:NSMakeRange(0, [storage length])];
106 [storage endEditing];
109 - (BOOL)validateToolbarItem:(NSToolbarItem *)_item {
110 return [self validateMenuItem:(id <NSMenuItem>)_item];
113 - (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem {
114 SEL action = [menuItem action];
116 if(action == @selector(clear:))
117 return [[self->text textStorage] length] > 0;
121 - (void)appendLogEvent:(NGLogEvent *)_event {
122 NSTextStorage *storage;
126 storage = [self->text textStorage];
127 msg = [eventFormatter formattedEvent:_event];
129 [storage beginEditing];
130 loc = [storage length];
131 [storage replaceCharactersInRange:NSMakeRange(loc, 0) withString:msg];
132 [storage replaceCharactersInRange:NSMakeRange([storage length], 0)
134 [storage setAttributes:self->stdoutAttributes
135 range:NSMakeRange(loc, [msg length] + 1)];
137 if([storage length] > 50 * 1024)
138 [storage deleteCharactersInRange:NSMakeRange(0, [storage length] - 50 * 1024)];
139 [storage endEditing];
141 // scroll to bottom if verticalScroller is at bottom
142 if([[(NSScrollView*)[[self->text superview] superview] verticalScroller] floatValue] == 1.0)
143 [self->text scrollRangeToVisible:NSMakeRange([storage length], 1)];