Commit b0aa6c5f authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx: re-written the messages panel to use a table view instead of a text...

macosx: re-written the messages panel to use a table view instead of a text view. this vastly improves its performance and prevents any related crashes known to me so far

thanks to poldi for the idea
parent 6e37e198
/***************************************************************************** /*****************************************************************************
* intf.h: MacOS X interface module * intf.h: MacOS X interface module
***************************************************************************** *****************************************************************************
* Copyright (C) 2002-2011 VLC authors and VideoLAN * Copyright (C) 2002-2012 VLC authors and VideoLAN
* $Id$ * $Id$
* *
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net> * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
...@@ -116,15 +116,14 @@ struct intf_sys_t ...@@ -116,15 +116,14 @@ struct intf_sys_t
IBOutlet VLCControls * o_controls; /* VLCControls */ IBOutlet VLCControls * o_controls; /* VLCControls */
IBOutlet VLCPlaylist * o_playlist; /* VLCPlaylist */ IBOutlet VLCPlaylist * o_playlist; /* VLCPlaylist */
IBOutlet NSTextView * o_messages; /* messages tv */
IBOutlet NSWindow * o_msgs_panel; /* messages panel */ IBOutlet NSWindow * o_msgs_panel; /* messages panel */
NSMutableArray * o_msg_arr; /* messages array */ NSMutableArray * o_msg_arr; /* messages array */
NSLock * o_msg_lock; /* messages lock */ NSLock * o_msg_lock; /* messages lock */
BOOL b_msg_arr_changed; /* did the array change? */ BOOL b_msg_arr_changed; /* did the array change? */
IBOutlet NSButton * o_msgs_crashlog_btn; /* messages open crashlog */ IBOutlet NSButton * o_msgs_crashlog_btn; /* messages open crashlog */
IBOutlet NSButton * o_msgs_save_btn; /* save the log as rtf */ IBOutlet NSButton * o_msgs_save_btn; /* save the log as rtf */
IBOutlet NSButton * o_msgs_liveUpdate_ckb; /* always update the panel when visible */ IBOutlet NSButton * o_msgs_refresh_btn; /* update the panel */
BOOL b_msg_live_update; IBOutlet id o_msgs_table;
/* CrashReporter panel */ /* CrashReporter panel */
IBOutlet NSButton * o_crashrep_dontSend_btn; IBOutlet NSButton * o_crashrep_dontSend_btn;
...@@ -195,13 +194,11 @@ struct intf_sys_t ...@@ -195,13 +194,11 @@ struct intf_sys_t
- (void)initStrings; - (void)initStrings;
- (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename; - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename;
- (void)updateMessageDisplay;
- (IBAction)crashReporterAction:(id)sender; - (IBAction)crashReporterAction:(id)sender;
- (IBAction)openCrashLog:(id)sender; - (IBAction)openCrashLog:(id)sender;
- (IBAction)saveDebugLog:(id)sender; - (IBAction)saveDebugLog:(id)sender;
- (IBAction)showMessagesPanel:(id)sender; - (IBAction)showMessagesPanel:(id)sender;
- (IBAction)liveUpdateMessagesPanel:(id)sender; - (IBAction)updateMessagesPanel:(id)sender;
- (void)processReceivedlibvlcMessage:(const msg_item_t *) item ofType: (int)type withStr: (char *)str; - (void)processReceivedlibvlcMessage:(const msg_item_t *) item ofType: (int)type withStr: (char *)str;
......
...@@ -611,8 +611,7 @@ static VLCMain *_o_sharedMainInstance = nil; ...@@ -611,8 +611,7 @@ static VLCMain *_o_sharedMainInstance = nil;
[o_remote setClickCountEnabledButtons: kRemoteButtonPlay]; [o_remote setClickCountEnabledButtons: kRemoteButtonPlay];
[o_remote setDelegate: _o_sharedMainInstance]; [o_remote setDelegate: _o_sharedMainInstance];
b_msg_live_update = [[NSUserDefaults standardUserDefaults] boolForKey:@"LiveUpdateTheMessagesPanel"]; [o_msgs_refresh_btn setImage: [NSImage imageNamed: NSImageNameRefreshTemplate]];
[o_msgs_liveUpdate_ckb setState: b_msg_live_update];
/* yeah, we are done */ /* yeah, we are done */
b_nativeFullscreenMode = config_GetInt( p_intf, "macosx-nativefullscreenmode" ); b_nativeFullscreenMode = config_GetInt( p_intf, "macosx-nativefullscreenmode" );
...@@ -660,7 +659,6 @@ static VLCMain *_o_sharedMainInstance = nil; ...@@ -660,7 +659,6 @@ static VLCMain *_o_sharedMainInstance = nil;
[o_msgs_panel setTitle: _NS("Messages")]; [o_msgs_panel setTitle: _NS("Messages")];
[o_msgs_crashlog_btn setTitle: _NS("Open CrashLog...")]; [o_msgs_crashlog_btn setTitle: _NS("Open CrashLog...")];
[o_msgs_save_btn setTitle: _NS("Save this Log...")]; [o_msgs_save_btn setTitle: _NS("Save this Log...")];
[o_msgs_liveUpdate_ckb setTitle: _NS("Live Update")];
/* crash reporter panel */ /* crash reporter panel */
[o_crashrep_send_btn setTitle: _NS("Send")]; [o_crashrep_send_btn setTitle: _NS("Send")];
...@@ -1837,15 +1835,9 @@ unsigned int CocoaKeyToVLC( unichar i_key ) ...@@ -1837,15 +1835,9 @@ unsigned int CocoaKeyToVLC( unichar i_key )
#pragma mark - #pragma mark -
#pragma mark Errors, warnings and messages #pragma mark Errors, warnings and messages
- (IBAction)liveUpdateMessagesPanel:(id)sender - (IBAction)updateMessagesPanel:(id)sender
{ {
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"LiveUpdateTheMessagesPanel"]) [self windowDidBecomeKey:nil];
[[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"LiveUpdateTheMessagesPanel"];
else
[[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"LiveUpdateTheMessagesPanel"];
b_msg_live_update = [[NSUserDefaults standardUserDefaults] boolForKey:@"LiveUpdateTheMessagesPanel"];
[o_msgs_liveUpdate_ckb setState: b_msg_live_update];
} }
- (IBAction)showMessagesPanel:(id)sender - (IBAction)showMessagesPanel:(id)sender
...@@ -1855,29 +1847,20 @@ unsigned int CocoaKeyToVLC( unichar i_key ) ...@@ -1855,29 +1847,20 @@ unsigned int CocoaKeyToVLC( unichar i_key )
- (void)windowDidBecomeKey:(NSNotification *)o_notification - (void)windowDidBecomeKey:(NSNotification *)o_notification
{ {
if( [o_notification object] == o_msgs_panel ) [o_msgs_table reloadData];
[self updateMessageDisplay]; [o_msgs_table scrollRowToVisible: [o_msg_arr count] - 1];
} }
- (void)updateMessageDisplay - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{ {
if( [o_msgs_panel isVisible] && (b_msg_live_update || [o_msgs_panel isKeyWindow]) && b_msg_arr_changed ) if (aTableView == o_msgs_table)
{ return [o_msg_arr count];
id o_msg; return 0;
NSEnumerator * o_enum; }
[o_messages setString: @""];
[o_msg_lock lock];
o_enum = [o_msg_arr objectEnumerator];
while( ( o_msg = [o_enum nextObject] ) != NULL )
[o_messages insertText: o_msg];
b_msg_arr_changed = NO; - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
[o_msg_lock unlock]; {
} return [o_msg_arr objectAtIndex: rowIndex];
} }
- (void)processReceivedlibvlcMessage:(const msg_item_t *) item ofType: (int)i_type withStr: (char *)str - (void)processReceivedlibvlcMessage:(const msg_item_t *) item ofType: (int)i_type withStr: (char *)str
...@@ -1886,12 +1869,13 @@ unsigned int CocoaKeyToVLC( unichar i_key ) ...@@ -1886,12 +1869,13 @@ unsigned int CocoaKeyToVLC( unichar i_key )
NSColor *o_red = [NSColor redColor]; NSColor *o_red = [NSColor redColor];
NSColor *o_yellow = [NSColor yellowColor]; NSColor *o_yellow = [NSColor yellowColor];
NSColor *o_gray = [NSColor grayColor]; NSColor *o_gray = [NSColor grayColor];
NSString * firstString, * secondString;
NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray }; NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
static const char * ppsz_type[4] = { ": ", " error: ", " warning: ", " debug: " }; static const char * ppsz_type[4] = { ": ", " error: ", " warning: ", " debug: " };
NSDictionary *o_attr; NSDictionary *o_attr;
NSAttributedString *o_msg_color; NSMutableAttributedString *o_msg_color;
[o_msg_lock lock]; [o_msg_lock lock];
...@@ -1900,19 +1884,17 @@ unsigned int CocoaKeyToVLC( unichar i_key ) ...@@ -1900,19 +1884,17 @@ unsigned int CocoaKeyToVLC( unichar i_key )
[o_msg_arr removeObjectAtIndex: 0]; [o_msg_arr removeObjectAtIndex: 0];
[o_msg_arr removeObjectAtIndex: 1]; [o_msg_arr removeObjectAtIndex: 1];
} }
firstString = [NSString stringWithFormat:@"%s%s", item->psz_module, ppsz_type[i_type]];
secondString = [NSString stringWithFormat:@"%@%s\n", firstString, str];
o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type] forKey: NSForegroundColorAttributeName];
o_msg_color = [[NSMutableAttributedString alloc] initWithString: secondString attributes: o_attr];
o_attr = [NSDictionary dictionaryWithObject: pp_color[3] forKey: NSForegroundColorAttributeName]; o_attr = [NSDictionary dictionaryWithObject: pp_color[3] forKey: NSForegroundColorAttributeName];
o_msg_color = [[NSAttributedString alloc] initWithString: [NSString stringWithFormat: @"%s%s", item->psz_module, ppsz_type[i_type]] attributes: o_attr]; [o_msg_color setAttributes: o_attr range: NSMakeRange( 0, [firstString length] )];
[o_msg_arr addObject: [o_msg_color autorelease]];
o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type] forKey: NSForegroundColorAttributeName];
o_msg_color = [[NSAttributedString alloc] initWithString: [NSString stringWithFormat: @"%s\n", str] attributes: o_attr];
[o_msg_arr addObject: [o_msg_color autorelease]]; [o_msg_arr addObject: [o_msg_color autorelease]];
b_msg_arr_changed = YES; b_msg_arr_changed = YES;
[o_msg_lock unlock]; [o_msg_lock unlock];
[self performSelectorOnMainThread:@selector(updateMessageDisplay) withObject: nil waitUntilDone:NO];
} }
- (IBAction)saveDebugLog:(id)sender - (IBAction)saveDebugLog:(id)sender
...@@ -1930,7 +1912,15 @@ unsigned int CocoaKeyToVLC( unichar i_key ) ...@@ -1930,7 +1912,15 @@ unsigned int CocoaKeyToVLC( unichar i_key )
BOOL b_returned; BOOL b_returned;
if( returnCode == NSOKButton ) if( returnCode == NSOKButton )
{ {
b_returned = [o_messages writeRTFDToFile: [[sheet URL] path] atomically: YES]; NSUInteger count = [o_msg_arr count];
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] init];
for (NSUInteger i = 0; i < count; i++)
{
[string appendAttributedString: [o_msg_arr objectAtIndex: i]];
}
b_returned = [[string RTFDFileWrapperFromRange:NSMakeRange( 0, [string length] ) documentAttributes:[NSDictionary dictionaryWithObject: NSRTFDTextDocumentType forKey: NSDocumentTypeDocumentAttribute]] writeToFile:[[sheet URL] path] atomically:YES updateFilenames:NO];
[string release];
if(! b_returned ) if(! b_returned )
msg_Warn( p_intf, "Error while saving the debug log" ); msg_Warn( p_intf, "Error while saving the debug log" );
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment