Revision: 15645
          http://sourceforge.net/p/skim-app/code/15645
Author:   hofman
Date:     2025-07-11 22:03:17 +0000 (Fri, 11 Jul 2025)
Log Message:
-----------
let pdfview make itself first responder after editing based on delegate method 
parameter. No need for delegate to be a responder.

Modified Paths:
--------------
    trunk/SKPDFView.m
    trunk/SKTextNoteEditor.h
    trunk/SKTextNoteEditor.m

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2025-07-11 16:33:57 UTC (rev 15644)
+++ trunk/SKPDFView.m   2025-07-11 22:03:17 UTC (rev 15645)
@@ -2793,9 +2793,12 @@
         [[self delegate] PDFViewDidBeginEditing:self];
 }
 
-- (void)textNoteEditorDidEndEditing:(SKTextNoteEditor *)textNoteEditor {
+- (void)textNoteEditorDidEndEditing:(SKTextNoteEditor *)textNoteEditor 
wasFirstResponder:(BOOL)wasFirstResponder {
     editor = nil;
     
+    if (wasFirstResponder)
+        [[self window] makeFirstResponder:self];
+    
     [self updatedAnnotation:currentAnnotation];
     
     if ([[self delegate] respondsToSelector:@selector(PDFViewDidEndEditing:)])

Modified: trunk/SKTextNoteEditor.h
===================================================================
--- trunk/SKTextNoteEditor.h    2025-07-11 16:33:57 UTC (rev 15644)
+++ trunk/SKTextNoteEditor.h    2025-07-11 22:03:17 UTC (rev 15645)
@@ -45,12 +45,12 @@
 
 @interface SKTextNoteEditor : NSView <NSTextViewDelegate> {
     NSTextView *textView;
-    __weak NSResponder<SKTextNoteEditorDelegate> *delegate;
+    __weak id<SKTextNoteEditorDelegate> delegate;
     PDFAnnotation *annotation;
     NSUndoManager *undoManager;
 }
 
-- (instancetype)initWithAnnotation:(PDFAnnotation *)anAnnotation 
delegate:(NSResponder<SKTextNoteEditorDelegate> *)aDelegate;
+- (instancetype)initWithAnnotation:(PDFAnnotation *)anAnnotation 
delegate:(id<SKTextNoteEditorDelegate>)aDelegate;
 
 @property (nonatomic, nullable, weak, readonly) NSString *currentString;
 
@@ -62,7 +62,7 @@
 @protocol SKTextNoteEditorDelegate <NSObject>;
 - (void)textNoteEditorSetFrame:(SKTextNoteEditor *)textNoteEditor;
 - (void)textNoteEditorDidBeginEditing:(SKTextNoteEditor *)textNoteEditor;
-- (void)textNoteEditorDidEndEditing:(SKTextNoteEditor *)textNoteEditor;
+- (void)textNoteEditorDidEndEditing:(SKTextNoteEditor *)textNoteEditor 
wasFirstResponder:(BOOL)wasFirstResponder;
 @end
 
 NS_ASSUME_NONNULL_END

Modified: trunk/SKTextNoteEditor.m
===================================================================
--- trunk/SKTextNoteEditor.m    2025-07-11 16:33:57 UTC (rev 15644)
+++ trunk/SKTextNoteEditor.m    2025-07-11 22:03:17 UTC (rev 15645)
@@ -58,7 +58,7 @@
     return @[SKNPDFAnnotationBoundsKey, SKNPDFAnnotationFontKey, 
SKNPDFAnnotationFontColorKey, SKNPDFAnnotationAlignmentKey, 
SKNPDFAnnotationColorKey, SKNPDFAnnotationBorderKey, SKNPDFAnnotationStringKey];
 }
 
-- (instancetype)initWithAnnotation:(PDFAnnotation *)anAnnotation 
delegate:(NSResponder<SKTextNoteEditorDelegate> *)aDelegate {
+- (instancetype)initWithAnnotation:(PDFAnnotation *)anAnnotation 
delegate:(id<SKTextNoteEditorDelegate>)aDelegate {
     self = [super initWithFrame:[annotation bounds]];
     if (self) {
         delegate = aDelegate;
@@ -156,19 +156,19 @@
     // avoid getting textDidEndEditing: messages
     [textView setDelegate:nil];
     
+    BOOL wasFirstResponder = NO;
+    
     if ([self superview]) {
         NSWindow *window = [self window];
-        BOOL wasFirstResponder = (textView && [window firstResponder] == 
textView);
+        wasFirstResponder = (textView && [window firstResponder] == textView);
         [self removeFromSuperview];
         [window recalculateKeyViewLoop];
-        if (wasFirstResponder)
-            [window makeFirstResponder:delegate];
     }
     
-    NSResponder<SKTextNoteEditorDelegate> *theDelegate = delegate;
+    id<SKTextNoteEditorDelegate> theDelegate = delegate;
     delegate = nil;
     
-    [theDelegate textNoteEditorDidEndEditing:self];
+    [theDelegate textNoteEditorDidEndEditing:self 
wasFirstResponder:wasFirstResponder];
 }
 
 - (void)startEditingWithEvent:(NSEvent *)event {
@@ -207,7 +207,7 @@
 
 - (NSUndoManager *)undoManagerForTextView:(NSTextView *)view {
     if (undoManager == nil)
-        undoManager = [[SKChainedUndoManager alloc] 
initWithNextUndoManager:[delegate undoManager]];
+        undoManager = [[SKChainedUndoManager alloc] 
initWithNextUndoManager:[self undoManager]];
     return undoManager;
 }
 

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