|
From: <ho...@us...> - 2025-07-03 09:14:00
|
Revision: 15590
http://sourceforge.net/p/skim-app/code/15590
Author: hofman
Date: 2025-07-03 09:13:55 +0000 (Thu, 03 Jul 2025)
Log Message:
-----------
move joining notes bby shift-mousedown to separate method
Modified Paths:
--------------
trunk/SKPDFView.m
Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m 2025-07-02 16:23:14 UTC (rev 15589)
+++ trunk/SKPDFView.m 2025-07-03 09:13:55 UTC (rev 15590)
@@ -2398,6 +2398,58 @@
[[self undoManager] setActionName:NSLocalizedString(@"Remove Note", @"Undo action name")];
}
+- (PDFAnnotation *)joinAnnotationToCurrentAnnotation:(PDFAnnotation *)annotation {
+ PDFAnnotation *newAnnotation = nil;
+ PDFPage *page = [currentAnnotation page];
+ if ([currentAnnotation isMarkup]) {
+ NSString *type = [currentAnnotation type];
+ PDFSelection *sel = [currentAnnotation selection];
+ PDFSelection *newSel = [annotation selection];
+ BOOL copyText = [[NSUserDefaults standardUserDefaults] integerForKey:SKDisableUpdateContentsFromEnclosedTextKey] < 2;
+ NSString *string1 = [currentAnnotation string];
+ NSString *string2 = [annotation string];
+ NSString *string = nil;
+ if ([string1 length] > 0 && [string2 length] > 0) {
+ if ([sel safeIndexOfFirstCharacterOnPage:page] > (copyText ? [newSel safeIndexOfLastCharacterOnPage:page] : [newSel safeIndexOfFirstCharacterOnPage:page]))
+ string = [NSString stringWithFormat:@"%@ %@", string2, string1];
+ else if (copyText == NO || [newSel safeIndexOfFirstCharacterOnPage:page] > [sel safeIndexOfLastCharacterOnPage:page])
+ string = [NSString stringWithFormat:@"%@ %@", string1, string2];
+ }
+ [sel addSelection:newSel];
+ if (string == nil) {
+ if (copyText)
+ string = [sel cleanedString];
+ else if ([string1 length])
+ string = string1;
+ else if ([string2 length])
+ string = string2;
+ }
+
+ newAnnotation = [PDFAnnotation newSkimNoteWithSelection:sel forType:type];
+ if ([string length] > 0)
+ [newAnnotation setString:string];
+ } else if ([currentAnnotation isInk]) {
+ NSMutableArray *paths = [[currentAnnotation pagePaths] mutableCopy];
+ [paths addObjectsFromArray:[annotation pagePaths]];
+ NSString *string1 = [currentAnnotation string];
+ NSString *string2 = [annotation string];
+
+ newAnnotation = [PDFAnnotation newSkimNoteWithPaths:paths];
+ if ([string1 length] > 0 || [string2 length] > 0)
+ [newAnnotation setString:[string2 length] == 0 ? string1 : [string1 length] == 0 ? string2 : [NSString stringWithFormat:@"%@ %@", string1, string2]];
+ [newAnnotation setBorder:[currentAnnotation border]];
+ } else {
+ return nil;
+ }
+ [newAnnotation setColor:[currentAnnotation color]];
+ [newAnnotation registerUserName];
+ [[self document] removeAnnotation:currentAnnotation];
+ [[self document] removeAnnotation:annotation];
+ [[self document] addAnnotation:newAnnotation toPage:page];
+ [[self undoManager] setActionName:NSLocalizedString(@"Join Notes", @"Undo action name")];
+ return newAnnotation;
+}
+
- (BOOL)addAnnotationWithType:(SKNoteType)annotationType selection:(PDFSelection *)selection page:(PDFPage *)page bounds:(NSRect)bounds {
PDFAnnotation *newAnnotation = nil;
NSArray *newAnnotations = nil;
@@ -3778,11 +3830,9 @@
PDFPage *newActivePage = [self pageAndPoint:&point forEvent:theEvent nearest:YES];
if (newActivePage) { // newActivePage should never be nil, but just to be sure
- if (newActivePage != [currentAnnotation page]) {
+ if (newActivePage != [currentAnnotation page])
// move the annotation to the new page
[[self document] moveAnnotation:currentAnnotation toPage:newActivePage];
- [[self undoManager] setActionName:NSLocalizedString(@"Edit Note", @"Undo action name")];
- }
NSRect newBounds = [currentAnnotation bounds];
newBounds.origin = SKIntegralPoint(SKSubstractPoints(point, offset));
@@ -4173,54 +4223,7 @@
// don't drag markup notes or in freehand tool mode, unless the note was previously selected, so we can select text or draw freehand strokes
newCurrentAnnotation = nil;
} else if ((modifiers & NSEventModifierFlagShift) && currentAnnotation != newCurrentAnnotation && [[currentAnnotation page] isEqual:[newCurrentAnnotation page]] && [[currentAnnotation type] isEqualToString:[newCurrentAnnotation type]]) {
- PDFAnnotation *newAnnotation = nil;
- if ([currentAnnotation isMarkup]) {
- NSString *type = [currentAnnotation type];
- PDFSelection *sel = [currentAnnotation selection];
- PDFSelection *newSel = [newCurrentAnnotation selection];
- BOOL copyText = [[NSUserDefaults standardUserDefaults] integerForKey:SKDisableUpdateContentsFromEnclosedTextKey] < 2;
- NSString *string1 = [currentAnnotation string];
- NSString *string2 = [newCurrentAnnotation string];
- NSString *string = nil;
- if ([string1 length] > 0 && [string2 length] > 0) {
- if ([sel safeIndexOfFirstCharacterOnPage:page] > (copyText ? [newSel safeIndexOfLastCharacterOnPage:page] : [newSel safeIndexOfFirstCharacterOnPage:page]))
- string = [NSString stringWithFormat:@"%@ %@", string2, string1];
- else if (copyText == NO || [newSel safeIndexOfFirstCharacterOnPage:page] > [sel safeIndexOfLastCharacterOnPage:page])
- string = [NSString stringWithFormat:@"%@ %@", string1, string2];
- }
- [sel addSelection:newSel];
- if (string == nil) {
- if (copyText)
- string = [sel cleanedString];
- else if ([string1 length])
- string = string1;
- else if ([string2 length])
- string = string2;
- }
-
- newAnnotation = [PDFAnnotation newSkimNoteWithSelection:sel forType:type];
- if ([string length] > 0)
- [newAnnotation setString:string];
- } else if ([currentAnnotation isInk]) {
- NSMutableArray *paths = [[currentAnnotation pagePaths] mutableCopy];
- [paths addObjectsFromArray:[newCurrentAnnotation pagePaths]];
- NSString *string1 = [currentAnnotation string];
- NSString *string2 = [newCurrentAnnotation string];
-
- newAnnotation = [PDFAnnotation newSkimNoteWithPaths:paths];
- if ([string1 length] > 0 || [string2 length] > 0)
- [newAnnotation setString:[string2 length] == 0 ? string1 : [string1 length] == 0 ? string2 : [NSString stringWithFormat:@"%@ %@", string1, string2]];
- [newAnnotation setBorder:[currentAnnotation border]];
- }
- if (newAnnotation) {
- [newAnnotation setColor:[currentAnnotation color]];
- [newAnnotation registerUserName];
- [[self document] removeAnnotation:currentAnnotation];
- [[self document] removeAnnotation:newCurrentAnnotation];
- [[self document] addAnnotation:newAnnotation toPage:page];
- [[self undoManager] setActionName:NSLocalizedString(@"Join Notes", @"Undo action name")];
- newCurrentAnnotation = newAnnotation;
- }
+ newCurrentAnnotation = [self joinAnnotationToCurrentAnnotation:newCurrentAnnotation] ?: newCurrentAnnotation;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|