macosx: convert debug message visualizer to NSWindowController
authorDavid Fuhrmann <dfuhrmann@videolan.org>
Thu, 30 Jul 2015 17:18:12 +0000 (19:18 +0200)
committerDavid Fuhrmann <dfuhrmann@videolan.org>
Thu, 30 Jul 2015 17:49:59 +0000 (19:49 +0200)
... and get rid of another singleton.

extras/package/macosx/Resources/English.lproj/DebugMessageVisualizer.xib
modules/gui/macosx/DebugMessageVisualizer.h
modules/gui/macosx/DebugMessageVisualizer.m
modules/gui/macosx/MainMenu.m
modules/gui/macosx/intf.h
modules/gui/macosx/intf.m

index e7d8cd8..a35e4f1 100644 (file)
@@ -2,13 +2,13 @@
 <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="8.00">
        <data>
                <int key="IBDocument.SystemTarget">1060</int>
-               <string key="IBDocument.SystemVersion">14B25</string>
-               <string key="IBDocument.InterfaceBuilderVersion">6254</string>
-               <string key="IBDocument.AppKitVersion">1343.16</string>
-               <string key="IBDocument.HIToolboxVersion">755.00</string>
+               <string key="IBDocument.SystemVersion">14F6a</string>
+               <string key="IBDocument.InterfaceBuilderVersion">7706</string>
+               <string key="IBDocument.AppKitVersion">1348.17</string>
+               <string key="IBDocument.HIToolboxVersion">758.70</string>
                <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
                        <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
-                       <string key="NS.object.0">6254</string>
+                       <string key="NS.object.0">7706</string>
                </object>
                <array key="IBDocument.IntegratedClassDependencies">
                        <string>NSButton</string>
                                </object>
                                <object class="IBConnectionRecord">
                                        <object class="IBOutletConnection" key="connection">
-                                               <string key="label">_msgs_panel</string>
+                                               <string key="label">window</string>
                                                <reference key="source" ref="1001"/>
                                                <reference key="destination" ref="401114513"/>
                                        </object>
-                                       <int key="connectionID">23</int>
+                                       <int key="connectionID">24</int>
                                </object>
                                <object class="IBConnectionRecord">
                                        <object class="IBOutletConnection" key="connection">
                        <nil key="activeLocalization"/>
                        <dictionary class="NSMutableDictionary" key="localizations"/>
                        <nil key="sourceID"/>
-                       <int key="maxID">23</int>
+                       <int key="maxID">24</int>
                </object>
                <object class="IBClassDescriber" key="IBDocument.Classes">
                        <array class="NSMutableArray" key="referencedPartialClassDescriptions">
                                <object class="IBPartialClassDescription">
                                        <string key="className">VLCDebugMessageVisualizer</string>
-                                       <string key="superclassName">NSObject</string>
+                                       <string key="superclassName">NSWindowController</string>
                                        <dictionary class="NSMutableDictionary" key="actions">
                                                <string key="saveDebugLog:">id</string>
                                                <string key="updateMessagesPanel:">id</string>
                                                </object>
                                        </dictionary>
                                        <dictionary class="NSMutableDictionary" key="outlets">
-                                               <string key="_msgs_panel">NSWindow</string>
                                                <string key="_msgs_refresh_btn">NSButton</string>
                                                <string key="_msgs_save_btn">NSButton</string>
                                                <string key="_msgs_table">id</string>
                                        </dictionary>
                                        <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
-                                               <object class="IBToOneOutletInfo" key="_msgs_panel">
-                                                       <string key="name">_msgs_panel</string>
-                                                       <string key="candidateClassName">NSWindow</string>
-                                               </object>
                                                <object class="IBToOneOutletInfo" key="_msgs_refresh_btn">
                                                        <string key="name">_msgs_refresh_btn</string>
                                                        <string key="candidateClassName">NSButton</string>
                                                <string key="minorKey">AppKit.framework/Headers/NSWindow.h</string>
                                        </object>
                                </object>
