VocalEasel/Sources/VLLogWindow.mm

60 lines
1.3 KiB
Plaintext
Raw Normal View History

2006-10-26 08:21:50 +00:00
//
2007-04-27 06:41:34 +00:00
// File: VLLogWindow.mm - Manage output log window
2006-10-26 08:21:50 +00:00
//
2007-04-27 06:41:34 +00:00
// Author(s):
//
// (MN) Matthias Neeracher
//
// Copyright © 2005-2007 Matthias Neeracher
2006-10-26 08:21:50 +00:00
//
#import "VLLogWindow.h"
@implementation VLLogWindow
- (id)init
2006-10-26 08:21:50 +00:00
{
self = [super initWithWindowNibName:@"VLLogWindow"];
2006-10-26 08:21:50 +00:00
logText = [[NSMutableString alloc] initWithCapacity:1000];
return self;
}
- (void)dealloc
{
[logText autorelease];
[super dealloc];
}
- (IBAction)printDocument:(id)sender
{
[log print: sender];
}
- (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName
{
return [displayName stringByAppendingString: @" - Log"];
}
- (void) logFromFileHandle:(NSFileHandle *) h
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSData * data;
[logText setString: @""];
[log setString: logText];
while ((data = [h availableData]) && [data length]) {
NSString * append = [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease];
2017-11-24 05:01:22 +00:00
dispatch_sync(dispatch_get_main_queue(), ^{
[logText appendString: append];
[log setString: logText];
[log scrollRangeToVisible: NSMakeRange([logText length], 0)];
});
2006-10-26 08:21:50 +00:00
[pool release];
pool = [[NSAutoreleasePool alloc] init];
}
[pool release];
}
@end