-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Common Superclass for Floating Window and Panel and other changes.
- Loading branch information
Showing
10 changed files
with
301 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,4 @@ | |
|
||
@interface CLAppearanceViewController : NSViewController | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// CLParentPanelController.h | ||
// Clocker | ||
// | ||
// Created by Abhishek Banthia on 4/4/16. | ||
// | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
#import "CLOneWindowController.h" | ||
|
||
@interface CLParentPanelController : NSWindowController<NSWindowDelegate, NSTableViewDataSource, NSTableViewDelegate> | ||
|
||
|
||
@property (nonatomic, strong) NSMutableArray *defaultPreferences; | ||
@property (nonatomic, strong) NSDateFormatter *dateFormatter; | ||
@property (nonatomic, assign) NSInteger futureSliderValue; | ||
@property (nonatomic) BOOL showReviewCell; | ||
|
||
@property (weak) IBOutlet NSButton *shutdownButton; | ||
@property (weak) IBOutlet NSButton *preferencesButton; | ||
@property (weak) IBOutlet NSSlider *futureSlider; | ||
@property (weak) IBOutlet NSTableView *mainTableview; | ||
@property (weak) IBOutlet NSLayoutConstraint *scrollViewHeight; | ||
@property (nonatomic, strong) CLOneWindowController *oneWindow; | ||
|
||
- (void)updateDefaultPreferences; | ||
- (void)showOptions:(BOOL)value; | ||
- (void)removeContextHelpForSlider; | ||
- (void)updatePanelColor; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
// | ||
// CLParentPanelController.m | ||
// Clocker | ||
// | ||
// Created by Abhishek Banthia on 4/4/16. | ||
// | ||
// | ||
|
||
#import "CLParentPanelController.h" | ||
#import "CLRatingCellView.h" | ||
#import "CLTimezoneData.h" | ||
#import "CommonStrings.h" | ||
#import "CLOneWindowController.h" | ||
|
||
@interface CLParentPanelController () | ||
|
||
@end | ||
|
||
@implementation CLParentPanelController | ||
|
||
- (void)awakeFromNib | ||
{ | ||
[super awakeFromNib]; | ||
|
||
if ([[[NSUserDefaults standardUserDefaults] objectForKey:CLThemeKey] isKindOfClass:[NSString class]]) { | ||
[[NSUserDefaults standardUserDefaults] setObject:@0 forKey:CLThemeKey]; | ||
} | ||
|
||
NSNumber *theme = [[NSUserDefaults standardUserDefaults] objectForKey:CLThemeKey]; | ||
|
||
if (theme.integerValue == 1) | ||
{ | ||
self.shutdownButton.image = [NSImage imageNamed:@"PowerIcon-White"]; | ||
self.preferencesButton.image = [NSImage imageNamed:@"Settings-White"]; | ||
} | ||
else | ||
{ | ||
self.shutdownButton.image = [NSImage imageNamed:@"PowerIcon"]; | ||
self.preferencesButton.image = [NSImage imageNamed:NSImageNameActionTemplate]; | ||
} | ||
|
||
self.mainTableview.selectionHighlightStyle = NSTableViewSelectionHighlightStyleNone; | ||
|
||
|
||
} | ||
|
||
- (void) updateDefaultPreferences | ||
{ | ||
|
||
NSArray *defaultZones = [[NSUserDefaults standardUserDefaults] objectForKey:CLDefaultPreferenceKey]; | ||
|
||
self.defaultPreferences = self.defaultPreferences == nil ? [[NSMutableArray alloc] initWithArray:defaultZones] : [NSMutableArray arrayWithArray:defaultZones]; | ||
|
||
self.scrollViewHeight.constant = self.showReviewCell ? | ||
(self.defaultPreferences.count+1)*55+40 : self.defaultPreferences.count*55 + 30; | ||
|
||
if (self.defaultPreferences.count == 1) { | ||
self.futureSlider.hidden = YES; | ||
} | ||
else | ||
{ | ||
self.futureSlider.hidden = NO; | ||
} | ||
|
||
[self updatePanelColor]; | ||
} | ||
|
||
- (void)updatePanelColor | ||
{ | ||
NSNumber *theme = [[NSUserDefaults standardUserDefaults] objectForKey:CLThemeKey]; | ||
if (theme.integerValue == 1) | ||
{ | ||
[self.mainTableview setBackgroundColor:[NSColor blackColor]]; | ||
self.window.alphaValue = 0.90; | ||
} | ||
else | ||
{ | ||
[self.mainTableview setBackgroundColor:[NSColor whiteColor]]; | ||
self.window.alphaValue = 1; | ||
} | ||
} | ||
|
||
|
||
- (void)showOptions:(BOOL)value | ||
{ | ||
|
||
if (self.defaultPreferences.count == 0) | ||
{ | ||
value = YES; | ||
} | ||
|
||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
self.shutdownButton.hidden = !value; | ||
self.preferencesButton.hidden = !value; | ||
|
||
}); | ||
|
||
} | ||
|
||
|
||
- (IBAction)sliderMoved:(id)sender | ||
{ | ||
NSCalendar *currentCalendar = [NSCalendar autoupdatingCurrentCalendar]; | ||
NSDate *newDate = [currentCalendar dateByAddingUnit:NSCalendarUnitMinute | ||
value:self.futureSliderValue | ||
toDate:[NSDate date] | ||
options:kNilOptions]; | ||
|
||
self.dateFormatter.dateStyle = kCFDateFormatterNoStyle; | ||
self.dateFormatter.timeStyle = kCFDateFormatterShortStyle; | ||
|
||
NSString *relativeDate = [currentCalendar isDateInToday:newDate] ? @"Today" : @"Tomorrow"; | ||
|
||
NSString *helper = [self.dateFormatter stringFromDate:newDate]; | ||
|
||
NSHelpManager *helpManager = [NSHelpManager sharedHelpManager]; | ||
|
||
NSPoint pointInScreen = [NSEvent mouseLocation]; | ||
pointInScreen.y -= 5; | ||
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ %@", relativeDate, helper]]; | ||
[NSHelpManager setContextHelpModeActive:YES]; | ||
[helpManager setContextHelp:attributedString forObject:self.futureSlider]; | ||
[helpManager showContextHelpForObject:self.futureSlider locationHint:pointInScreen]; | ||
|
||
[self.mainTableview reloadData]; | ||
} | ||
|
||
- (void)removeContextHelpForSlider | ||
{ | ||
NSEvent *newEvent = [NSEvent mouseEventWithType:NSLeftMouseDown | ||
location:self.window.mouseLocationOutsideOfEventStream | ||
modifierFlags:0 | ||
timestamp:0 | ||
windowNumber:self.window.windowNumber | ||
context:self.window.graphicsContext | ||
eventNumber:0 | ||
clickCount:1 | ||
pressure:0]; | ||
[NSApp postEvent:newEvent atStart:NO]; | ||
newEvent = [NSEvent mouseEventWithType:NSLeftMouseUp | ||
location:self.window.mouseLocationOutsideOfEventStream | ||
modifierFlags:0 | ||
timestamp:0 | ||
windowNumber:self.window.windowNumber | ||
context:self.window.graphicsContext | ||
eventNumber:0 | ||
clickCount:1 | ||
pressure:0]; | ||
|
||
[NSApp postEvent:newEvent atStart:NO]; | ||
} | ||
|
||
#pragma mark - | ||
#pragma mark Preferences Target-Action | ||
#pragma mark - | ||
|
||
- (IBAction)openPreferences:(id)sender | ||
{ | ||
self.oneWindow = [CLOneWindowController sharedWindow]; | ||
[self.oneWindow showWindow:nil]; | ||
[NSApp activateIgnoringOtherApps:YES]; | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.