Revision: 15573
http://sourceforge.net/p/skim-app/code/15573
Author: hofman
Date: 2025-06-29 17:36:22 +0000 (Sun, 29 Jun 2025)
Log Message:
-----------
convenience methods to add and remove annotation with undo acttion name
Modified Paths:
--------------
trunk/SKPDFView.m
Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m 2025-06-29 17:22:07 UTC (rev 15572)
+++ trunk/SKPDFView.m 2025-06-29 17:36:22 UTC (rev 15573)
@@ -207,6 +207,9 @@
- (void)beginNewUndoGroupIfNeededWithCommit:(BOOL)commit;
+- (void)addAnnotation:(PDFAnnotation *)annotation toPage:(PDFPage *)page;
+- (void)removeAnnotation:(PDFAnnotation *)annotation;
+
- (void)stopPacer;
- (void)updatePacer;
@@ -1233,8 +1236,6 @@
if ([newAnnotations count] > 0) {
- [self beginNewUndoGroupIfNeededWithCommit:YES];
-
for (PDFAnnotation *newAnnotation in newAnnotations) {
NSRect bounds = [newAnnotation bounds];
@@ -1244,10 +1245,9 @@
[newAnnotation setBounds:bounds];
[newAnnotation registerUserName];
- [[self document] addAnnotation:newAnnotation toPage:page];
+ [self addAnnotation:newAnnotation toPage:page];
}
- [[self undoManager] setActionName:NSLocalizedString(@"Add Note",
@"Undo action name")];
if (toolMode == SKToolModeText || toolMode == SKToolModeNote)
[self setCurrentAnnotation:[newAnnotations lastObject]];
@@ -1316,9 +1316,7 @@
}
[newAnnotation registerUserName];
- [self beginNewUndoGroupIfNeededWithCommit:YES];
- [[self document] addAnnotation:newAnnotation toPage:page];
- [[self undoManager] setActionName:NSLocalizedString(@"Add Note",
@"Undo action name")];
+ [self addAnnotation:newAnnotation toPage:page];
if (toolMode == SKToolModeText || toolMode == SKToolModeNote)
[self setCurrentAnnotation:newAnnotation];
@@ -1360,9 +1358,7 @@
[newAnnotation setString:text];
[newAnnotation registerUserName];
- [self beginNewUndoGroupIfNeededWithCommit:YES];
- [[self document] addAnnotation:newAnnotation toPage:page];
- [[self undoManager] setActionName:NSLocalizedString(@"Add
Note", @"Undo action name")];
+ [self addAnnotation:newAnnotation toPage:page];
if (toolMode == SKToolModeText || toolMode == SKToolModeNote)
[self setCurrentAnnotation:newAnnotation];
@@ -2307,9 +2303,7 @@
[(SKNPDFAnnotationNote *)newAnnotation
setExtendedIconType:kSKNPDFTextAnnotationIconImage];
[newAnnotation registerUserName];
- [self beginNewUndoGroupIfNeededWithCommit:YES];
- [[self document] addAnnotation:newAnnotation toPage:page];
- [[self undoManager] setActionName:NSLocalizedString(@"Add
Note", @"Undo action name")];
+ [self addAnnotation:newAnnotation toPage:page];
if (toolMode == SKToolModeText || toolMode == SKToolModeNote)
[self setCurrentAnnotation:newAnnotation];
@@ -2387,6 +2381,17 @@
#pragma mark Annotation management
+- (void)addAnnotation:(PDFAnnotation *)annotation toPage:(PDFPage *)page {
+ [self beginNewUndoGroupIfNeededWithCommit:YES];
+ [[self document] addAnnotation:annotation toPage:page];
+ [[self undoManager] setActionName:NSLocalizedString(@"Add Note", @"Undo
action name")];
+}
+
+- (void)removeAnnotation:(PDFAnnotation *)annotation {
+ [[self document] removeAnnotation:annotation];
+ [[self undoManager] setActionName:NSLocalizedString(@"Remove Note", @"Undo
action name")];
+}
+
- (BOOL)addAnnotationWithType:(SKNoteType)annotationType
selection:(PDFSelection *)selection page:(PDFPage *)page bounds:(NSRect)bounds {
PDFAnnotation *newAnnotation = nil;
NSArray *newAnnotations = nil;
@@ -2446,7 +2451,6 @@
}
if ([newAnnotations count] > 0) {
- [self beginNewUndoGroupIfNeededWithCommit:YES];
for (NSArray *annotationAndPage in newAnnotations) {
newAnnotation = [annotationAndPage firstObject];
@@ -2454,9 +2458,8 @@
if ([text length] > 0 || [newAnnotation string] == nil)
[newAnnotation setString:text ?: @""];
[newAnnotation registerUserName];
- [[self document] addAnnotation:newAnnotation toPage:page];
+ [self addAnnotation:newAnnotation toPage:page];
}
- [[self undoManager] setActionName:NSLocalizedString(@"Add Note",
@"Undo action name")];
if (toolMode == SKToolModeText || toolMode == SKToolModeNote)
[self setCurrentAnnotation:newAnnotation];
@@ -2463,7 +2466,6 @@
return YES;
} else if (newAnnotation) {
- [self beginNewUndoGroupIfNeededWithCommit:YES];
if (annotationType != SKNoteTypeLine && annotationType !=
SKNoteTypeInk) {
if ([text length] > 0)
@@ -2474,8 +2476,7 @@
if ([newAnnotation string] == nil)
[newAnnotation setString:@""];
[newAnnotation registerUserName];
- [[self document] addAnnotation:newAnnotation toPage:page];
- [[self undoManager] setActionName:NSLocalizedString(@"Add Note",
@"Undo action name")];
+ [self addAnnotation:newAnnotation toPage:page];
if (toolMode == SKToolModeText || toolMode == SKToolModeNote)
[self setCurrentAnnotation:newAnnotation];
@@ -2669,19 +2670,14 @@
}
- (void)removeCurrentAnnotation:(id)sender{
- if ([currentAnnotation isSkimNote]) {
- [[self document] removeAnnotation:currentAnnotation];
- [[self undoManager] setActionName:NSLocalizedString(@"Remove Note",
@"Undo action name")];
- }
+ if ([currentAnnotation isSkimNote])
+ [self removeAnnotation:currentAnnotation];
}
- (void)removeThisAnnotation:(id)sender{
PDFAnnotation *annotation = [sender representedObject];
-
- if (annotation) {
- [[self document] removeAnnotation:annotation];
- [[self undoManager] setActionName:NSLocalizedString(@"Remove Note",
@"Undo action name")];
- }
+ if (annotation)
+ [self removeAnnotation:annotation];
}
- (void)editThisAnnotation:(id)sender {
@@ -4176,9 +4172,7 @@
// select a new copy of the annotation
PDFAnnotation *newAnnotation = [PDFAnnotation
newSkimNoteWithProperties:[newCurrentAnnotation SkimNoteProperties]];
[newAnnotation registerUserName];
- [self beginNewUndoGroupIfNeededWithCommit:YES];
- [[self document] addAnnotation:newAnnotation toPage:page];
- [[self undoManager] setActionName:NSLocalizedString(@"Add Note",
@"Undo action name")];
+ [self addAnnotation:newAnnotation toPage:page];
newCurrentAnnotation = newAnnotation;
} else if (([newCurrentAnnotation isMarkup] ||
(isInk && (newCurrentAnnotation != currentAnnotation ||
(modifiers & (NSEventModifierFlagShift | NSEventModifierFlagCapsLock))))) &&
@@ -4229,7 +4223,7 @@
[self beginNewUndoGroupIfNeededWithCommit:YES];
[newAnnotation setColor:[currentAnnotation color]];
[newAnnotation registerUserName];
- [[self document] removeAnnotation:newCurrentAnnotation];
+ [self removeAnnotation:newCurrentAnnotation];
[self removeCurrentAnnotation:nil];
[[self document] addAnnotation:newAnnotation toPage:page];
[[self undoManager] setActionName:NSLocalizedString(@"Join
Notes", @"Undo action name")];
@@ -4375,9 +4369,7 @@
[annotation setString:[currentAnnotation string]];
}
[annotation registerUserName];
- [self beginNewUndoGroupIfNeededWithCommit:NO];
- [[self document] addAnnotation:annotation toPage:page];
- [[self undoManager] setActionName:NSLocalizedString(@"Add Note",
@"Undo action name")];
+ [self addAnnotation:annotation toPage:page];
if (currentAnnotation) {
[self removeCurrentAnnotation:nil];
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