Revision: 14457
http://sourceforge.net/p/skim-app/code/14457
Author: hofman
Date: 2024-09-17 16:05:39 +0000 (Tue, 17 Sep 2024)
Log Message:
-----------
Register undo for page rotation by gestures only for full rotationinstead of 90
degree steps
Modified Paths:
--------------
trunk/SKMainWindowController_UI.m
trunk/SKPDFView.h
trunk/SKPDFView.m
Modified: trunk/SKMainWindowController_UI.m
===================================================================
--- trunk/SKMainWindowController_UI.m 2024-09-17 15:47:33 UTC (rev 14456)
+++ trunk/SKMainWindowController_UI.m 2024-09-17 16:05:39 UTC (rev 14457)
@@ -1570,8 +1570,15 @@
[self showSnapshotAtPageNumber:pageNum forRect:rect
scaleFactor:scaleFactor autoFits:autoFits];
}
-- (void)PDFView:(PDFView *)sender rotatePageAtIndex:(NSUInteger)idx
by:(NSInteger)rotation {
- [self rotatePageAtIndex:idx by:rotation];
+- (void)PDFView:(PDFView *)sender didRotatePageAtIndex:(NSUInteger)idx
by:(NSInteger)rotation {
+ NSUndoManager *undoManager = [[self document] undoManager];
+ [[undoManager prepareWithInvocationTarget:self] rotatePageAtIndex:idx
by:-rotation];
+ [undoManager setActionName:NSLocalizedString(@"Rotate Page", @"Undo action
name")];
+ [undoManager setActionIsDiscardable:YES];
+
+ PDFPage *page = [[pdfView document] pageAtIndex:idx];
+ [[NSNotificationCenter defaultCenter]
postNotificationName:SKPDFPageBoundsDidChangeNotification
+ object:[pdfView
document] userInfo:@{SKPDFPageActionKey:SKPDFPageActionRotate,
SKPDFPagePageKey:page}];
}
- (NSUndoManager *)undoManagerForPDFView:(PDFView *)sender {
Modified: trunk/SKPDFView.h
===================================================================
--- trunk/SKPDFView.h 2024-09-17 15:47:33 UTC (rev 14456)
+++ trunk/SKPDFView.h 2024-09-17 16:05:39 UTC (rev 14457)
@@ -125,7 +125,7 @@
- (void)PDFView:(PDFView *)sender showSnapshotAtPageNumber:(NSInteger)pageNum
forRect:(NSRect)rect scaleFactor:(CGFloat)scaleFactor autoFits:(BOOL)autoFits;
- (void)PDFViewPerformHideFind:(PDFView *)sender;
- (BOOL)PDFViewIsFindVisible:(PDFView *)sender;
-- (void)PDFView:(PDFView *)sender rotatePageAtIndex:(NSUInteger)idx
by:(NSInteger)rotation;
+- (void)PDFView:(PDFView *)sender didRotatePageAtIndex:(NSUInteger)idx
by:(NSInteger)rotation;
- (nullable NSUndoManager *)undoManagerForPDFView:(PDFView *)sender;
@end
Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m 2024-09-17 15:47:33 UTC (rev 14456)
+++ trunk/SKPDFView.m 2024-09-17 16:05:39 UTC (rev 14457)
@@ -2076,23 +2076,35 @@
}
- (void)rotateWithEvent:(NSEvent *)theEvent {
- if ([theEvent phase] == NSEventPhaseBegan) {
+ NSEventPhase phase = [theEvent phase];
+ if (phase == NSEventPhaseBegan) {
PDFPage *page = [self pageAndPoint:NULL forEvent:theEvent nearest:YES];
gestureRotation = 0.0;
gesturePageIndex = [(page ?: [self currentPage]) pageIndex];
+ } else if (phase == NSEventPhaseMayBegin) {
+ gestureRotation = 0.0;
+ gesturePageIndex = NSNotFound;
+ return;
+ } else if (phase == NSEventPhaseNone || gesturePageIndex == NSNotFound) {
+ return;
}
+ NSInteger prevRotation = 90 * (NSInteger)round(gestureRotation / 90.0);
gestureRotation -= [theEvent rotation];
- if (fabs(gestureRotation) > 45.0 && gesturePageIndex != NSNotFound) {
- CGFloat rotation = 90.0 * round(gestureRotation / 90.0);
- if ([[self delegate]
respondsToSelector:@selector(PDFView:rotatePageAtIndex:by:)]) {
- [[self delegate] PDFView:self rotatePageAtIndex:gesturePageIndex
by:(NSInteger)rotation];
- } else {
+ NSInteger rotation = 90 * (NSInteger)round(gestureRotation / 90.0);
+ if (((rotation - prevRotation) % 360)) {
+ PDFPage *page = [[self document] pageAtIndex:gesturePageIndex];
+ [page setRotation:[page rotation] + rotation - prevRotation];
+ }
+ if (phase == NSEventPhaseEnded) {
+ if ((rotation % 360) && [[self delegate]
respondsToSelector:@selector(PDFView:didRotatePageAtIndex:by:)])
+ [[self delegate] PDFView:self
didRotatePageAtIndex:gesturePageIndex by:rotation % 360];
+ gestureRotation = 0.0;
+ gesturePageIndex = NSNotFound;
+ } else if (phase == NSEventPhaseCancelled) {
+ if (gesturePageIndex != NSNotFound) {
PDFPage *page = [[self document] pageAtIndex:gesturePageIndex];
- [page setRotation:[page rotation] + (NSInteger)rotation];
+ [page setRotation:[page rotation] - rotation];
}
- gestureRotation -= rotation;
- }
- if (([theEvent phase] == NSEventPhaseEnded || [theEvent phase] ==
NSEventPhaseCancelled)) {
gestureRotation = 0.0;
gesturePageIndex = NSNotFound;
}
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