Revision: 15540
          http://sourceforge.net/p/skim-app/code/15540
Author:   hofman
Date:     2025-06-24 14:24:42 +0000 (Tue, 24 Jun 2025)
Log Message:
-----------
Add canExitPresentation property to NSDocument. Delay terminating the app when 
a document is busy entering presentation. Delay updating file from disk when 
busy entering presentation. Exit presentation when updating from file update 
from file update checker.

Modified Paths:
--------------
    trunk/NSDocument_SKExtensions.h
    trunk/NSDocument_SKExtensions.m
    trunk/SKApplicationController.m
    trunk/SKFileUpdateChecker.m
    trunk/SKMainDocument.m

Modified: trunk/NSDocument_SKExtensions.h
===================================================================
--- trunk/NSDocument_SKExtensions.h     2025-06-24 09:37:26 UTC (rev 15539)
+++ trunk/NSDocument_SKExtensions.h     2025-06-24 14:24:42 UTC (rev 15540)
@@ -62,6 +62,8 @@
 
 @property (nonatomic) SKInteractionMode interactionMode;
 
+@property (nonatomic, readonly) BOOL canExitPresentation;
+
 #pragma mark Document Setup
 
 - (void)saveRecentDocumentInfo;

Modified: trunk/NSDocument_SKExtensions.m
===================================================================
--- trunk/NSDocument_SKExtensions.m     2025-06-24 09:37:26 UTC (rev 15539)
+++ trunk/NSDocument_SKExtensions.m     2025-06-24 14:24:42 UTC (rev 15540)
@@ -100,6 +100,8 @@
         [[self mainWindow] toggleFullScreen:nil];
 }
 
+- (BOOL)canExitPresentation { return NO; }
+
 #pragma mark Document Setup
 
 - (void)saveRecentDocumentInfo {

Modified: trunk/SKApplicationController.m
===================================================================
--- trunk/SKApplicationController.m     2025-06-24 09:37:26 UTC (rev 15539)
+++ trunk/SKApplicationController.m     2025-06-24 14:24:42 UTC (rev 15540)
@@ -315,9 +315,23 @@
 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication 
*)application {
     for (NSDocument *doc in [[NSDocumentController sharedDocumentController] 
documents]) {
         if ([doc interactionMode] == SKPresentationMode) {
-            if (currentDocumentsTimer == nil)
-                [self registerForCurrentDocumentsNotifications];
-            return NSTerminateCancel;
+            if ([doc canExitPresentation]) {
+                [doc setInteractionMode:SKNormalMode];
+                break;
+            } else {
+                DISPATCH_MAIN_AFTER_SEC(0.51, ^{
+                    if ([doc interactionMode] == SKPresentationMode && [doc 
canExitPresentation] == NO) {
+                        [NSApp replyToApplicationShouldTerminate:NO];
+                        if (currentDocumentsTimer == nil)
+                            [self registerForCurrentDocumentsNotifications];
+                    } else {
+                        if ([doc canExitPresentation])
+                            [doc setInteractionMode:SKNormalMode];
+                        [NSApp replyToApplicationShouldTerminate:YES];
+                    }
+                });
+                return NSTerminateLater;
+            }
         }
     }
     return NSTerminateNow;

Modified: trunk/SKFileUpdateChecker.m
===================================================================
--- trunk/SKFileUpdateChecker.m 2025-06-24 09:37:26 UTC (rev 15539)
+++ trunk/SKFileUpdateChecker.m 2025-06-24 14:24:42 UTC (rev 15540)
@@ -168,6 +168,9 @@
         if (option == SKFileUpdateOptionAuto)
             fucFlags.autoUpdate = YES;
         
+        if ([document interactionMode] == SKPresentationMode)
+            [document setInteractionMode:SKNormalMode];
+        
         NSError *error = nil;
         BOOL didRevert = [document revertToContentsOfURL:[document fileURL] 
ofType:[document fileType] error:&error];
         if (didRevert == NO && error != nil && [error isUserCancelledError] == 
NO)
@@ -209,6 +212,8 @@
         if ([docWindow attachedSheet]) {
             [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleWindowDidEndSheetNotification:) 
                                                          
name:NSWindowDidEndSheetNotification object:docWindow];
+        } else if ([document interactionMode] == SKPresentationMode && 
[document canExitPresentation] == NO) {
+            [self performSelector:@selector(fileUpdated) withObject:nil 
afterDelay:0.51];
         } else if (canUpdateFromURL(fileURL)) {
             BOOL documentHasEdits = [document isDocumentEdited] || [document 
hasNotes];
             if (fucFlags.autoUpdate && documentHasEdits == NO) {

Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m      2025-06-24 09:37:26 UTC (rev 15539)
+++ trunk/SKMainDocument.m      2025-06-24 14:24:42 UTC (rev 15540)
@@ -308,6 +308,25 @@
     return [[self mainWindowController] interactionMode];
 }
 
+- (void)setInteractionMode:(SKInteractionMode)mode {
+    if (mode == SKNormalMode) {
+        if ([[self mainWindowController] canExitFullscreen])
+            [[self mainWindowController] exitFullscreen];
+        else if ([[self mainWindowController] canExitPresentation])
+            [[self mainWindowController] exitPresentation];
+    } else if (mode == SKFullScreenMode) {
+        if ([[self mainWindowController] canEnterFullscreen])
+            [[self mainWindowController] enterFullscreen];
+    } else if (mode == SKPresentationMode) {
+        if ([[self mainWindowController] canEnterPresentation])
+            [[self mainWindowController] enterPresentation];
+    }
+}
+
+- (BOOL)canExitPresentation {
+    return [[self mainWindowController] canExitPresentation];
+}
+
 #pragma mark Writing
 
 - (NSString *)fileType {
@@ -998,9 +1017,6 @@
     NSWindow *modalwindow = nil;
     NSModalSession session;
     
-    if ([[self mainWindowController] canExitPresentation])
-        [[self mainWindowController] exitPresentation];
-    
     if ([mainWindow attachedSheet] == nil && [mainWindow isMainWindow]) {
         modalwindow = [[SKAnimatedBorderlessWindow alloc] 
initWithContentRect:NSZeroRect];
         [(SKApplication *)NSApp setUserAttentionDisabled:YES];
@@ -1859,21 +1875,6 @@
     [[self pdfView] setToolMode:newToolMode];
 }
 
-- (void)setInteractionMode:(SKInteractionMode)mode {
-    if (mode == SKNormalMode) {
-        if ([[self mainWindowController] canExitFullscreen])
-            [[self mainWindowController] exitFullscreen];
-        else if ([[self mainWindowController] canExitPresentation])
-            [[self mainWindowController] exitPresentation];
-    } else if (mode == SKFullScreenMode) {
-        if ([[self mainWindowController] canEnterFullscreen])
-            [[self mainWindowController] enterFullscreen];
-    } else if (mode == SKPresentationMode) {
-        if ([[self mainWindowController] canEnterPresentation])
-            [[self mainWindowController] enterPresentation];
-    }
-}
-
 - (NSDocument *)presentationNotesDocument {
     return [[self mainWindowController] presentationNotesDocument];
 }

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