diff --git a/CLCMenuExtra/CLCMenuExtra/CLCMenuExtraView.h b/CLCMenuExtra/CLCMenuExtra/CLCMenuExtraView.h index a9e4d28..40d9c57 100644 --- a/CLCMenuExtra/CLCMenuExtra/CLCMenuExtraView.h +++ b/CLCMenuExtra/CLCMenuExtra/CLCMenuExtraView.h @@ -16,7 +16,7 @@ { } -@property(strong, nonatomic) CLCPopoverViewController *control; +@property(strong, nonatomic) NSPopover *popover; @property(strong, nonatomic) CLCCalendar *calendar; @property BOOL active; diff --git a/CLCMenuExtra/CLCMenuExtra/CLCMenuExtraView.m b/CLCMenuExtra/CLCMenuExtra/CLCMenuExtraView.m index da19e6a..f75046b 100644 --- a/CLCMenuExtra/CLCMenuExtra/CLCMenuExtraView.m +++ b/CLCMenuExtra/CLCMenuExtra/CLCMenuExtraView.m @@ -7,7 +7,7 @@ // #import "CLCMenuExtraView.h" -#import "CLCPopoverViewController.h" +#import "CLCPopController.h" #import "CLCCalendar.h" @interface CLCMenuExtraView() @@ -20,7 +20,7 @@ @interface CLCMenuExtraView() @implementation CLCMenuExtraView -@synthesize control; +@synthesize popover; @synthesize active; @synthesize calendar; @@ -40,7 +40,7 @@ - (void)drawRect:(CGRect)rect // init the status item popup if(self.active) { - [[NSColor blueColor] set]; + [[NSColor brownColor] set]; } else { [[NSColor blackColor] set]; } @@ -84,21 +84,25 @@ - (void)mouseDown:(id)arg1 } } +- (void) setupPopover +{ + if(! self.popover) + { + self.popover = [[NSPopover alloc] init]; + self.popover.contentViewController = [[CLCPopController alloc] initWithNibName:@"CLCPopController" bundle:_menuExtra.bundle]; + } +} - (void) showPopover { self.active = true; - if(!self.control) - { - self.control = [[CLCPopoverViewController alloc] initWithNibName:@"CLCPopoverViewController" bundle:nil]; - } - if(self.control && self.control.popover) - { -// [self.control.popover showRelativeToRect:[self bounds] ofView:self preferredEdge:NSMaxYEdge]; - } - - + [self setupPopover]; + + [self.popover showRelativeToRect:[self bounds] + ofView:self + preferredEdge:NSMinYEdge]; + // if user click area outside of our menulet, hide the popover _popoverTransiencyMonitor = [NSEvent addGlobalMonitorForEventsMatchingMask:NSLeftMouseDownMask|NSRightMouseDownMask handler:^(NSEvent* event) { [self hidePopover]; @@ -112,6 +116,8 @@ - (void) hidePopover { self.active = false; + [self.popover performClose:nil]; + // remove the monitor [NSEvent removeMonitor:_popoverTransiencyMonitor]; diff --git a/CLCMenuExtra/CLCMenuExtra/CLCPopoverViewController.h b/CLCMenuExtra/CLCMenuExtra/CLCPopController.h similarity index 55% rename from CLCMenuExtra/CLCMenuExtra/CLCPopoverViewController.h rename to CLCMenuExtra/CLCMenuExtra/CLCPopController.h index 8ce5ebd..2a8da32 100644 --- a/CLCMenuExtra/CLCMenuExtra/CLCPopoverViewController.h +++ b/CLCMenuExtra/CLCMenuExtra/CLCPopController.h @@ -1,5 +1,5 @@ // -// CLCPopoverViewController.h +// CLCPopController.h // chinese lunar calendar // // Created by Zhengfa DANG on 9/25/14. @@ -8,10 +8,6 @@ #import -@interface CLCPopoverViewController : NSViewController -{ -} - -@property (retain) NSPopover *popover; +@interface CLCPopController : NSViewController @end diff --git a/CLCMenuExtra/CLCMenuExtra/CLCPopoverViewController.m b/CLCMenuExtra/CLCMenuExtra/CLCPopController.m similarity index 58% rename from CLCMenuExtra/CLCMenuExtra/CLCPopoverViewController.m rename to CLCMenuExtra/CLCMenuExtra/CLCPopController.m index 222e220..b5d944a 100644 --- a/CLCMenuExtra/CLCMenuExtra/CLCPopoverViewController.m +++ b/CLCMenuExtra/CLCMenuExtra/CLCPopController.m @@ -1,32 +1,33 @@ // -// CLCPopoverViewController.m +// CLCPopController.m // chinese lunar calendar // // Created by Zhengfa DANG on 9/25/14. // Copyright (c) 2014 Zhengfa. All rights reserved. // -#import "CLCPopoverViewController.h" +#import "CLCPopController.h" -@interface CLCPopoverViewController () +@interface CLCPopController () @end -@implementation CLCPopoverViewController +@implementation CLCPopController -@synthesize popover; +- (void)viewDidLoad { +// [super viewDidLoad]; + // Do view setup here. +} - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Initialization code here. - self.popover = [[NSPopover alloc] init]; - self.popover.contentViewController = self; } + return self; } - @end diff --git a/CLCMenuExtra/CLCMenuExtra/CLCPopoverViewController.xib b/CLCMenuExtra/CLCMenuExtra/CLCPopController.xib similarity index 58% rename from CLCMenuExtra/CLCMenuExtra/CLCPopoverViewController.xib rename to CLCMenuExtra/CLCMenuExtra/CLCPopController.xib index 2740cf0..3a3e4cf 100644 --- a/CLCMenuExtra/CLCMenuExtra/CLCPopoverViewController.xib +++ b/CLCMenuExtra/CLCMenuExtra/CLCPopController.xib @@ -4,35 +4,25 @@ - + - + - - - + + + - diff --git a/CLCMenuExtra/chinese lunar calendar.xcodeproj/project.pbxproj b/CLCMenuExtra/chinese lunar calendar.xcodeproj/project.pbxproj index 654ed98..33bdbde 100644 --- a/CLCMenuExtra/chinese lunar calendar.xcodeproj/project.pbxproj +++ b/CLCMenuExtra/chinese lunar calendar.xcodeproj/project.pbxproj @@ -11,9 +11,9 @@ 691657AC19D3F8410086C6D9 /* cloud@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 691657A819D3F8410086C6D9 /* cloud@2x.png */; }; 691657AD19D3F8410086C6D9 /* cloudgrey.png in Resources */ = {isa = PBXBuildFile; fileRef = 691657A919D3F8410086C6D9 /* cloudgrey.png */; }; 691657AE19D3F8410086C6D9 /* cloudgrey@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 691657AA19D3F8410086C6D9 /* cloudgrey@2x.png */; }; + 6985D80B19D4423F00343F35 /* CLCPopController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6985D80919D4423F00343F35 /* CLCPopController.m */; }; + 6985D80C19D4423F00343F35 /* CLCPopController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6985D80A19D4423F00343F35 /* CLCPopController.xib */; }; 69C45CD219D3B17D004AC6DD /* CLCCalendar.m in Sources */ = {isa = PBXBuildFile; fileRef = 69C45CD119D3B17D004AC6DD /* CLCCalendar.m */; }; - 69C45CD619D3B230004AC6DD /* CLCPopoverViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 69C45CD419D3B230004AC6DD /* CLCPopoverViewController.m */; }; - 69C45CD719D3B230004AC6DD /* CLCPopoverViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 69C45CD519D3B230004AC6DD /* CLCPopoverViewController.xib */; }; 69D8B52019D27A3E00A75B32 /* SystemUIPlugin.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 69D8B51F19D27A3E00A75B32 /* SystemUIPlugin.framework */; }; 69D8B52419D27AF900A75B32 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 69D8B52319D27AF900A75B32 /* Cocoa.framework */; }; 69D8B53D19D290E400A75B32 /* CLCMenuExtra.m in Sources */ = {isa = PBXBuildFile; fileRef = 69D8B53A19D290E400A75B32 /* CLCMenuExtra.m */; }; @@ -25,11 +25,11 @@ 691657A819D3F8410086C6D9 /* cloud@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "cloud@2x.png"; path = "CLCMenuExtra/Resources/cloud@2x.png"; sourceTree = ""; }; 691657A919D3F8410086C6D9 /* cloudgrey.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = cloudgrey.png; path = CLCMenuExtra/Resources/cloudgrey.png; sourceTree = ""; }; 691657AA19D3F8410086C6D9 /* cloudgrey@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "cloudgrey@2x.png"; path = "CLCMenuExtra/Resources/cloudgrey@2x.png"; sourceTree = ""; }; + 6985D80819D4423F00343F35 /* CLCPopController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CLCPopController.h; path = CLCMenuExtra/CLCPopController.h; sourceTree = ""; }; + 6985D80919D4423F00343F35 /* CLCPopController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CLCPopController.m; path = CLCMenuExtra/CLCPopController.m; sourceTree = ""; }; + 6985D80A19D4423F00343F35 /* CLCPopController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = CLCPopController.xib; path = CLCMenuExtra/CLCPopController.xib; sourceTree = ""; }; 69C45CD019D3B17D004AC6DD /* CLCCalendar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CLCCalendar.h; path = CLCMenuExtra/CLCCalendar.h; sourceTree = ""; }; 69C45CD119D3B17D004AC6DD /* CLCCalendar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CLCCalendar.m; path = CLCMenuExtra/CLCCalendar.m; sourceTree = ""; }; - 69C45CD319D3B230004AC6DD /* CLCPopoverViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CLCPopoverViewController.h; path = CLCMenuExtra/CLCPopoverViewController.h; sourceTree = ""; }; - 69C45CD419D3B230004AC6DD /* CLCPopoverViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CLCPopoverViewController.m; path = CLCMenuExtra/CLCPopoverViewController.m; sourceTree = ""; }; - 69C45CD519D3B230004AC6DD /* CLCPopoverViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = CLCPopoverViewController.xib; path = CLCMenuExtra/CLCPopoverViewController.xib; sourceTree = ""; }; 69D8B51519D278A900A75B32 /* CLCMenuExtra.menu */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CLCMenuExtra.menu; sourceTree = BUILT_PRODUCTS_DIR; }; 69D8B51919D278A900A75B32 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 69D8B51F19D27A3E00A75B32 /* SystemUIPlugin.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = SystemUIPlugin.framework; sourceTree = ""; }; @@ -120,9 +120,8 @@ 69D8B53A19D290E400A75B32 /* CLCMenuExtra.m */, 69D8B53B19D290E400A75B32 /* CLCMenuExtraView.h */, 69D8B53C19D290E400A75B32 /* CLCMenuExtraView.m */, - 69C45CD319D3B230004AC6DD /* CLCPopoverViewController.h */, - 69C45CD419D3B230004AC6DD /* CLCPopoverViewController.m */, - 69C45CD519D3B230004AC6DD /* CLCPopoverViewController.xib */, + 6985D80819D4423F00343F35 /* CLCPopController.h */, + 6985D80919D4423F00343F35 /* CLCPopController.m */, 69C45CD019D3B17D004AC6DD /* CLCCalendar.h */, 69C45CD119D3B17D004AC6DD /* CLCCalendar.m */, ); @@ -132,6 +131,7 @@ 69D8B53F19D2946300A75B32 /* Resources */ = { isa = PBXGroup; children = ( + 6985D80A19D4423F00343F35 /* CLCPopController.xib */, 691657A719D3F8410086C6D9 /* cloud.png */, 691657A819D3F8410086C6D9 /* cloud@2x.png */, 691657A919D3F8410086C6D9 /* cloudgrey.png */, @@ -196,7 +196,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 69C45CD719D3B230004AC6DD /* CLCPopoverViewController.xib in Resources */, + 6985D80C19D4423F00343F35 /* CLCPopController.xib in Resources */, 691657AB19D3F8410086C6D9 /* cloud.png in Resources */, 691657AE19D3F8410086C6D9 /* cloudgrey@2x.png in Resources */, 691657AD19D3F8410086C6D9 /* cloudgrey.png in Resources */, @@ -212,8 +212,8 @@ buildActionMask = 2147483647; files = ( 69C45CD219D3B17D004AC6DD /* CLCCalendar.m in Sources */, - 69C45CD619D3B230004AC6DD /* CLCPopoverViewController.m in Sources */, 69D8B53D19D290E400A75B32 /* CLCMenuExtra.m in Sources */, + 6985D80B19D4423F00343F35 /* CLCPopController.m in Sources */, 69D8B53E19D290E400A75B32 /* CLCMenuExtraView.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/CLCMenuExtra/chinese lunar calendar.xcodeproj/project.xcworkspace/xcuserdata/zfdang.xcuserdatad/UserInterfaceState.xcuserstate b/CLCMenuExtra/chinese lunar calendar.xcodeproj/project.xcworkspace/xcuserdata/zfdang.xcuserdatad/UserInterfaceState.xcuserstate index 0656dfc..03ce865 100644 Binary files a/CLCMenuExtra/chinese lunar calendar.xcodeproj/project.xcworkspace/xcuserdata/zfdang.xcuserdatad/UserInterfaceState.xcuserstate and b/CLCMenuExtra/chinese lunar calendar.xcodeproj/project.xcworkspace/xcuserdata/zfdang.xcuserdatad/UserInterfaceState.xcuserstate differ