Revision: 13357
          http://sourceforge.net/p/skim-app/code/13357
Author:   hofman
Date:     2023-03-13 17:43:03 +0000 (Mon, 13 Mar 2023)
Log Message:
-----------
Don't animate using sliding when user disabled motion. Convenience class 
methods to check whether we should animate.

Modified Paths:
--------------
    trunk/NSView_SKExtensions.h
    trunk/NSView_SKExtensions.m
    trunk/SKAnimatedBorderlessWindow.m
    trunk/SKBookmarkController.m
    trunk/SKDownloadController.m
    trunk/SKFullScreenWindow.m
    trunk/SKMainWindowController.m
    trunk/SKPreferenceController.m
    trunk/SKSideViewController.m
    trunk/SKSideWindow.m
    trunk/SKSplitView.m
    trunk/SKStatusBar.m

Modified: trunk/NSView_SKExtensions.h
===================================================================
--- trunk/NSView_SKExtensions.h 2023-03-10 10:29:26 UTC (rev 13356)
+++ trunk/NSView_SKExtensions.h 2023-03-13 17:43:03 UTC (rev 13357)
@@ -63,4 +63,7 @@
 - (NSLayoutConstraint *)constraintWithFirstItem:(id)item 
firstAttribute:(NSLayoutAttribute)attribute;
 - (NSLayoutConstraint *)constraintWithSecondItem:(id)item 
secondAttribute:(NSLayoutAttribute)attribute;
 
++ (BOOL)shouldShowSlideAnimation;
++ (BOOL)shouldShowFadeAnimation;
+
 @end

Modified: trunk/NSView_SKExtensions.m
===================================================================
--- trunk/NSView_SKExtensions.m 2023-03-10 10:29:26 UTC (rev 13356)
+++ trunk/NSView_SKExtensions.m 2023-03-13 17:43:03 UTC (rev 13357)
@@ -39,7 +39,14 @@
 #import "NSView_SKExtensions.h"
 #import "SKLineWell.h"
 #import "SKFontWell.h"
+#import "SKStringConstants.h"
 
+#if SDK_BEFORE(10_12)
+@interface NSWorkSpace (BDSKSierraDeclarations)
+- (void)accessibilityDisplayShouldReduceMotion;
+@end
+#endif
+
 @implementation NSView (SKExtensions)
 
 - (id)descendantOfClass:(Class)aClass {
@@ -128,6 +135,21 @@
     return nil;
 }
 
