Revision: 29278
          http://sourceforge.net/p/bibdesk/svn/29278
Author:   hofman
Date:     2025-07-14 16:00:07 +0000 (Mon, 14 Jul 2025)
Log Message:
-----------
implement NSEditor methods instead of custom method

Modified Paths:
--------------
    trunk/bibdesk/BDSKCharacterConversion.h
    trunk/bibdesk/BDSKCharacterConversion.m
    trunk/bibdesk/BDSKDocumentInfoWindowController.h
    trunk/bibdesk/BDSKDocumentInfoWindowController.m

Modified: trunk/bibdesk/BDSKCharacterConversion.h
===================================================================
--- trunk/bibdesk/BDSKCharacterConversion.h     2025-07-14 09:18:01 UTC (rev 
29277)
+++ trunk/bibdesk/BDSKCharacterConversion.h     2025-07-14 16:00:07 UTC (rev 
29278)
@@ -87,7 +87,8 @@
 @property (nonatomic, copy) NSDictionary *twoWayDict;
 
 - (void)updateButtons;
-- (BOOL)finalizeChangesIgnoringEdit:(BOOL)flag;
+- (BOOL)commitEditing;
+- (void)discardEditing;
 
 @end
 

Modified: trunk/bibdesk/BDSKCharacterConversion.m
===================================================================
--- trunk/bibdesk/BDSKCharacterConversion.m     2025-07-14 09:18:01 UTC (rev 
29277)
+++ trunk/bibdesk/BDSKCharacterConversion.m     2025-07-14 16:00:07 UTC (rev 
29278)
@@ -169,11 +169,13 @@
 
 - (IBAction)dismiss:(id)sender {
     // commit edit before saving
-    if (NO == [self finalizeChangesIgnoringEdit:[sender tag] == 
NSModalResponseCancel]) {
+    if ([sender tag] == NSModalResponseCancel) {
+        [self discardEditing];
+    } else if (NO == [self commitEditing]) {
         NSBeep();
         return;
     }
-       
+    
     if ([sender tag] == NSModalResponseOK) {
         if (!validRoman || !validTex) {
             NSAlert *alert = [[NSAlert alloc] init];
@@ -217,7 +219,7 @@
 
 - (IBAction)changeList:(id)sender {
     // commit edit before switching
-    if ([self finalizeChangesIgnoringEdit:NO])
+    if ([self commitEditing])
         [self setListType:[[sender selectedItem] tag]];
     else
         NSBeep();
@@ -227,7 +229,7 @@
     if ([sender selectedSegment] == 0) { // add
         
         // make sure we are not editing
-        if (NO == [self finalizeChangesIgnoringEdit:NO])
+        if (NO == [self commitEditing])
             return;
         
         unichar ch = (unichar)0x00E4;
@@ -253,8 +255,7 @@
     } else { // remove
         
         // make sure we are not editing
-        if (NO == [self finalizeChangesIgnoringEdit:YES])
-            return;
+        [self discardEditing];
         
         NSInteger row = [tableView selectedRow];
         if (row == -1) return;
@@ -349,18 +350,24 @@
        [addRemoveButton setEnabled:[tableView selectedRow] != -1 forSegment:1];
 }
 
-- (BOOL)finalizeChangesIgnoringEdit:(BOOL)flag {
+- (BOOL)commitEditing {
     id firstResponder = [[self window] firstResponder];
-    if ([firstResponder isKindOfClass:[NSText class]] == NO)
+    if ([firstResponder isKindOfClass:[NSText class]])
+        return [[self window] makeFirstResponder:[self window]];
+    else
         return YES;
-    else if (flag == NO)
-        return [[self window] makeFirstResponder:nil];
-    else if ([[firstResponder delegate] 
respondsToSelector:@selector(abortEditing)])
-        return [[firstResponder delegate] abortEditing];
-    else
-        return [firstResponder abortEditing];
 }
 
+- (void)discardEditing {
+    id firstResponder = [[self window] firstResponder];
+    if ([firstResponder isKindOfClass:[NSText class]]) {
+        if ([[firstResponder delegate] 
respondsToSelector:@selector(abortEditing)])
+            [[firstResponder delegate] abortEditing];
+        else
+            [[self window] endEditingFor:nil];
+    }
+}
+
 #pragma mark NSTableview Datasource
 
 - (NSInteger)numberOfRowsInTableView:(NSTableView *)tv {

Modified: trunk/bibdesk/BDSKDocumentInfoWindowController.h
===================================================================
--- trunk/bibdesk/BDSKDocumentInfoWindowController.h    2025-07-14 09:18:01 UTC 
(rev 29277)
+++ trunk/bibdesk/BDSKDocumentInfoWindowController.h    2025-07-14 16:00:07 UTC 
(rev 29278)
@@ -47,7 +47,6 @@
     NSButton *cancelButton;
     NSMapTable *info;
     NSMutableArray *keys;
-    BOOL ignoreEdit;
 }
 
 @property (nonatomic, nullable, strong) IBOutlet NSTableView *tableView;

Modified: trunk/bibdesk/BDSKDocumentInfoWindowController.m
===================================================================
--- trunk/bibdesk/BDSKDocumentInfoWindowController.m    2025-07-14 09:18:01 UTC 
(rev 29277)
+++ trunk/bibdesk/BDSKDocumentInfoWindowController.m    2025-07-14 16:00:07 UTC 
(rev 29278)
@@ -54,7 +54,6 @@
     if (self) {
         info = [[NSMapTable alloc] 
initWithKeyPointerFunctions:[NSPointerFunctions 
caseInsensitiveStringPointerFunctions] 
valuePointerFunctions:[NSPointerFunctions strongObjectPointerFunctions] 
capacity:0];
         keys = nil;
-        ignoreEdit = NO;
     }
     return self;
 }
@@ -79,15 +78,26 @@
     [self updateButtons];
 }
 
-- (void)finalizeChangesIgnoringEdit:(BOOL)flag {
-       ignoreEdit = flag;
-       if ([[self window] makeFirstResponder:nil] == NO)
-        [[self window] endEditingFor:nil];
-       ignoreEdit = NO;
+- (BOOL)commitEditing {
+    id firstResponder = [[self window] firstResponder];
+    if ([firstResponder isKindOfClass:[NSText class]])
+        return [[self window] makeFirstResponder:[self window]];
+    else
+        return YES;
 }
 
+- (void)discardEditing {
+    id firstResponder = [[self window] firstResponder];
+    if ([firstResponder isKindOfClass:[NSText class]]) {
+        if ([[firstResponder delegate] 
respondsToSelector:@selector(abortEditing)])
+            [[firstResponder delegate] abortEditing];
+        else
+            [[self window] endEditingFor:nil];
+    }
+}
+
 - (void)windowWillClose:(NSNotification *)notification{
-    [self finalizeChangesIgnoringEdit:YES];
+    [self discardEditing];
 }
 
 - (void)setInfo:(NSMapTable *)newInfo {
@@ -100,12 +110,14 @@
 #pragma mark Button actions
 
 - (IBAction)dismiss:(id)sender{
-    [self finalizeChangesIgnoringEdit:[sender tag] == NSModalResponseCancel]; 
// commit edit before reloading
+    if ([sender tag] == NSModalResponseCancel) {
+        [self discardEditing];
+    } else if (NO == [self commitEditing]) {
+        NSBeep();
+        return;
+    }
     
-    if ([sender tag] == NSModalResponseOK && [tableView editedTextRow] != -1)
-        NSBeep();
-    else
-        [super dismiss:sender];
+    [super dismiss:sender];
 }
 
 - (IBAction)addRemoveKey:(id)sender{

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



_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to