-
Notifications
You must be signed in to change notification settings - Fork 404
/
Copy pathPreferencesGeneralViewController.m
68 lines (55 loc) · 1.88 KB
/
PreferencesGeneralViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// PreferencesGeneralViewController.m
// SelfControl
//
// Created by Charles Stigler on 9/27/14.
//
//
#import "PreferencesGeneralViewController.h"
#import "SCSettings.h"
#import "SCUIUtilities.h"
@interface PreferencesGeneralViewController ()
@end
@implementation PreferencesGeneralViewController
- (instancetype)init {
return [super initWithNibName: @"PreferencesGeneralViewController" bundle: nil];
}
- (void)viewDidLoad {
// set the valid sounds in the Block Sound menu
[self.soundMenu removeAllItems];
[self.soundMenu addItemsWithTitles: SCConstants.systemSoundNames];
}
- (IBAction)soundSelectionChanged:(NSPopUpButton*)sender {
// Map the tags used in interface builder to the sound
NSArray<NSString*>* systemSoundNames = SCConstants.systemSoundNames;
NSString* selectedSoundName = sender.titleOfSelectedItem;
NSUInteger blockSoundIndex = [systemSoundNames indexOfObject: selectedSoundName];
if (blockSoundIndex == NSNotFound) {
NSLog(@"WARNING: User selected unknown alert sound %@.", selectedSoundName);
NSError* err = [SCErr errorWithCode: 310];
[SCSentry captureError: err];
[SCUIUtilities presentError: err];
return;
}
// now play the sound to preview it for the user
NSSound* alertSound = [NSSound soundNamed: systemSoundNames[blockSoundIndex]];
if(!alertSound) {
NSLog(@"WARNING: Alert sound not found.");
NSError* err = [SCErr errorWithCode: 311];
[SCSentry captureError: err];
[SCUIUtilities presentError: err];
} else {
[alertSound play];
}
}
#pragma mark MASPreferencesViewController
- (NSString*)identifier {
return @"GeneralPreferences";
}
- (NSImage *)toolbarItemImage {
return [NSImage imageNamed: NSImageNamePreferencesGeneral];
}
- (NSString *)toolbarItemLabel {
return NSLocalizedString(@"General", @"Toolbar item name for the General preference pane");
}
@end