+                               <object class="IBPartialClassDescription">
+                                       <string key="className">NSWindowController</string>
+                                       <string key="superclassName">NSResponder</string>
+                                       <object class="NSMutableDictionary" key="actions">
+                                               <string key="NS.key.0">showWindow:</string>
+                                               <string key="NS.object.0">id</string>
+                                       </object>
+                                       <object class="NSMutableDictionary" key="actionInfosByName">
+                                               <string key="NS.key.0">showWindow:</string>
+                                               <object class="IBActionInfo" key="NS.object.0">
+                                                       <string key="name">showWindow:</string>
+                                                       <string key="candidateClassName">id</string>
+                                               </object>
+                                       </object>
+                                       <object class="IBClassDescriptionSource" key="sourceIdentifier">
+                                               <string key="majorKey">IBFrameworkSource</string>
+                                               <string key="minorKey">AppKit.framework/Headers/NSWindowController.h</string>
+                                       </object>
+                               </object>
                        </array>
                </object>
                <int key="IBDocument.localizationMode">0</int>
index b318f7d..225174e 100644 (file)
 
 #import <Cocoa/Cocoa.h>
 
-@interface VLCDebugMessageVisualizer : NSObject
+@interface VLCDebugMessageVisualizer : NSWindowController
 {
-    IBOutlet NSWindow * _msgs_panel;
     IBOutlet NSButton * _msgs_save_btn;
     IBOutlet NSButton * _msgs_refresh_btn;
     IBOutlet id _msgs_table;
 }
 + (VLCDebugMessageVisualizer *)sharedInstance;
 
-- (void)showPanel;
+- (void)showWindow:(id)sender;
 
 - (IBAction)updateMessagesPanel:(id)sender;
 - (IBAction)saveDebugLog:(id)sender;
