Revision: 27409
          http://sourceforge.net/p/bibdesk/svn/27409
Author:   hofman
Date:     2022-05-13 15:56:26 +0000 (Fri, 13 May 2022)
Log Message:
-----------
Force commit or end editing when window closes or document is removed from 
editor

Modified Paths:
--------------
    trunk/bibdesk/BDSKEditor.m

Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m  2022-05-13 15:12:02 UTC (rev 27408)
+++ trunk/bibdesk/BDSKEditor.m  2022-05-13 15:56:26 UTC (rev 27409)
@@ -357,31 +357,33 @@
 {
     id firstResponder = [[self window] firstResponder];
     // check textviews first
-    if (currentEditedView == firstResponder) {
-        // need some reasonable state for annote et al. textviews
-        NSParameterAssert(nil != previousValueForCurrentEditedView);
-        [currentEditedView setString:previousValueForCurrentEditedView];
-    }
-    // now handle any field editor(s)
-    else if ([firstResponder isKindOfClass:[NSText class]]) {
-     
-        /*
-         Omit the standard check for [[self window] fieldEditor:NO 
forObject:nil],
-         since that returns nil for the tableview's field editor.
-         */
-        
-        NSControl *control = (NSControl *)[(NSText *)firstResponder delegate];
-        
-        // may be self, if a textview was being edited (but we should have 
taken the first branch in that case)
-        if ([control respondsToSelector:@selector(abortEditing)]) {
-            [control abortEditing];
-            if ([tableView rowForView:control] != -1) {
-                // controlTextDidEndEditing: is not called when calling 
abortEditing
-                [tableCellFormatter setEditAsComplexString:NO];
-            }
+    if ([firstResponder isKindOfClass:[NSText class]]) {
+        if (currentEditedView == firstResponder) {
+            // need some reasonable state for annote et al. textviews
+            NSParameterAssert(nil != previousValueForCurrentEditedView);
+            [currentEditedView setString:previousValueForCurrentEditedView];
         }
+        // now handle any field editor(s)
         else {
-            fprintf(stderr, "%s, control does not respond to abortEditing\n", 
__func__);
+         
+            /*
+             Omit the standard check for [[self window] fieldEditor:NO 
forObject:nil],
+             since that returns nil for the tableview's field editor.
+             */
+            
+            NSControl *control = (NSControl *)[(NSText *)firstResponder 
delegate];
+            
+            // may be self, if a textview was being edited (but we should have 
taken the first branch in that case)
+            if ([control respondsToSelector:@selector(abortEditing)]) {
+                [control abortEditing];
+                if ([tableView rowForView:control] != -1) {
+                    // controlTextDidEndEditing: is not called when calling 
abortEditing
+                    [tableCellFormatter setEditAsComplexString:NO];
+                }
+            }
+            else {
+                fprintf(stderr, "%s, control does not respond to 
abortEditing\n", __func__);
+            }
         }
     }
     if (editorFlags.isEditing) {
@@ -456,6 +458,20 @@
     return YES;
 }
 
+- (void)forceCommitEditing {
+    NSResponder *firstResponder = [[self window] firstResponder];
+    
+    if ([firstResponder isKindOfClass:[NSText class]]) {
+        if (NO == [[self window] makeFirstResponder:[self window]])
+            [self discardEditing];
+    }
+    
+    if (editorFlags.isEditing) {
+        [[self document] objectDidEndEditing:(id)self];
+        editorFlags.isEditing = NO;
+    }
+}
+
 #pragma mark Actions
 
 - (IBAction)copy:(id)sender {
@@ -2987,8 +3003,8 @@
     editorFlags.didClose = YES;
     
     // make sure we're not registered as editor because we will be invalid, 
this shouldn't be necessary but there have been reports of crashes
-    if (editorFlags.isEditing && [self commitEditing] == NO)
-        [self discardEditing];
+    if (editorFlags.isEditing)
+        [self forceCommitEditing];
        
     // see method for notes
     [self breakTextStorageConnections];
@@ -3019,14 +3035,8 @@
 
 - (void)setDocument:(NSDocument *)document {
     // in case the document is reset before windowWillClose: is called, I 
think this can happen on Tiger
-    if ([self document] && document == nil && editorFlags.isEditing) {
-        if ([self commitEditing] == NO)
-            [self discardEditing];
-        if (editorFlags.isEditing) {
-            [[self document] objectDidEndEditing:(id)self];
-            editorFlags.isEditing = NO;
-        }
-    }
+    if ([self document] && document == nil && editorFlags.isEditing)
+        [self forceCommitEditing];
     [super setDocument:document];
 }
 

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



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to