++ (BOOL)shouldShowSlideAnimation {
+    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey])
+        return NO;
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpartial-availability"
+    if (RUNNING_AFTER(10_12) && [[NSWorkspace sharedWorkspace] 
accessibilityDisplayShouldReduceMotion])
+        return NO;
+#pragma clang diagnostic pop
+    return YES;
+}
+
++ (BOOL)shouldShowFadeAnimation {
+    return NO == [[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey];
+}
+
 @end
 
 

Modified: trunk/SKAnimatedBorderlessWindow.m
===================================================================
--- trunk/SKAnimatedBorderlessWindow.m  2023-03-10 10:29:26 UTC (rev 13356)
+++ trunk/SKAnimatedBorderlessWindow.m  2023-03-13 17:43:03 UTC (rev 13357)
@@ -38,6 +38,7 @@
 
 #import "SKAnimatedBorderlessWindow.h"
 #import "SKStringConstants.h"
+#import "NSView_SKExtensions.h"
 
 #define ALPHA_VALUE 1.0
 #define FADE_IN_DURATION 0.3
@@ -123,7 +124,7 @@
     
     [self setAlphaValue:[self defaultAlphaValue]];
     
-    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey]) {
+    if ([NSView shouldShowFadeAnimation] == NO) {
         [self remove];
     } else {
         [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
@@ -143,7 +144,7 @@
         [self setAlphaValue:0.0];
     [super orderFront:self];
     
-    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey]) {
+    if ([NSView shouldShowFadeAnimation] == NO) {
         [self setAlphaValue:[self defaultAlphaValue]];
     } else {
         [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){

Modified: trunk/SKBookmarkController.m
===================================================================
--- trunk/SKBookmarkController.m        2023-03-10 10:29:26 UTC (rev 13356)
+++ trunk/SKBookmarkController.m        2023-03-13 17:43:03 UTC (rev 13357)
@@ -341,7 +341,7 @@
 
 - (void)insertBookmarks:(NSArray *)newBookmarks atIndexes:(NSIndexSet 
*)indexes ofBookmark:(SKBookmark *)parent animate:(BOOL)animate {
     NSTableViewAnimationOptions options = NSTableViewAnimationEffectGap | 
NSTableViewAnimationSlideDown;
-    if (animate == NO || [self isWindowLoaded] == NO || [[self window] 
isVisible] == NO || [[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey])
+    if (animate == NO || [self isWindowLoaded] == NO || [[self window] 
isVisible] == NO || [NSView shouldShowSlideAnimation] == NO)
         options = NSTableViewAnimationEffectNone;
     if (needsBeginUpdates) {
         [outlineView beginUpdates];
@@ -353,7 +353,7 @@
 
 - (void)removeBookmarksAtIndexes:(NSIndexSet *)indexes ofBookmark:(SKBookmark 
*)parent animate:(BOOL)animate {
     NSTableViewAnimationOptions options = NSTableViewAnimationEffectGap | 
NSTableViewAnimationSlideUp;
-    if (animate == NO || [self isWindowLoaded] == NO || [[self window] 
isVisible] == NO || [[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey])
+    if (animate == NO || [self isWindowLoaded] == NO || [[self window] 
isVisible] == NO || [NSView shouldShowSlideAnimation] == NO)
         options = NSTableViewAnimationEffectNone;
     if (needsBeginUpdates) {
         [outlineView beginUpdates];
@@ -468,7 +468,7 @@
     [self getInsertionFolder:&item childIndex:&idx];
     [self insertBookmark:folder atIndex:idx ofBookmark:item animate:YES];
     
-    CGFloat delay = [[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey] ? 0.0 : 0.25;
+    CGFloat delay = [NSView shouldShowSlideAnimation] ? 0.25 : 0.0;
     DISPATCH_MAIN_AFTER_SEC(delay, ^{
         NSInteger row = [outlineView rowForItem:folder];
         [outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:row] 
byExtendingSelection:NO];

Modified: trunk/SKDownloadController.m
===================================================================
--- trunk/SKDownloadController.m        2023-03-10 10:29:26 UTC (rev 13356)
+++ trunk/SKDownloadController.m        2023-03-13 17:43:03 UTC (rev 13357)
@@ -262,7 +262,7 @@
 - (void)addObjectToDownloads:(SKDownload *)download {
     NSInteger row = [self countOfDownloads];
     NSTableViewAnimationOptions options = NSTableViewAnimationEffectGap | 
NSTableViewAnimationSlideDown;
-    if ([self isWindowLoaded] == NO || [[self window] isVisible] == NO || 
[[NSUserDefaults standardUserDefaults] boolForKey:SKDisableAnimationsKey])
+    if ([self isWindowLoaded] == NO || [[self window] isVisible] == NO || 
[NSView shouldShowSlideAnimation] == NO)
         options = NSTableViewAnimationEffectNone;
     [tableView beginUpdates];
     [tableView insertRowsAtIndexes:[NSIndexSet indexSetWithIndex:row] 
withAnimation:options];
@@ -272,7 +272,7 @@
 
 - (void)removeObjectsFromDownloadsAtIndexes:(NSIndexSet *)indexes {
     NSTableViewAnimationOptions options = NSTableViewAnimationEffectGap | 
NSTableViewAnimationSlideUp;
-    if ([self isWindowLoaded] == NO || [[self window] isVisible] == NO || 
[[NSUserDefaults standardUserDefaults] boolForKey:SKDisableAnimationsKey])
+    if ([self isWindowLoaded] == NO || [[self window] isVisible] == NO || 
[NSView shouldShowSlideAnimation] == NO)
         options = NSTableViewAnimationEffectNone;
     [tableView beginUpdates];
     [tableView removeRowsAtIndexes:indexes withAnimation:options];

Modified: trunk/SKFullScreenWindow.m
===================================================================
--- trunk/SKFullScreenWindow.m  2023-03-10 10:29:26 UTC (rev 13356)
+++ trunk/SKFullScreenWindow.m  2023-03-13 17:43:03 UTC (rev 13357)
@@ -38,6 +38,7 @@
 
 #import "SKFullScreenWindow.h"
 #import "SKStringConstants.h"
+#import "NSView_SKExtensions.h"
 
 #define DURATION 0.3
 
@@ -66,7 +67,7 @@
 - (BOOL)canBecomeMainWindow { return isMain; }
 
 - (void)fadeOutBlocking:(BOOL)blocking {
-    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey]) {
+    if ([NSView shouldShowFadeAnimation] == NO) {
         [self orderOut:nil];
     } else {
         __block BOOL wait = blocking;
@@ -84,7 +85,7 @@
 }
 
 - (void)fadeInBlocking:(BOOL)blocking {
-    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey]) {
+    if ([NSView shouldShowFadeAnimation]) {
         [self orderFront:nil];
     } else {
         __block BOOL wait = blocking;

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2023-03-10 10:29:26 UTC (rev 13356)
+++ trunk/SKMainWindowController.m      2023-03-13 17:43:03 UTC (rev 13357)
@@ -1674,7 +1674,7 @@
     if ([overviewView window])
         return;
     
-    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey])
+    if ([NSView shouldShowFadeAnimation] == NO)
         animate = NO;
     
     if (overviewView == nil) {
@@ -1768,7 +1768,7 @@
         return;
     }
     
-    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey])
+    if ([NSView shouldShowFadeAnimation] == NO)
         animate = NO;
     
     BOOL isMainWindow = [overviewContentView window] == mainWindow;
@@ -1869,7 +1869,7 @@
     if (mwcFlags.isAnimatingFindBar)
         return;
     
-    BOOL animate = NO == [[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey];
+    BOOL animate = [NSView shouldShowSlideAnimation];
     NSView *findBar = [findController view];
     NSView *contentView = [findBar superview];
     NSLayoutConstraint *newTopConstraint = nil;
@@ -1924,7 +1924,7 @@
         [findField selectText:nil];
     } else if (mwcFlags.isAnimatingFindBar == 0) {
         
-        BOOL animate = NO == [[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey];
+        BOOL animate = [NSView shouldShowSlideAnimation];
         NSView *contentView = mwcFlags.fullSizeContent ? pdfContentView : 
centerContentView;
         CGFloat barHeight = NSHeight([findBar frame]);
         NSArray *constraints = nil;
@@ -2359,7 +2359,7 @@
             NSUInteger row = [[rightSideController.snapshotArrayController 
arrangedObjects] indexOfObject:controller];
             if (row != NSNotFound) {
                 NSTableViewAnimationOptions options = 
NSTableViewAnimationEffectGap | NSTableViewAnimationSlideDown;
-                if ([self rightSidePaneIsOpen] == NO || [self 
rightSidePaneState] != SKSidePaneStateSnapshot || [[NSUserDefaults 
standardUserDefaults] boolForKey:SKDisableAnimationsKey])
+                if ([self rightSidePaneIsOpen] == NO || [self 
rightSidePaneState] != SKSidePaneStateSnapshot || [NSView 
shouldShowSlideAnimation] == NO)
                     options = NSTableViewAnimationEffectNone;
                 [rightSideController.snapshotTableView 
insertRowsAtIndexes:[NSIndexSet indexSetWithIndex:row] withAnimation:options];
             }
@@ -2378,7 +2378,7 @@
         NSUInteger row = [[rightSideController.snapshotArrayController 
arrangedObjects] indexOfObject:controller];
         if (row != NSNotFound) {
             NSTableViewAnimationOptions options = 
NSTableViewAnimationEffectGap | NSTableViewAnimationSlideUp;
-            if ([self rightSidePaneIsOpen] == NO || [self rightSidePaneState] 
!= SKSidePaneStateSnapshot || [[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey])
+            if ([self rightSidePaneIsOpen] == NO || [self rightSidePaneState] 
!= SKSidePaneStateSnapshot || [NSView shouldShowSlideAnimation] == NO)
                 options = NSTableViewAnimationEffectNone;
             [rightSideController.snapshotTableView 
removeRowsAtIndexes:[NSIndexSet indexSetWithIndex:row] withAnimation:options];
         }

Modified: trunk/SKPreferenceController.m
===================================================================
--- trunk/SKPreferenceController.m      2023-03-10 10:29:26 UTC (rev 13356)
+++ trunk/SKPreferenceController.m      2023-03-13 17:43:03 UTC (rev 13357)
@@ -157,7 +157,7 @@
             [NSLayoutConstraint constraintWithItem:view 
attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual 
toItem:contentView attribute:NSLayoutAttributeLeading multiplier:1.0 
constant:0.0]];
         [[constraints lastObject] setPriority:NSLayoutPriorityDefaultLow];
         
-        if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey]) {
+        if ([NSView shouldShowFadeAnimation] == NO) {
             [contentView replaceSubview:oldView with:view];
             [NSLayoutConstraint activateConstraints:constraints];
             [window setFrame:frame display:YES];

Modified: trunk/SKSideViewController.m
===================================================================
--- trunk/SKSideViewController.m        2023-03-10 10:29:26 UTC (rev 13356)
+++ trunk/SKSideViewController.m        2023-03-13 17:43:03 UTC (rev 13357)
@@ -95,7 +95,7 @@
     if ([newView superview] != nil)
         return;
     
-    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey] ||
+    if ([NSView shouldShowFadeAnimation] == NO ||
         [currentView window] == nil)
         animate = NO;
     

Modified: trunk/SKSideWindow.m
===================================================================
--- trunk/SKSideWindow.m        2023-03-10 10:29:26 UTC (rev 13356)
+++ trunk/SKSideWindow.m        2023-03-13 17:43:03 UTC (rev 13357)
@@ -127,7 +127,7 @@
     [window addChildWindow:self ordered:NSWindowAbove];
     
     frame.size.width = NSWidth([mainContentView frame]) + CONTENT_INSET;
-    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey]) {
+    if ([NSView shouldShowSlideAnimation]) {
         [self setFrame:frame display:YES];
         if ([window isKeyWindow])
             [self makeKeyAndOrderFront:nil];

Modified: trunk/SKSplitView.m
===================================================================
--- trunk/SKSplitView.m 2023-03-10 10:29:26 UTC (rev 13356)
+++ trunk/SKSplitView.m 2023-03-13 17:43:03 UTC (rev 13357)
@@ -38,6 +38,7 @@
 
 #import "SKSplitView.h"
 #import "SKStringConstants.h"
+#import "NSView_SKExtensions.h"
 
 
 @implementation SKSplitView
@@ -114,7 +115,7 @@
 }
 
 - (void)setPosition:(CGFloat)position ofDividerAtIndex:(NSInteger)dividerIndex 
animate:(BOOL)animate {
-    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey] ||
+    if ([NSView shouldShowSlideAnimation] == NO ||
         [self window] == nil || dividerIndex > 1)
         animate = NO;
     

Modified: trunk/SKStatusBar.m
===================================================================
--- trunk/SKStatusBar.m 2023-03-10 10:29:26 UTC (rev 13356)
+++ trunk/SKStatusBar.m 2023-03-13 17:43:03 UTC (rev 13357)
@@ -136,7 +136,7 @@
 - (void)toggleBelowView:(NSView *)view animate:(BOOL)animate {
     if (animating)
         return;
-    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableAnimationsKey])
+    if ([NSView shouldShowSlideAnimation] == NO)
         animate = NO;
     
     NSView *contentView = [view superview];

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

Reply via email to