Revision: 15642
http://sourceforge.net/p/skim-app/code/15642
Author: hofman
Date: 2025-07-11 15:49:35 +0000 (Fri, 11 Jul 2025)
Log Message:
-----------
Let pdfview set the frame for the text note editor. Declare pdfview as
NSResponder conforming to delegate protocol.
Modified Paths:
--------------
trunk/SKPDFView.m
trunk/SKTextNoteEditor.h
trunk/SKTextNoteEditor.m
Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m 2025-07-11 14:51:46 UTC (rev 15641)
+++ trunk/SKPDFView.m 2025-07-11 15:49:35 UTC (rev 15642)
@@ -188,7 +188,7 @@
- (void)enableSwipeGestures:(BOOL)flag;
@end
-@interface SKPDFView () <SKReadingBarDelegate, SKLayerDelegate>
+@interface SKPDFView () <SKReadingBarDelegate, SKLayerDelegate,
SKTextNoteEditorDelegate>
@property (strong) SKReadingBar *readingBar;
@property (strong) SKSyncDot *syncDot;
@end
@@ -415,7 +415,7 @@
[self resetPDFToolTipRects];
if (editor) {
if ([self isPageAtIndexDisplayed:[currentAnnotation pageIndex]])
- [editor updateFrame];
+ [self textNoteEditorSetFrame:editor];
else
[self commitEditing];
}
@@ -2774,7 +2774,7 @@
if ([self isEditingAnnotation:currentAnnotation])
return;
- editor = [[SKTextNoteEditor alloc] initWithPDFView:self
annotation:currentAnnotation];
+ editor = [[SKTextNoteEditor alloc] initWithAnnotation:currentAnnotation
delegate:self];
[[self documentView] addSubview:editor];
[editor startEditingWithEvent:theEvent];
@@ -2781,6 +2781,13 @@
[self updatedAnnotation:currentAnnotation];
}
+- (void)textNoteEditorSetFrame:(SKTextNoteEditor *)textNoteEditor {
+ NSRect frame = [self convertRect:[currentAnnotation bounds]
fromPage:[currentAnnotation page]];
+ frame = [self backingAlignedRect:frame options:NSAlignAllEdgesNearest];
+ frame = [self convertRect:frame toView:[self documentView]];
+ [editor setFrame:frame];
+}
+
- (void)textNoteEditorDidBeginEditing:(SKTextNoteEditor *)textNoteEditor {
if ([[self delegate]
respondsToSelector:@selector(PDFViewDidBeginEditing:)])
[[self delegate] PDFViewDidBeginEditing:self];
@@ -3152,7 +3159,7 @@
[self resetPDFToolTipRects];
} else if ([self isEditingAnnotation:annotation]) {
if ([self isPageAtIndexDisplayed:[annotation pageIndex]])
- [editor updateFrame];
+ [self textNoteEditorSetFrame:editor];
else
[self commitEditing];
}
@@ -3193,7 +3200,7 @@
- (void)handleScaleChangedNotification:(NSNotification *)notification {
[self resetPDFToolTipRects];
[self updatePacer];
- [editor updateFrame];
+ [self textNoteEditorSetFrame:editor];
}
- (void)handleUpdateTrackingAreasNotification:(NSNotification *)notification {
Modified: trunk/SKTextNoteEditor.h
===================================================================
--- trunk/SKTextNoteEditor.h 2025-07-11 14:51:46 UTC (rev 15641)
+++ trunk/SKTextNoteEditor.h 2025-07-11 15:49:35 UTC (rev 15642)
@@ -41,24 +41,26 @@
NS_ASSUME_NONNULL_BEGIN
+@protocol SKTextNoteEditorDelegate;
+
@interface SKTextNoteEditor : NSView <NSTextViewDelegate> {
NSTextView *textView;
- __weak PDFView *pdfView;
+ __weak NSResponder<SKTextNoteEditorDelegate> *delegate;
PDFAnnotation *annotation;
NSUndoManager *undoManager;
}
-- (instancetype)initWithPDFView:(PDFView *)aPDFView annotation:(PDFAnnotation
*)anAnnotation;
+- (instancetype)initWithAnnotation:(PDFAnnotation *)anAnnotation
delegate:(NSResponder<SKTextNoteEditorDelegate> *)aDelegate;
@property (nonatomic, nullable, weak, readonly) NSString *currentString;
- (void)startEditingWithEvent:(nullable NSEvent *)event;
- (void)endEditingWithCommit:(BOOL)commit;
-- (void)updateFrame;
@end
-@interface PDFView (SKTextNoteEditor)
+@protocol SKTextNoteEditorDelegate <NSObject>;
+- (void)textNoteEditorSetFrame:(SKTextNoteEditor *)textNoteEditor;
- (void)textNoteEditorDidBeginEditing:(SKTextNoteEditor *)textNoteEditor;
- (void)textNoteEditorDidEndEditing:(SKTextNoteEditor *)textNoteEditor;
@end
Modified: trunk/SKTextNoteEditor.m
===================================================================
--- trunk/SKTextNoteEditor.m 2025-07-11 14:51:46 UTC (rev 15641)
+++ trunk/SKTextNoteEditor.m 2025-07-11 15:49:35 UTC (rev 15642)
@@ -37,9 +37,7 @@
*/
#import "SKTextNoteEditor.h"
-#import "PDFView_SKExtensions.h"
#import "PDFAnnotation_SKExtensions.h"
-#import "NSView_SKExtensions.h"
#import "NSEvent_SKExtensions.h"
#import "SKChainedUndoManager.h"
#import "SKStringConstants.h"
@@ -60,10 +58,10 @@
return @[SKNPDFAnnotationBoundsKey, SKNPDFAnnotationFontKey,
SKNPDFAnnotationFontColorKey, SKNPDFAnnotationAlignmentKey,
SKNPDFAnnotationColorKey, SKNPDFAnnotationBorderKey, SKNPDFAnnotationStringKey];
}
-- (instancetype)initWithPDFView:(PDFView *)aPDFView annotation:(PDFAnnotation
*)anAnnotation {
+- (instancetype)initWithAnnotation:(PDFAnnotation *)anAnnotation
delegate:(NSResponder<SKTextNoteEditorDelegate> *)aDelegate {
self = [super initWithFrame:[annotation bounds]];
if (self) {
- pdfView = aPDFView;
+ delegate = aDelegate;
annotation = anAnnotation;
for (NSString *key in [[self class] keysToObserve])
@@ -89,12 +87,6 @@
return [textView string] ?: [annotation string];
}
-- (void)updateFrame {
- NSRect frame = [pdfView backingAlignedRect:[pdfView
convertRect:[annotation bounds] fromPage:[annotation page]]
options:NSAlignAllEdgesNearest];
- frame = [pdfView convertRect:frame toView:[self superview]];
- [self setFrame:frame];
-}
-
- (void)updateParagraphStyle {
NSFont *font = [annotation font];
NSMutableParagraphStyle *parStyle = [[NSMutableParagraphStyle alloc] init];
@@ -165,24 +157,24 @@
[textView setDelegate:nil];
if ([self superview]) {
- BOOL wasFirstResponder = (textView && [[pdfView window]
firstResponder] == textView);
+ NSWindow *window = [self window];
+ BOOL wasFirstResponder = (textView && [window firstResponder] ==
textView);
[self removeFromSuperview];
- [[pdfView window] recalculateKeyViewLoop];
+ [window recalculateKeyViewLoop];
if (wasFirstResponder)
- [[pdfView window] makeFirstResponder:pdfView];
+ [window makeFirstResponder:delegate];
}
- PDFView *thePdfView = pdfView;
- pdfView = nil;
+ NSResponder<SKTextNoteEditorDelegate> *theDelegate = delegate;
+ delegate = nil;
- if ([thePdfView
respondsToSelector:@selector(textNoteEditorDidEndEditing:)])
- [thePdfView textNoteEditorDidEndEditing:self];
+ [theDelegate textNoteEditorDidEndEditing:self];
}
- (void)startEditingWithEvent:(NSEvent *)event {
- [self updateFrame];
+ [delegate textNoteEditorSetFrame:self];
[self setUpTextView];
- [[pdfView window] recalculateKeyViewLoop];
+ [[self window] recalculateKeyViewLoop];
[textView scrollPoint:NSZeroPoint];
[annotation setShouldDisplay:NO];
if (event) {
@@ -207,8 +199,7 @@
}
- (void)textDidBeginEditing:(NSNotification *)notification {
- if ([pdfView respondsToSelector:@selector(textNoteEditorDidBeginEditing:)])
- [pdfView textNoteEditorDidBeginEditing:self];
+ [delegate textNoteEditorDidBeginEditing:self];
}
- (void)textDidEndEditing:(NSNotification *)notification {
@@ -217,7 +208,7 @@
- (NSUndoManager *)undoManagerForTextView:(NSTextView *)view {
if (undoManager == nil)
- undoManager = [[SKChainedUndoManager alloc]
initWithNextUndoManager:[pdfView undoManager]];
+ undoManager = [[SKChainedUndoManager alloc]
initWithNextUndoManager:[delegate undoManager]];
return undoManager;
}
@@ -224,7 +215,7 @@
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
if (context == &SKPDFAnnotationPropertiesObservationContext) {
if ([keyPath isEqualToString:SKNPDFAnnotationBoundsKey]) {
- [self updateFrame];
+ [delegate textNoteEditorSetFrame:self];
} else if ([keyPath isEqualToString:SKNPDFAnnotationFontKey]) {
[textView setFont:[annotation font]];
[self updateParagraphStyle];
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit