Revision: 27410
          http://sourceforge.net/p/bibdesk/svn/27410
Author:   hofman
Date:     2022-05-13 16:10:29 +0000 (Fri, 13 May 2022)
Log Message:
-----------
Convenience methods to (de)register editor window controller as editor

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

Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m  2022-05-13 15:56:26 UTC (rev 27409)
+++ trunk/bibdesk/BDSKEditor.m  2022-05-13 16:10:29 UTC (rev 27410)
@@ -331,6 +331,20 @@
     [super dealloc];
 }
 
+- (void)beginditing {
+    if (editorFlags.isEditing == NO) {
+        [[self document] objectDidBeginEditing:(id)self];
+        editorFlags.isEditing = YES;
+    }
+}
+
+- (void)endEditing {
+    if (editorFlags.isEditing) {
+        [[self document] objectDidEndEditing:(id)self];
+        editorFlags.isEditing = NO;
+    }
+}
+
 static inline BOOL validRanges(NSArray *ranges, NSUInteger max) {
     for (NSValue *range in ranges) {
         if (NSMaxRange([range rangeValue]) > max)
@@ -386,10 +400,7 @@
             }
         }
     }
-    if (editorFlags.isEditing) {
-        [[self document] objectDidEndEditing:(id)self];
-        editorFlags.isEditing = NO;
-    }
+    [self endEditing];
 }
 
 - (void)commitEditingWithDelegate:(id)delegate 
didCommitSelector:(SEL)didCommitSelector contextInfo:(void *)contextInfo
@@ -459,17 +470,13 @@
 }
 
 - (void)forceCommitEditing {
-    NSResponder *firstResponder = [[self window] firstResponder];
-    
-    if ([firstResponder isKindOfClass:[NSText class]]) {
-        if (NO == [[self window] makeFirstResponder:[self window]])
+    if (editorFlags.isEditing) {
+        if ([[[self window] firstResponder] isKindOfClass:[NSText class]] &&
+            NO == [[self window] makeFirstResponder:[self window]])
             [self discardEditing];
+        
+        [self endEditing];
     }
-    
-    if (editorFlags.isEditing) {
-        [[self document] objectDidEndEditing:(id)self];
-        editorFlags.isEditing = NO;
-    }
 }
 
 #pragma mark Actions
@@ -2127,10 +2134,7 @@
 }
 
 - (void)controlTextDidBeginEditing:(NSNotification *)note {
-    if (editorFlags.isEditing == NO) {
-        [[self document] objectDidBeginEditing:(id)self];
-        editorFlags.isEditing = YES;
-    }
+    [self beginditing];
 }
 
 // send by the formatter when validation failed
@@ -2267,10 +2271,7 @@
 }
 
 - (void)controlTextDidEndEditing:(NSNotification *)notification{
-    if (editorFlags.isEditing) {
-        [[self document] objectDidEndEditing:(id)self];
-        editorFlags.isEditing = NO;
-    }
+    [self endEditing];
        
     if ([tableView rowForView:[notification object]] != -1)
         [tableCellFormatter setEditAsComplexString:NO];
@@ -2280,10 +2281,7 @@
     NSInteger row = [tableView rowForView:control];
     if (commandSelector == @selector(cancelOperation:)) {
         [control abortEditing];
-        if (editorFlags.isEditing) {
-            [[self document] objectDidEndEditing:(id)self];
-            editorFlags.isEditing = NO;
-        }
+        [self endEditing];
         if (row != -1)
             [tableCellFormatter setEditAsComplexString:NO];
         return YES;
@@ -2356,10 +2354,7 @@
     
     // save off the old value in case abortEditing gets called
     [self setPreviousValueForCurrentEditedNotesView:[currentEditedView 
string]];
-    if (editorFlags.isEditing == NO) {
-        [[self document] objectDidBeginEditing:(id)self];
-        editorFlags.isEditing = YES;
-    }
+    [self beginditing];
 }
 
 // Clear all the undo actions when changing tab items, just in case; otherwise 
we
@@ -2384,10 +2379,7 @@
 
 // sent by the textViews
 - (void)textDidEndEditing:(NSNotification *)aNotification{
-    if (editorFlags.isEditing) {
-        [[self document] objectDidEndEditing:(id)self];
-        editorFlags.isEditing = NO;
-    }
+    [self endEditing];
     
     NSString *field = nil;
     if(currentEditedView == notesView)
@@ -3003,8 +2995,7 @@
     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 forceCommitEditing];
+    [self forceCommitEditing];
        
     // see method for notes
     [self breakTextStorageConnections];
@@ -3035,7 +3026,7 @@
 
 - (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 document] && document == nil)
         [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