Revision: 14146
          http://sourceforge.net/p/skim-app/code/14146
Author:   hofman
Date:     2024-03-26 10:47:37 +0000 (Tue, 26 Mar 2024)
Log Message:
-----------
wrap miniaturize and deminiaturize completely in single method

Modified Paths:
--------------
    trunk/SKSnapshotWindowController.m

Modified: trunk/SKSnapshotWindowController.m
===================================================================
--- trunk/SKSnapshotWindowController.m  2024-03-25 17:40:32 UTC (rev 14145)
+++ trunk/SKSnapshotWindowController.m  2024-03-26 10:47:37 UTC (rev 14146)
@@ -610,90 +610,85 @@
     [NSGraphicsContext restoreGraphicsState];
 }
 
-- (void)miniaturizeWindow:(BOOL)miniaturize fromRect:(NSRect)startRect 
toRect:(NSRect)endRect {
-    NSWindow *window = [self window];
-    NSArray *filters = SKColorEffectFilters();
-    NSImage *contentImage = [self thumbnailWithSize:-1.0];
-    NSImage *windowImage;
-    
-    if (miniaturize) {
-        CGImageRef cgImage = CGWindowListCreateImage(CGRectNull, 
kCGWindowListOptionIncludingWindow, (CGWindowID)[window windowNumber], 
kCGWindowImageBoundsIgnoreFraming);
-        windowImage = [[NSImage alloc] initWithCGImage:cgImage size:[window 
frame].size];
-        CGImageRelease(cgImage);
-    } else {
-        NSBitmapImageRep *imageRep = [[[window contentView] superview] 
bitmapImageRepCachingDisplay];
-        if ([filters count] > 0 && [NSScroller preferredScrollerStyle] == 
NSScrollerStyleLegacy)
-            applyFiltersToImageRep(imageRep, filters, [window 
contentLayoutRect]);
-        windowImage = [[NSImage alloc] initWithSize:[window frame].size];
-        [windowImage addRepresentation:imageRep];
-    }
-    
-    SKAnimatedBorderlessWindow *miniaturizeWindow = 
[[SKAnimatedBorderlessWindow alloc] initWithContentRect:startRect];
-    [miniaturizeWindow setLevel:NSFloatingWindowLevel];
-    [miniaturizeWindow setHasShadow:YES];
-    [[miniaturizeWindow contentView] setWantsLayer:YES];
-    NSImageView *imageView = addImageView([miniaturizeWindow contentView], 
windowImage);
-    NSImageView *contentImageView = addImageView([miniaturizeWindow 
contentView], contentImage);
-    [contentImageView setContentFilters:filters];
-    if (miniaturize == NO)
-        [imageView setAlphaValue:0.0];
-    
-    [miniaturizeWindow orderFront:nil];
-    
-    if (miniaturize) {
-        [window setAnimationBehavior:NSWindowAnimationBehaviorNone];
-        [window orderOut:nil];
-        [window setAnimationBehavior:NSWindowAnimationBehaviorDefault];
-    }
-    
-    animating = YES;
-    
-    [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
-            [context setDuration:RESIZE_TIME_FACTOR * [miniaturizeWindow 
animationResizeTime:endRect]];
-            [[miniaturizeWindow animator] setFrame:endRect display:YES];
-            [[imageView animator] setAlphaValue:miniaturize ? 0.0 : 1.0];
-        }
-        completionHandler:^{
-            if (miniaturize == NO) {
-                [window setAnimationBehavior:NSWindowAnimationBehaviorNone];
-                [window orderFront:nil];
-                [self updateWindowLevel];
-                [window setAnimationBehavior:NSWindowAnimationBehaviorDefault];
-            }
-            [miniaturizeWindow orderOut:nil];
-            animating = NO;
-    }];
-    
-}
-
-- (void)miniaturize {
+- (void)miniaturizeWindow:(BOOL)miniaturize {
     if (animating)
         return;
     if ([[self delegate] 
respondsToSelector:@selector(snapshotController:miniaturizedRect:)]) {
-        NSRect dockRect = [[self delegate] snapshotController:self 
miniaturizedRect:YES];
-        NSRect startRect = [[self window] frame];
-        NSRect endRect = [self miniaturizedRectForDockingRect:dockRect];
+        NSWindow *window = [self window];
+        NSArray *filters = SKColorEffectFilters();
+        NSImage *contentImage = [self thumbnailWithSize:-1.0];
+        NSImage *windowImage;
+        NSRect startRect, endRect;
+        NSRect dockRect = [[self delegate] snapshotController:self 
miniaturizedRect:miniaturize];
+        dockRect = [self miniaturizedRectForDockingRect:dockRect];
         
-        [self miniaturizeWindow:YES fromRect:startRect toRect:endRect];
+        if (miniaturize) {
+            endRect = [[self window] frame];
+            startRect = dockRect;
+            
+            CGImageRef cgImage = CGWindowListCreateImage(CGRectNull, 
kCGWindowListOptionIncludingWindow, (CGWindowID)[window windowNumber], 
kCGWindowImageBoundsIgnoreFraming);
+            windowImage = [[NSImage alloc] initWithCGImage:cgImage 
size:[window frame].size];
+            CGImageRelease(cgImage);
+        } else {
+            startRect = [[self window] frame];
+            endRect = dockRect;
+            
+            NSBitmapImageRep *imageRep = [[[window contentView] superview] 
bitmapImageRepCachingDisplay];
+            if ([filters count] > 0 && [NSScroller preferredScrollerStyle] == 
NSScrollerStyleLegacy)
+                applyFiltersToImageRep(imageRep, filters, [window 
contentLayoutRect]);
+            windowImage = [[NSImage alloc] initWithSize:[window frame].size];
+            [windowImage addRepresentation:imageRep];
+        }
+        
+        SKAnimatedBorderlessWindow *miniaturizeWindow = 
[[SKAnimatedBorderlessWindow alloc] initWithContentRect:startRect];
+        [miniaturizeWindow setLevel:NSFloatingWindowLevel];
+        [miniaturizeWindow setHasShadow:YES];
+        [[miniaturizeWindow contentView] setWantsLayer:YES];
+        NSImageView *imageView = addImageView([miniaturizeWindow contentView], 
windowImage);
+        NSImageView *contentImageView = addImageView([miniaturizeWindow 
contentView], contentImage);
+        [contentImageView setContentFilters:filters];
+        if (miniaturize == NO)
+            [imageView setAlphaValue:0.0];
+        
+        [miniaturizeWindow orderFront:nil];
+        
+        if (miniaturize) {
+            [window setAnimationBehavior:NSWindowAnimationBehaviorNone];
+            [window orderOut:nil];
+            [window setAnimationBehavior:NSWindowAnimationBehaviorDefault];
+        }
+        
+        animating = YES;
+        
+        [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
+                [context setDuration:RESIZE_TIME_FACTOR * [miniaturizeWindow 
animationResizeTime:endRect]];
+                [[miniaturizeWindow animator] setFrame:endRect display:YES];
+                [[imageView animator] setAlphaValue:miniaturize ? 0.0 : 1.0];
+            }
+            completionHandler:^{
+                if (miniaturize == NO) {
+                    [window 
setAnimationBehavior:NSWindowAnimationBehaviorNone];
+                    [window orderFront:nil];
+                    [self updateWindowLevel];
+                    [window 
setAnimationBehavior:NSWindowAnimationBehaviorDefault];
+                }
+                [miniaturizeWindow orderOut:nil];
+                animating = NO;
+        }];
+    } else if (miniaturize) {
+        [[self window] orderOut:nil];
     } else {
-        [[self window] orderOut:nil];
+        [self showWindow:nil];
     }
-    [self setHasWindow:NO];
+    [self setHasWindow:miniaturize == NO];
 }
 
+- (void)miniaturize {
+    [self miniaturizeWindow:YES];
+}
+
 - (void)deminiaturize {
-    if (animating)
-        return;
-    if ([[self delegate] 
respondsToSelector:@selector(snapshotController:miniaturizedRect:)]) {
-        NSRect dockRect = [[self delegate] snapshotController:self 
miniaturizedRect:NO];
-        NSRect endRect = [[self window] frame];
-        NSRect startRect = [self miniaturizedRectForDockingRect:dockRect];
-        
-        [self miniaturizeWindow:NO fromRect:startRect toRect:endRect];
-    } else {
-        [self showWindow:self];
-    }
-    [self setHasWindow:YES];
+    [self miniaturizeWindow:NO];
 }
 
 #pragma mark KVO

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