Fixed menu shortcut not working in fullscreen (close #537)

This commit is contained in:
Marco Antognini 2014-04-21 19:37:56 +02:00
parent c222c28aa7
commit 7f0f89bac9
2 changed files with 58 additions and 0 deletions

View File

@ -65,6 +65,26 @@
////////////////////////////////////////////////////////////
-(void)keyDown:(NSEvent*)theEvent;
////////////////////////////////////////////////////////////
/// \brief This action method simulates the user clicking the close button
///
/// Override NSWindow implementation, see implementation for details
///
/// \param sender The messages sender
///
////////////////////////////////////////////////////////////
-(void)performClose:(id)sender;
////////////////////////////////////////////////////////////
/// \brief Enabling or disabling a specific menu item
///
/// \param menuItem An NSMenuItem object that represents the menu item
///
/// \return YES to enable menuItem, NO to disable it.
///
////////////////////////////////////////////////////////////
-(BOOL)validateMenuItem:(NSMenuItem*)menuItem;
@end

View File

@ -59,6 +59,44 @@
}
////////////////////////////////////////////////////////
-(void)performClose:(id)sender
{
// From Apple documentation:
//
// > If the windows delegate or the window itself implements windowShouldClose:,
// > that message is sent with the window as the argument. (Only one such message is sent;
// > if both the delegate and the NSWindow object implement the method, only the delegate
// > receives the message.) If the windowShouldClose: method returns NO, the window isnt
// > closed. If it returns YES, or if it isnt implemented, performClose: invokes the
// > close method to close the window.
// >
// > If the window doesnt have a close button or cant be closed (for example, if the
// > delegate replies NO to a windowShouldClose: message), the system emits the alert sound.
//
// The last paragraph is problematic for SFML fullscreen window since they don't have
// a close button (style is NSBorderlessWindowMask). So we reimplement this function.
BOOL shouldClose = NO;
if ([self delegate] && [[self delegate] respondsToSelector:@selector(windowShouldClose:)])
shouldClose = [[self delegate] windowShouldClose:sender];
// else if ([self respondsToSelector:@selector(windowShouldClose:)])
// shouldClose = [self windowShouldClose:sender];
// error: no visible @interface for 'SFWindow' declares the selector 'windowShouldClose:'
if (shouldClose)
[self close];
}
////////////////////////////////////////////////////////
-(BOOL)validateMenuItem:(NSMenuItem*)menuItem
{
return [menuItem action] == @selector(performClose:);
}
@end