|
|
@ -36,6 +36,7 @@ |
|
|
|
#import "CLTimezoneCellView.h" |
|
|
|
#import "CLTimezoneCellView.h" |
|
|
|
#import "DateTools.h" |
|
|
|
#import "DateTools.h" |
|
|
|
#import "CLTimezoneData.h" |
|
|
|
#import "CLTimezoneData.h" |
|
|
|
|
|
|
|
#import "Panel.h" |
|
|
|
|
|
|
|
|
|
|
|
#define OPEN_DURATION .15 |
|
|
|
#define OPEN_DURATION .15 |
|
|
|
#define CLOSE_DURATION .1 |
|
|
|
#define CLOSE_DURATION .1 |
|
|
@ -59,6 +60,8 @@ NSString *const CLPanelNibIdentifier = @"Panel"; |
|
|
|
NSString *const CLRatingCellViewIdentifier = @"ratingCellView"; |
|
|
|
NSString *const CLRatingCellViewIdentifier = @"ratingCellView"; |
|
|
|
NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell"; |
|
|
|
NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static PanelController *sharedPanel = nil; |
|
|
|
|
|
|
|
|
|
|
|
@implementation PanelController |
|
|
|
@implementation PanelController |
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - |
|
|
|
#pragma mark - |
|
|
@ -80,6 +83,8 @@ NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell"; |
|
|
|
{ |
|
|
|
{ |
|
|
|
[super awakeFromNib]; |
|
|
|
[super awakeFromNib]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.futureSlider.continuous = YES; |
|
|
|
|
|
|
|
|
|
|
|
if (!self.dateFormatter) |
|
|
|
if (!self.dateFormatter) |
|
|
|
{ |
|
|
|
{ |
|
|
|
self.dateFormatter = [NSDateFormatter new]; |
|
|
|
self.dateFormatter = [NSDateFormatter new]; |
|
|
@ -99,6 +104,7 @@ NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell"; |
|
|
|
self.mainTableview.selectionHighlightStyle = NSTableViewSelectionHighlightStyleNone; |
|
|
|
self.mainTableview.selectionHighlightStyle = NSTableViewSelectionHighlightStyleNone; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NSPanel *panel = (id)[self window]; |
|
|
|
NSPanel *panel = (id)[self window]; |
|
|
|
[panel setAcceptsMouseMovedEvents:YES]; |
|
|
|
[panel setAcceptsMouseMovedEvents:YES]; |
|
|
|
[panel setLevel:NSPopUpMenuWindowLevel]; |
|
|
|
[panel setLevel:NSPopUpMenuWindowLevel]; |
|
|
@ -112,17 +118,82 @@ NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell"; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ (instancetype)sharedPanel |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (sharedPanel == nil) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
/*Using a thread safe pattern*/ |
|
|
|
|
|
|
|
static dispatch_once_t onceToken; |
|
|
|
|
|
|
|
dispatch_once(&onceToken, ^{ |
|
|
|
|
|
|
|
sharedPanel = [[self alloc] initWithWindowNibName:@"Panel"]; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return sharedPanel; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)openAsFloatingWindow |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (self.panelWindow) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
[self.panelWindow.window makeKeyAndOrderFront:nil]; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:@1 forKey:CLShowAppInForeground]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.panelWindow = [PanelController sharedPanel]; |
|
|
|
|
|
|
|
self.panelWindow.window.level = NSFloatingWindowLevel; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.panelWindow.window.styleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask; |
|
|
|
|
|
|
|
self.panelWindow.window.titlebarAppearsTransparent = YES; |
|
|
|
|
|
|
|
self.panelWindow.window.titleVisibility = NSWindowTitleVisible; |
|
|
|
|
|
|
|
[self.panelWindow showWindow:nil]; |
|
|
|
|
|
|
|
NSSize maxWindowSize; |
|
|
|
|
|
|
|
maxWindowSize.width = self.window.frame.size.width; |
|
|
|
|
|
|
|
maxWindowSize.height = self.window.frame.size.height+40; |
|
|
|
|
|
|
|
NSSize minWindowSize; |
|
|
|
|
|
|
|
minWindowSize.width = 110; |
|
|
|
|
|
|
|
minWindowSize.height = 50; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NSSize currentSize; |
|
|
|
|
|
|
|
currentSize.width = self.window.frame.size.width; |
|
|
|
|
|
|
|
currentSize.height = self.window.frame.size.height; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.panelWindow.window.contentMaxSize = maxWindowSize; |
|
|
|
|
|
|
|
self.panelWindow.window.contentMinSize = minWindowSize; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[self.panelWindow.window setContentSize:currentSize]; |
|
|
|
|
|
|
|
[NSApp activateIgnoringOtherApps:YES]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.floatingWindowTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 |
|
|
|
|
|
|
|
target:self selector:@selector(updateTime) |
|
|
|
|
|
|
|
userInfo:nil |
|
|
|
|
|
|
|
repeats:YES]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)updateTime |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (self.panelWindow) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
[self.panelWindow.mainTableview reloadData]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - |
|
|
|
#pragma mark - |
|
|
|
#pragma mark Updating Timezones |
|
|
|
#pragma mark Updating Timezones |
|
|
|
#pragma mark - |
|
|
|
#pragma mark - |
|
|
|
|
|
|
|
|
|
|
|
- (void) updateDefaultPreferences |
|
|
|
- (void) updateDefaultPreferences |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
NSArray *defaultZones = [[NSUserDefaults standardUserDefaults] objectForKey:CLDefaultPreferenceKey]; |
|
|
|
NSArray *defaultZones = [[NSUserDefaults standardUserDefaults] objectForKey:CLDefaultPreferenceKey]; |
|
|
|
|
|
|
|
|
|
|
|
self.defaultPreferences = self.defaultPreferences == nil ? [[NSMutableArray alloc] initWithArray:defaultZones] : [NSMutableArray arrayWithArray:defaultZones]; |
|
|
|
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; |
|
|
|
self.scrollViewHeight.constant = self.showReviewCell ? |
|
|
|
|
|
|
|
(self.defaultPreferences.count+1)*55+40 : self.defaultPreferences.count*55 + 30; |
|
|
|
|
|
|
|
|
|
|
|
if (self.defaultPreferences.count == 0) { |
|
|
|
if (self.defaultPreferences.count == 0) { |
|
|
|
self.futureSlider.hidden = YES; |
|
|
|
self.futureSlider.hidden = YES; |
|
|
@ -134,6 +205,12 @@ NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell"; |
|
|
|
self.sliderLabel.hidden = NO; |
|
|
|
self.sliderLabel.hidden = NO; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//hide the label when show review cell is shown so that the Main Panel looks cleaner |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (self.showReviewCell) { |
|
|
|
|
|
|
|
self.sliderLabel.hidden = YES; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - Public accessors |
|
|
|
#pragma mark - Public accessors |
|
|
@ -157,7 +234,27 @@ NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell"; |
|
|
|
|
|
|
|
|
|
|
|
- (void)windowWillClose:(NSNotification *)notification |
|
|
|
- (void)windowWillClose:(NSNotification *)notification |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if ([notification.object isKindOfClass:[Panel class]]) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (NSWindow *currentWindow in [NSApplication sharedApplication].windows) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if ([currentWindow.windowController isKindOfClass:[CLOneWindowController class]]) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CLOneWindowController *reference = (CLOneWindowController *)currentWindow.windowController; |
|
|
|
|
|
|
|
CLAppearanceViewController *appearanceView = reference.appearanceView; |
|
|
|
|
|
|
|
[appearanceView updateState]; |
|
|
|
|
|
|
|
self.panelWindow = nil; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:@0 forKey:CLShowAppInForeground]; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
self.hasActivePanel = NO; |
|
|
|
self.hasActivePanel = NO; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void)windowDidResignKey:(NSNotification *)notification; |
|
|
|
- (void)windowDidResignKey:(NSNotification *)notification; |
|
|
@ -178,7 +275,6 @@ NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell"; |
|
|
|
CGFloat panelX = statusX - NSMinX(panelRect); |
|
|
|
CGFloat panelX = statusX - NSMinX(panelRect); |
|
|
|
|
|
|
|
|
|
|
|
self.backgroundView.arrowX = panelX; |
|
|
|
self.backgroundView.arrowX = panelX; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - Keyboard |
|
|
|
#pragma mark - Keyboard |
|
|
@ -437,8 +533,16 @@ NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell"; |
|
|
|
|
|
|
|
|
|
|
|
- (void)showOptions:(BOOL)value |
|
|
|
- (void)showOptions:(BOOL)value |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (self.showReviewCell) { |
|
|
|
|
|
|
|
self.sliderLabel.hidden = YES; |
|
|
|
|
|
|
|
self.panelWindow.sliderLabel.hidden = YES; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!self.futureSlider.isHidden) { |
|
|
|
if (!self.futureSlider.isHidden) { |
|
|
|
self.sliderLabel.hidden = !value; |
|
|
|
self.sliderLabel.hidden = !value; |
|
|
|
|
|
|
|
self.panelWindow.sliderLabel.hidden = !value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -449,7 +553,28 @@ NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell"; |
|
|
|
{ |
|
|
|
{ |
|
|
|
self.sliderLabel.hidden = YES; |
|
|
|
self.sliderLabel.hidden = YES; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (self.panelWindow.defaultPreferences.count == 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
value = YES; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!self.panelWindow.futureSlider.isHidden) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
self.panelWindow.sliderLabel.hidden = YES; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.panelWindow.shutdownButton.hidden = !value; |
|
|
|
|
|
|
|
self.panelWindow.preferencesButton.hidden = !value; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (value) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
self.panelWindow.window.styleMask = NSResizableWindowMask | NSClosableWindowMask | NSTitledWindowMask; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
self.panelWindow.window.styleMask = NSBorderlessWindowMask; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
self.shutdownButton.hidden = !value; |
|
|
|
self.shutdownButton.hidden = !value; |
|
|
|