Daemon status popup works

Change-Id: Ic58070ce80578593053c6f4d68df6c785dff7442
diff --git a/osx/MainMenu.xib b/osx/MainMenu.xib
index 5ebd3ef..0ad9c80 100644
--- a/osx/MainMenu.xib
+++ b/osx/MainMenu.xib
@@ -14,7 +14,10 @@
         <customObject id="494" customClass="MenuDelegate">
             <connections>
                 <outlet property="connectionStatus" destination="yhj-L6-nZL" id="v5Y-5B-2aW"/>
+                <outlet property="connectionStatusText" destination="EUJ-R2-Os4" id="2pC-dc-tng"/>
+                <outlet property="connectionStatusView" destination="24d-37-bzd" id="AYC-I7-1KX"/>
                 <outlet property="daemonStatus" destination="Tap-5m-ZRP" id="yrK-Nr-zKm"/>
+                <outlet property="daemonStatusView" destination="NBE-Gf-zLc" id="91G-ey-DeA"/>
                 <outlet property="routingStatus" destination="Vc8-fu-RAY" id="GVC-zB-uSO"/>
                 <outlet property="statusMenu" destination="ovl-jc-kIR" id="dlz-Qz-Ia0"/>
                 <outlet property="statusPopover" destination="eAA-vc-IW1" id="bD5-Rp-Syx"/>
@@ -58,6 +61,9 @@
                     <modifierMask key="keyEquivalentModifierMask"/>
                 </menuItem>
             </items>
+            <connections>
+                <outlet property="delegate" destination="494" id="AgM-WF-ty0"/>
+            </connections>
         </menu>
         <viewController id="QoL-hX-ilM" userLabel="Popover View Controller">
             <connections>
@@ -84,5 +90,35 @@
                 </textField>
             </subviews>
         </customView>
+        <customView id="NBE-Gf-zLc">
+            <rect key="frame" x="0.0" y="0.0" width="150" height="20"/>
+            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+            <subviews>
+                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="T4F-W2-p5Y">
+                    <rect key="frame" x="19" y="2" width="46" height="18"/>
+                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+                    <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Status" id="3iV-EO-iJG">
+                        <font key="font" size="14" name="LucidaGrande"/>
+                        <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+                        <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+                    </textFieldCell>
+                </textField>
+            </subviews>
+        </customView>
+        <customView id="24d-37-bzd">
+            <rect key="frame" x="0.0" y="0.0" width="155" height="20"/>
+            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+            <subviews>
+                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="EUJ-R2-Os4">
+                    <rect key="frame" x="0.0" y="0.0" width="155" height="20"/>
+                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+                    <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Disconnected" drawsBackground="YES" id="4JT-Ml-4Z3">
+                        <font key="font" size="14" name="LucidaGrande"/>
+                        <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+                        <color key="backgroundColor" red="0.28345577993626336" green="0.28865913722826086" blue="0.27492015640756962" alpha="1" colorSpace="calibratedRGB"/>
+                    </textFieldCell>
+                </textField>
+            </subviews>
+        </customView>
     </objects>
 </document>
\ No newline at end of file
diff --git a/osx/menu-delegate.h b/osx/menu-delegate.h
index 578a4a5..ca6e133 100644
--- a/osx/menu-delegate.h
+++ b/osx/menu-delegate.h
@@ -23,8 +23,14 @@
     IBOutlet NSMenuItem *trafficMap;
   
     BOOL daemonStarted;
+  
+    IBOutlet NSView *daemonStatusView;
+  
+    IBOutlet NSView *connectionStatusView;
+    IBOutlet NSTextField *connectionStatusText;
 }
 
+-(void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item;
 -(IBAction)switchDaemon:(id)sender;
 -(IBAction)openDaemonStatus:(id)sender;
 -(IBAction)openRoutingStatusPage:(id)sender;
diff --git a/osx/menu-delegate.mm b/osx/menu-delegate.mm
index 35e3881..1e2b1c1 100644
--- a/osx/menu-delegate.mm
+++ b/osx/menu-delegate.mm
@@ -31,6 +31,13 @@
   [statusItem setTitle:@""];
   [statusItem setImage:menuIcon];
   
+  
+  
+  [connectionStatus setView: connectionStatusView];
+  [connectionStatus setTarget:self];
+  [daemonStatus setView: daemonStatusView];
+  [daemonStatus setTarget:self];
+
   daemonStarted = false;
 }
 
@@ -40,7 +47,8 @@
   {
     daemonStarted = false;
     [sender setTitle:@"Start"];
-    [connectionStatus setTitle:@"NDN disconnected"];
+    //[connectionStatus setTitle:@"NDN disconnected"];
+    [connectionStatusText setStringValue:@"Disconnected"];
     
     NSBundle *bundle = [NSBundle bundleForClass:[self class]];
     NSString *path = [bundle pathForResource:@"FlatDisconnected" ofType:@"png"];
@@ -51,7 +59,8 @@
   {
     daemonStarted = true;
     [sender setTitle:@"Stop"];
-    [connectionStatus setTitle:@"NDN connected"];
+    //[connectionStatus setTitle:@"NDN connected"];
+    [connectionStatusText setStringValue:@"Connected"];
     
     NSBundle *bundle = [NSBundle bundleForClass:[self class]];
     NSString *path = [bundle pathForResource:@"FlatConnected" ofType:@"png"];
@@ -62,11 +71,6 @@
 
 -(IBAction)openDaemonStatus:(id)sender
 {
-  [statusPopover showRelativeToRect:[[daemonStatus view] bounds]
-                 ofView:[daemonStatus view]
-                 preferredEdge:NSMinXEdge];
-
-  //[statusPopover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
 }
 
 -(IBAction)openRoutingStatusPage:(id)sender
@@ -84,4 +88,20 @@
   [[NSWorkspace sharedWorkspace] openURL: pageURL];
 }
 
+-(void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item
+{
+
+  if( ([item view]!=nil) && (item == daemonStatus) )
+  {
+    [statusPopover showRelativeToRect:[[item view] bounds]
+                 ofView:[item view]
+                 preferredEdge:NSMinXEdge];
+    
+  }
+  else
+  {
+    [statusPopover performClose:nil];
+  }
+}
+
 @end