macOS: Simplify reflection delegate handling in QCocoaApplicationDelegate
Sending a message to a nil object returns nil, so there's no reason to check the delegate before calling respondsToSelector, and we can use the implicit _cmd argument to pass along the selector for the method we're in. For applicationShouldTerminate, if there's a reflection delegate but it doesn't answer to applicationShouldTerminate it makes no sense to skip our own logic. Change-Id: Iafcd883a5c8cec1b35d2f95238de55eff060d71f Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
aa3540b7be
commit
e4e3be7501
@ -171,12 +171,8 @@ QT_USE_NAMESPACE
|
||||
// This function will only be called when NSApp is actually running.
|
||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
|
||||
{
|
||||
// The reflection delegate gets precedence
|
||||
if (reflectionDelegate) {
|
||||
if ([reflectionDelegate respondsToSelector:@selector(applicationShouldTerminate:)])
|
||||
return [reflectionDelegate applicationShouldTerminate:sender];
|
||||
return NSTerminateNow;
|
||||
}
|
||||
if ([reflectionDelegate respondsToSelector:_cmd])
|
||||
return [reflectionDelegate applicationShouldTerminate:sender];
|
||||
|
||||
if ([self canQuit]) {
|
||||
if (!startedQuit) {
|
||||
@ -282,26 +278,22 @@ QT_USE_NAMESPACE
|
||||
QWindowSystemInterface::handleFileOpenEvent(qtFileName);
|
||||
}
|
||||
|
||||
if (reflectionDelegate &&
|
||||
[reflectionDelegate respondsToSelector:@selector(application:openFiles:)])
|
||||
if ([reflectionDelegate respondsToSelector:_cmd])
|
||||
[reflectionDelegate application:sender openFiles:filenames];
|
||||
|
||||
}
|
||||
|
||||
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
|
||||
{
|
||||
// If we have a reflection delegate, that will get to call the shots.
|
||||
if (reflectionDelegate
|
||||
&& [reflectionDelegate respondsToSelector:
|
||||
@selector(applicationShouldTerminateAfterLastWindowClosed:)])
|
||||
if ([reflectionDelegate respondsToSelector:_cmd])
|
||||
return [reflectionDelegate applicationShouldTerminateAfterLastWindowClosed:sender];
|
||||
|
||||
return NO; // Someday qApp->quitOnLastWindowClosed(); when QApp and NSApp work closer together.
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(NSNotification *)notification
|
||||
{
|
||||
if (reflectionDelegate
|
||||
&& [reflectionDelegate respondsToSelector:@selector(applicationDidBecomeActive:)])
|
||||
if ([reflectionDelegate respondsToSelector:_cmd])
|
||||
[reflectionDelegate applicationDidBecomeActive:notification];
|
||||
|
||||
QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationActive);
|
||||
@ -309,8 +301,7 @@ QT_USE_NAMESPACE
|
||||
|
||||
- (void)applicationDidResignActive:(NSNotification *)notification
|
||||
{
|
||||
if (reflectionDelegate
|
||||
&& [reflectionDelegate respondsToSelector:@selector(applicationDidResignActive:)])
|
||||
if ([reflectionDelegate respondsToSelector:_cmd])
|
||||
[reflectionDelegate applicationDidResignActive:notification];
|
||||
|
||||
QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationInactive);
|
||||
@ -318,10 +309,7 @@ QT_USE_NAMESPACE
|
||||
|
||||
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
|
||||
{
|
||||
Q_UNUSED(theApplication);
|
||||
Q_UNUSED(flag);
|
||||
if (reflectionDelegate
|
||||
&& [reflectionDelegate respondsToSelector:@selector(applicationShouldHandleReopen:hasVisibleWindows:)])
|
||||
if ([reflectionDelegate respondsToSelector:_cmd])
|
||||
return [reflectionDelegate applicationShouldHandleReopen:theApplication hasVisibleWindows:flag];
|
||||
|
||||
/*
|
||||
@ -354,16 +342,13 @@ QT_USE_NAMESPACE
|
||||
|
||||
- (BOOL)respondsToSelector:(SEL)aSelector
|
||||
{
|
||||
BOOL result = [super respondsToSelector:aSelector];
|
||||
if (!result && reflectionDelegate)
|
||||
result = [reflectionDelegate respondsToSelector:aSelector];
|
||||
return result;
|
||||
return [super respondsToSelector:aSelector] || [reflectionDelegate respondsToSelector:aSelector];
|
||||
}
|
||||
|
||||
- (void)forwardInvocation:(NSInvocation *)invocation
|
||||
{
|
||||
SEL invocationSelector = [invocation selector];
|
||||
if (reflectionDelegate && [reflectionDelegate respondsToSelector:invocationSelector])
|
||||
if ([reflectionDelegate respondsToSelector:invocationSelector])
|
||||
[invocation invokeWithTarget:reflectionDelegate];
|
||||
else
|
||||
[self doesNotRecognizeSelector:invocationSelector];
|
||||
|
Loading…
Reference in New Issue
Block a user