index 13c2f8e..b784045 100644 (file)
@@ -47,6 +47,9 @@ static void MsgCallback(void *data, int type, const vlc_log_t *item, const char
 static void MsgCallback(void *data, int type, const vlc_log_t *item, const char *format, va_list ap)
 {
     @autoreleasepool {
+
+        VLCDebugMessageVisualizer *visualizer = (__bridge VLCDebugMessageVisualizer*)data;
+
         int canc = vlc_savecancel();
         char *str;
 
@@ -55,7 +58,7 @@ static void MsgCallback(void *data, int type, const vlc_log_t *item, const char
             return;
         }
 
-        [[VLCDebugMessageVisualizer sharedInstance] processReceivedlibvlcMessage: item ofType: type withStr: str];
+        [visualizer processReceivedlibvlcMessage: item ofType: type withStr: str];
 
         vlc_restorecancel(canc);
         free(str);
@@ -78,33 +81,31 @@ static void MsgCallback(void *data, int type, const vlc_log_t *item, const char
 
 - (id)init
 {
-    self = [super init];
+    self = [super initWithWindowNibName:@"DebugMessageVisualizer"];
     if (self) {
         _msg_lock = [[NSLock alloc] init];
         _msg_arr = [NSMutableArray arrayWithCapacity:600];
-        BOOL loaded = [NSBundle loadNibNamed:@"DebugMessageVisualizer" owner:self];
     }
     return self;
 }
 
-- (void)awakeFromNib
+- (void)windowDidLoad
 {
-    [_msgs_panel setExcludedFromWindowsMenu: YES];
-    [_msgs_panel setDelegate: self];
-    [_msgs_panel setTitle: _NS("Messages")];
+    [self.window setExcludedFromWindowsMenu: YES];
+    [self.window setDelegate: self];
+    [self.window setTitle: _NS("Messages")];
     [_msgs_save_btn setTitle: _NS("Save this Log...")];
     [_msgs_refresh_btn setImage: [NSImage imageNamed: NSImageNameRefreshTemplate]];
 }
 
 #pragma mark - UI interaction
 
-- (void)showPanel
+- (void)showWindow:(id)sender
 {
     /* subscribe to LibVLCCore's messages */
-    vlc_LogSet(VLCIntf->p_libvlc, MsgCallback, NULL);
+    vlc_LogSet(VLCIntf->p_libvlc, MsgCallback, (__bridge void*)self);
 
-    /* show panel */
-    [_msgs_panel makeKeyAndOrderFront:nil];
+    [super showWindow:sender];
 }
 
 - (IBAction)updateMessagesPanel:(id)sender
@@ -132,7 +133,7 @@ static void MsgCallback(void *data, int type, const vlc_log_t *item, const char
     [saveFolderPanel setCanCreateDirectories: YES];
     [saveFolderPanel setAllowedFileTypes: [NSArray arrayWithObject:@"rtf"]];
     [saveFolderPanel setNameFieldStringValue:[NSString stringWithFormat: _NS("VLC Debug Log (%s).rtf"), VERSION_MESSAGE]];
-    [saveFolderPanel beginSheetModalForWindow: _msgs_panel completionHandler:^(NSInteger returnCode) {
+    [saveFolderPanel beginSheetModalForWindow: self.window completionHandler:^(NSInteger returnCode) {
         if (returnCode == NSOKButton) {
             NSUInteger count = [_msg_arr count];
             NSMutableAttributedString * string = [[NSMutableAttributedString alloc] init];
index 6137a02..86d9641 100644 (file)
 
 - (IBAction)showMessagesPanel:(id)showMessagesPanel
 {
-    [[VLCDebugMessageVisualizer sharedInstance] showPanel];
+    [[[VLCMain sharedInstance] debugMsgPanel] showWindow:self];
 }
 
 - (IBAction)showMainWindow:(id)sender
index 4b970b0..fec2eea 100644 (file)
@@ -64,6 +64,7 @@ static NSString * VLCInputChangedNotification = @"VLCInputChangedNotification";
 @class VLCCoreDialogProvider;
 @class VLCBookmarks;
 @class VLCOpen;
+@class VLCDebugMessageVisualizer;
 
 @interface VLCMain : NSObject <NSWindowDelegate, NSApplicationDelegate>
 {
@@ -88,6 +89,8 @@ static NSString * VLCInputChangedNotification = @"VLCInputChangedNotification";
 - (VLCCoreDialogProvider *)coreDialogProvider;
 - (ResumeDialogController *)resumeDialog;
 - (VLCInputManager *)inputManager;
+- (VLCDebugMessageVisualizer *)debugMsgPanel;
+
 - (void)setActiveVideoPlayback:(BOOL)b_value;
 - (BOOL)activeVideoPlayback;
 - (void)applicationWillTerminate:(NSNotification *)notification;
index 9860e67..06ac5a7 100644 (file)
@@ -58,6 +58,7 @@
 #import "ExtensionsManager.h"
 #import "BWQuincyManager.h"
 #import "ResumeDialogController.h"
+#import "DebugMessageVisualizer.h"
 
 #import "VideoEffects.h"
 #import "AudioEffects.h"
@@ -157,6 +158,7 @@ static int ShowController(vlc_object_t *p_this, const char *psz_variable,
     ResumeDialogController *_resume_dialog;
     VLCInputManager *_input_manager;
     VLCPlaylist *_playlist;
+    VLCDebugMessageVisualizer *_messagePanelController;
 
     bool b_intf_terminating; /* Makes sure applicationWillTerminate will be called only once */
 }
@@ -521,6 +523,14 @@ static int ShowController(vlc_object_t *p_this, const char *psz_variable,
     return _input_manager;
 }
 
+- (VLCDebugMessageVisualizer *)debugMsgPanel
+{
+    if (!_messagePanelController)
+        _messagePanelController = [[VLCDebugMessageVisualizer alloc] init];
+
+    return _messagePanelController;
+}
+
 - (VLCBookmarks *)bookmarks
 {
     if (!_bookmarks)