Author: fredkiefer
Date: Sun Jan  8 20:33:32 2017
New Revision: 40285

URL: http://svn.gna.org/viewcvs/gnustep?rev=40285&view=rev
Log:
        * Source/NSMenu.m (-_isVisible, -_isMain): Add two helper
        methods. And make sure we update the menu items before display and
        keyEquivalent processing.

Modified:
    libs/gui/trunk/ChangeLog
    libs/gui/trunk/Source/NSMenu.m

Modified: libs/gui/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/ChangeLog?rev=40285&r1=40284&r2=40285&view=diff
==============================================================================
--- libs/gui/trunk/ChangeLog    (original)
+++ libs/gui/trunk/ChangeLog    Sun Jan  8 20:33:32 2017
@@ -1,3 +1,9 @@
+2017-01-08 Fred Kiefer <[email protected]>
+
+       * Source/NSMenu.m (-_isVisible, -_isMain): Add two helper
+       methods. And make sure we update the menu items before display and
+       keyEquivalent processing.
+
 2016-12-31 Fred Kiefer <[email protected]>
 
        * Source/NSMenu.m (-update): Update only visible submenus.

Modified: libs/gui/trunk/Source/NSMenu.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/NSMenu.m?rev=40285&r1=40284&r2=40285&view=diff
==============================================================================
--- libs/gui/trunk/Source/NSMenu.m      (original)
+++ libs/gui/trunk/Source/NSMenu.m      Sun Jan  8 20:33:32 2017
@@ -144,6 +144,8 @@
 - (void) _setGeometry;
 - (void) _updateUserDefaults: (id) notification;
 - (void) _organizeMenu;
+- (BOOL) _isVisible;
+- (BOOL) _isMain;
 
 @end
 
@@ -157,9 +159,7 @@
 - (BOOL) canBecomeKeyWindow
 {
   /* See [NSWindow-_lossOfKeyOrMainWindow] */
-  if (self == (NSMenuPanel *)[[NSApp mainMenu] window])
-    return YES;
-  return NO;
+  return [_the_menu _isMain];
 }
 
 - (void) orderFrontRegardless
@@ -199,7 +199,7 @@
     }
   if (_superMenu == nil)
     {
-      if ([NSApp mainMenu] == self)
+      if ([self _isMain])
        {
          return @"\033";       /* Root menu.   */
        }
@@ -260,7 +260,7 @@
   NSString *servicesString = _(@"Services");
   int i;
 
-  if ([self isEqual: [NSApp mainMenu]] == YES)
+  if ([self _isMain])
     {
       NSString *appTitle;
       NSMenu *appMenu;
@@ -537,7 +537,7 @@
             menuLocations = nil;
 
           if ([_aWindow isVisible]
-              && ([self isTornOff] || ([NSApp mainMenu] == self)))
+              && ([self isTornOff] || ([self _isMain])))
             {
               if (menuLocations == nil)
                 {
@@ -572,6 +572,16 @@
                            forEvent: theEvent];
 }
 
+- (BOOL) _isVisible
+{
+  return [_aWindow isVisible] || [_bWindow isVisible];
+}
+
+- (BOOL) _isMain
+{
+  return [NSApp mainMenu] == self;
+}
+
 @end
 
 
@@ -712,7 +722,7 @@
  - (void) menuChanged
 {
   // propagate notification up to the main menu
-  if (self == [NSApp mainMenu])
+  if ([self _isMain])
     _menu.mainMenuChanged = YES;
   else
     [[self supermenu] menuChanged];
@@ -1087,7 +1097,7 @@
 
 - (void) _updateSubmenu
 {
-  if ([self isAttached] || [self isTornOff])
+  if ([self _isVisible])
     {
       // Update the menu items when the menu is visible...
       [self update];
@@ -1252,7 +1262,7 @@
       _menu.mainMenuChanged = NO;
     }
 
-  if (_menu.needsSizing && ([_aWindow isVisible] || [_bWindow isVisible]))
+  if (_menu.needsSizing && [self _isVisible])
     {
       NSDebugLLog (@"NSMenu", @" Calling Size To Fit (A)");
       [self sizeToFit];
@@ -1272,14 +1282,21 @@
   NSUInteger modifiers = [theEvent modifierFlags];
   NSString *keyEquivalent = [theEvent charactersIgnoringModifiers];
   NSUInteger relevantModifiersMask = NSCommandKeyMask | NSAlternateKeyMask | 
NSControlKeyMask;
+
+  if ((type != NSKeyDown && type != NSKeyUp) || [keyEquivalent length] == 0)
+    return NO;
+             
   /* Take shift key into account only for control keys and arrow and function 
keys */
   if ((modifiers & NSFunctionKeyMask)
       || ([keyEquivalent length] > 0 && [[NSCharacterSet controlCharacterSet] 
characterIsMember:[keyEquivalent characterAtIndex:0]]))
     relevantModifiersMask |= NSShiftKeyMask;
 
-  if ((type != NSKeyDown && type != NSKeyUp) || [keyEquivalent length] == 0)
-    return NO;
-             
+  if (![self _isVisible])
+    {
+      // Need to enable items as the automatic mechanism is switched off for 
invisible menus 
+      [self update];
+    }
+  
   for (i = 0; i < count; i++)
     {
       NSMenuItem *item = [_items objectAtIndex: i];
@@ -1377,7 +1394,7 @@
 
   _menu.needsSizing = YES;
   [(NSMenuView*)_view setNeedsSizing: YES];
-  if ([_aWindow isVisible] || [_bWindow isVisible])
+  if ([self _isVisible])
     {
       [self sizeToFit];
     }
@@ -1618,8 +1635,7 @@
       [encoder encodeObject: _title forKey: @"NSTitle"];
       [encoder encodeObject: _items forKey: @"NSMenuItems"];
       
-      // if there is no supermenu, make it the main menu.
-      if ([self supermenu] == nil && ![self _ownedByPopUp])
+      if ([self _isMain])
        {
          [encoder encodeObject: @"_NSMainMenu" forKey: @"NSName"];
        }
@@ -1782,7 +1798,7 @@
     {
       return;
     }
-  if ([NSApp mainMenu] != self)
+  if (![self _isMain])
     {
       NSString         *key;
 
@@ -1821,7 +1837,7 @@
 
 - (void) _showOnActivateApp: (NSNotification*)notification
 {
-  if ([NSApp mainMenu] == self)
+  if ([self _isMain])
   {
     [self display];
     // we must make sure that any attached submenu is visible too.
@@ -1861,6 +1877,7 @@
                    @"trying to display while already displayed transient");
     }
 
+  [self update];
   if (_menu.needsSizing)
     {
       [self sizeToFit];
@@ -2138,7 +2155,7 @@
   // Don't move the main menu bar in Macintosh interface style, this is
   // annoying (in particular, since the effective screen range is reduced
   // by the height of the menu bar!)
-  if (style == NSMacintoshInterfaceStyle && [self isEqual: [NSApp mainMenu]])
+  if (style == NSMacintoshInterfaceStyle && [self _isMain])
     return;
 
   // 1 - determine the amount we need to shift in the y direction.


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to