macOS: Use dark appearance for panel modals
[vlc.git] / modules / gui / macosx / VLCErrorWindowController.m
blobe3b8455bd02ef267ac20f1e19ac6ace9fb417a23
1 /*****************************************************************************
2  * HelpWindowController.m
3  *****************************************************************************
4  * Copyright (C) 2017 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Derk-Jan Hartman <thedj@users.sourceforge.net>
8  *          Felix Paul Kühne <fkuehne -at- videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
25 #import "VLCErrorWindowController.h"
27 #import "VLCStringUtility.h"
30 @interface VLCErrorWindowController()
32     NSMutableArray *_errors;
33     NSMutableArray *_icons;
36 @end
38 @implementation VLCErrorWindowController
40 - (id)init
42     self = [super initWithWindowNibName:@"ErrorPanel"];
43     if (self) {
44         /* init data sources */
45         _errors = [[NSMutableArray alloc] init];
46         _icons = [[NSMutableArray alloc] init];
47     }
49     return self;
52 - (void)windowDidLoad
54     /* init strings */
55     [self.window setTitle: _NS("Errors and Warnings")];
56     [self.cleanupButton setTitle: _NS("Clean up")];
58     if ([[NSApplication sharedApplication] userInterfaceLayoutDirection] == NSUserInterfaceLayoutDirectionRightToLeft) {
59         [self.errorTable moveColumn:0 toColumn:1];
60     }
63 - (void)addError:(NSString *)title withMsg:(NSString *)message;
65     /* format our string as desired */
66     NSMutableAttributedString * ourError;
67     ourError = [[NSMutableAttributedString alloc] initWithString:
68                 [NSString stringWithFormat:@"%@\n%@", title, message]
69                                                       attributes:
70                 [NSDictionary dictionaryWithObject: [NSFont systemFontOfSize:11] forKey: NSFontAttributeName]];
71     [ourError
72      addAttribute: NSFontAttributeName
73      value: [NSFont boldSystemFontOfSize:11]
74      range: NSMakeRange(0, [title length])];
75     [_errors addObject: ourError];
77     [_icons addObject: [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kAlertStopIcon)]];
79     [self.errorTable reloadData];
82 -(IBAction)cleanupTable:(id)sender
84     [_errors removeAllObjects];
85     [_icons removeAllObjects];
86     [self.errorTable reloadData];
89 /*----------------------------------------------------------------------------
90  * data source methods
91  *---------------------------------------------------------------------------*/
92 - (NSInteger)numberOfRowsInTableView:(NSTableView *)theDataTable
94     return [_errors count];
97 - (id)tableView:(NSTableView *)theDataTable objectValueForTableColumn:
98 (NSTableColumn *)theTableColumn row: (NSInteger)row
100     if ([[theTableColumn identifier] isEqualToString: @"error_msg"])
101         return [_errors objectAtIndex:row];
103     if ([[theTableColumn identifier] isEqualToString: @"icon"])
104         return [_icons objectAtIndex:row];
106     return @"";
109 @end