You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

114 lines
3.8 KiB

//
// CLAppearanceViewController.m
// Clocker
//
// Created by Abhishek Banthia on 12/19/15.
//
//
#import "CLAppearanceViewController.h"
#import "ApplicationDelegate.h"
#import "PanelController.h"
#import "CommonStrings.h"
@interface CLAppearanceViewController ()
@property (weak) IBOutlet NSSegmentedControl *timeFormat;
@property (weak) IBOutlet NSSegmentedControl *theme;
@property (weak) IBOutlet NSPopUpButton *fontPopup;
@property (weak) IBOutlet NSSegmentedControl *sunriseToggle;
@end
@implementation CLAppearanceViewController
- (void)viewDidLoad {
[super viewDidLoad];
CALayer *viewLayer = [CALayer layer];
[viewLayer setBackgroundColor:CGColorCreateGenericRGB(255.0, 255.0, 255.0, 0.8)]; //RGB plus Alpha Channel
[self.view setWantsLayer:YES]; // view's backing store is using a Core Animation Layer
[self.view setLayer:viewLayer];
//Certain fonts don't look good with constraints set
NSMutableArray *availableFonts = [[NSMutableArray alloc] init];
NSFontCollection *fontCollection = [NSFontCollection fontCollectionWithName:@"com.apple.UserFonts"];
for (NSFontDescriptor *descriptor in fontCollection.matchingDescriptors) {
if ([descriptor objectForKey:@"NSFontFamilyAttribute"]) {
if (![availableFonts containsObject:[descriptor objectForKey:@"NSFontFamilyAttribute"]]) {
[availableFonts addObject:[descriptor objectForKey:@"NSFontFamilyAttribute"]];
}
}
}
NSArray *fontsToRemove = [NSArray arrayWithObjects:@"Apple Chancery", @"Zapfino",
@"Trattatello", @"Noteworthy", @"Arial Black", @"Chalkduster",@"Monoid", @"Andale Mono", @"Courier" ,@"Courier New",@"Geneva",@"Menlo", @"Monaco",@"PT Mono", @"Verdana", nil];
for (NSString *font in fontsToRemove) {
if([availableFonts containsObject:font])
{
[availableFonts removeObject:font];
}
}
[availableFonts insertObject:@"Default" atIndex:0];
self.fontFamilies = [[NSArray alloc] initWithArray:availableFonts];
// Do view setup here.
}
- (IBAction)timeFormatSelectionChanged:(id)sender
{
NSSegmentedControl *timeFormat = (NSSegmentedControl *)sender;
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInteger:timeFormat.selectedSegment] forKey:CL24hourFormatSelectedKey];
[self refreshMainTableview];
}
- (IBAction)themeChanged:(id)sender
{
NSSegmentedControl *themeSegment = (NSSegmentedControl *)sender;
ApplicationDelegate *appDelegate = [[NSApplication sharedApplication] delegate];
PanelController *panelController = appDelegate.panelController;
[panelController.backgroundView setNeedsDisplay:YES];
if (themeSegment.selectedSegment == CLBlackTheme) {
panelController.shutdownButton.image = [NSImage imageNamed:@"PowerIcon-White"];
panelController.preferencesButton.image = [NSImage imageNamed:@"Settings-White"];
}
else
{
panelController.shutdownButton.image = [NSImage imageNamed:@"PowerIcon"];
panelController.preferencesButton.image = [NSImage imageNamed:NSImageNameActionTemplate];
}
[panelController.mainTableview reloadData];
}
- (IBAction)fontChanged:(id)sender
{
ApplicationDelegate *appDelegate = [[NSApplication sharedApplication] delegate];
PanelController *panelController = appDelegate.panelController;
[panelController.mainTableview reloadData];
}
- (IBAction)toggleSunriseAndSunset:(id)sender {
}
- (void)refreshMainTableview
{
dispatch_async(dispatch_get_main_queue(), ^{
ApplicationDelegate *appDelegate = [[NSApplication sharedApplication] delegate];
PanelController *panelController = appDelegate.panelController;
[panelController updateDefaultPreferences];
[panelController.mainTableview reloadData];
});
}
@end