Revision: 15549
          http://sourceforge.net/p/skim-app/code/15549
Author:   hofman
Date:     2025-06-24 16:55:41 +0000 (Tue, 24 Jun 2025)
Log Message:
-----------
separate function to find document in presentation mode

Modified Paths:
--------------
    trunk/SKApplicationController.m

Modified: trunk/SKApplicationController.m
===================================================================
--- trunk/SKApplicationController.m     2025-06-24 16:48:36 UTC (rev 15548)
+++ trunk/SKApplicationController.m     2025-06-24 16:55:41 UTC (rev 15549)
@@ -298,14 +298,15 @@
     return reply;
 }
 
-- (void)applicationStartsTerminating:(NSApplication *)application; {
+static inline NSDocument *presentationDocument(void) {
     for (NSDocument *doc in [[NSDocumentController sharedDocumentController] 
documents]) {
-        if ([doc interactionMode] == SKPresentationMode) {
-            [doc setInteractionMode:SKNormalMode];
-            break;
-        }
+        if ([doc interactionMode] == SKPresentationMode)
+            return doc;
     }
-    
+    return nil;
+}
+
+- (void)applicationStartsTerminating:(NSApplication *)application; {
     [currentDocumentsTimer invalidate];
     currentDocumentsTimer = nil;
     NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
@@ -312,6 +313,8 @@
     [nc removeObserver:self name:SKDocumentDidShowNotification object:nil];
     [nc removeObserver:self 
name:SKDocumentControllerDidRemoveDocumentNotification object:nil];
     
+    [presentationDocument() setInteractionMode:SKNormalMode];
+    
     [self registerCurrentDocuments:nil];
 }
 
@@ -321,26 +324,21 @@
 }
 
 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication 
*)application {
-    for (NSDocument *doc in [[NSDocumentController sharedDocumentController] 
documents]) {
-        if ([doc interactionMode] == SKPresentationMode) {
-            if ([doc canExitPresentation]) {
+    NSDocument *doc = presentationDocument();
+    if ([doc canExitPresentation]) {
+        [doc setInteractionMode:SKNormalMode];
+    } else if (doc) {
+        DISPATCH_MAIN_AFTER_SEC(0.51, ^{
+            if ([doc interactionMode] != SKPresentationMode) {
+                [NSApp replyToApplicationShouldTerminate:YES];
+            } else if ([doc canExitPresentation]) {
                 [doc setInteractionMode:SKNormalMode];
-                break;
+                [NSApp replyToApplicationShouldTerminate:YES];
             } else {
-                return NSTerminateCancel;
-                DISPATCH_MAIN_AFTER_SEC(0.51, ^{
-                    if ([doc interactionMode] != SKPresentationMode) {
-                        [NSApp replyToApplicationShouldTerminate:YES];
-                    } else if ([doc canExitPresentation]) {
-                        [doc setInteractionMode:SKNormalMode];
-                        [NSApp replyToApplicationShouldTerminate:YES];
-                    } else {
-                        [NSApp replyToApplicationShouldTerminate:NO];
-                    }
-                });
-                return NSTerminateLater;
+                [NSApp replyToApplicationShouldTerminate:NO];
             }
-        }
+        });
+        return NSTerminateLater;
     }
     return NSTerminateNow;
 }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to