Revision: 13523
          http://sourceforge.net/p/skim-app/code/13523
Author:   hofman
Date:     2023-07-02 16:28:42 +0000 (Sun, 02 Jul 2023)
Log Message:
-----------
highlight thumbnail in overview with emphasized selection when showing context 
menu

Modified Paths:
--------------
    trunk/SKThumbnailView.h
    trunk/SKThumbnailView.m

Modified: trunk/SKThumbnailView.h
===================================================================
--- trunk/SKThumbnailView.h     2023-07-01 20:27:41 UTC (rev 13522)
+++ trunk/SKThumbnailView.h     2023-07-02 16:28:42 UTC (rev 13523)
@@ -44,6 +44,7 @@
 @interface SKThumbnailView : SKGroupView <NSDraggingSource> {
     SKThumbnail *thumbnail;
     BOOL selected;
+    BOOL menuHighlighted;
     NSBackgroundStyle backgroundStyle;
     NSInteger highlightLevel;
     NSImageView *imageView;
@@ -56,6 +57,7 @@
 
 @property (nonatomic, retain) SKThumbnail *thumbnail;
 @property (nonatomic, getter=isSelected) BOOL selected;
+@property (nonatomic, getter=isMenuHighlighted) BOOL menuHighlighted;
 @property (nonatomic) NSBackgroundStyle backgroundStyle;
 @property (nonatomic) NSInteger highlightLevel;
 @property (nonatomic, getter=isMarked) BOOL marked;

Modified: trunk/SKThumbnailView.m
===================================================================
--- trunk/SKThumbnailView.m     2023-07-01 20:27:41 UTC (rev 13522)
+++ trunk/SKThumbnailView.m     2023-07-02 16:28:42 UTC (rev 13523)
@@ -69,7 +69,7 @@
 
 @implementation SKThumbnailView
 
-@synthesize selected, thumbnail, backgroundStyle, highlightLevel, controller;
+@synthesize selected, menuHighlighted, thumbnail, backgroundStyle, 
highlightLevel, controller;
 @dynamic marked;
 
 - (void)commonInit {
@@ -191,7 +191,7 @@
 
 - (void)updateImageHighlight {
     if (RUNNING_AFTER(10_15)) {
-        if ([self isSelected]) {
+        if ([self isSelected] || [self isMenuHighlighted]) {
             if (imageHighlightView == nil) {
                 imageHighlightView = [self newHighlightView];
 #pragma clang diagnostic push
@@ -203,6 +203,7 @@
                 [self addSubview:imageHighlightView positioned:NSWindowBelow 
relativeTo:nil];
                 [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(updateImageHighlightMask:) 
name:NSViewFrameDidChangeNotification object:imageHighlightView];
             }
+            [imageHighlightView setEmphasized:[self isMenuHighlighted]];
             [self updateImageHighlightMask:nil];
         } else if (imageHighlightView) {
             [[NSNotificationCenter defaultCenter] removeObserver:self 
name:NSViewFrameDidChangeNotification object:imageHighlightView];
@@ -279,6 +280,13 @@
     }
 }
 
+- (void)setMenuHighlighted:(BOOL)newMenuHighlighted {
+    if (menuHighlighted != newMenuHighlighted) {
+        menuHighlighted = newMenuHighlighted;
+        [self updateImageHighlight];
+    }
+}
+
 - (void)setBackgroundStyle:(NSBackgroundStyle)newBackgroundStyle {
     if (backgroundStyle != newBackgroundStyle) {
         backgroundStyle = newBackgroundStyle;
@@ -321,11 +329,13 @@
     if (RUNNING_AFTER(10_15))
         return;
     
-    if ([self isSelected]) {
+    if ([self isSelected] || [self isMenuHighlighted]) {
         NSRect rect = NSInsetRect([imageView frame], -SELECTION_MARGIN, 
-SELECTION_MARGIN);
         if (NSIntersectsRect(dirtyRect, rect)) {
             [NSGraphicsContext saveGraphicsState];
-            if ([self backgroundStyle] == NSBackgroundStyleDark)
+            if ([self isMenuHighlighted])
+                [[NSColor alternateSelectedControlColor] setFill];
+            else if ([self backgroundStyle] == NSBackgroundStyleDark)
                 [[NSColor darkGrayColor] setFill];
             else
                 [[NSColor secondarySelectedControlColor] setFill];
@@ -497,6 +507,34 @@
     }
 }
 
+- (void)applyMenuHighlighted:(BOOL)flag {
+    NSCollectionView *collectionView = [[self controller] collectionView];
+    NSIndexSet *selectionIndexes = [collectionView selectionIndexes];
+    if ([selectionIndexes containsIndex:[[[self thumbnail] page] pageIndex]]) {
+        [selectionIndexes enumerateIndexesUsingBlock:^(NSUInteger i, BOOL 
*stop){
+            NSCollectionViewItem *item = (RUNNING_BEFORE(10_11)) ? 
[collectionView itemAtIndex:i] : [collectionView itemAtIndexPath:[NSIndexPath 
indexPathForItem:i inSection:0]];
+            [(SKThumbnailView *)[item view] setMenuHighlighted:flag];
+        }];
+    } else {
+        [self setMenuHighlighted:flag];
+    }
+}
+
+- (void)handleMenuDidEndTracking:(NSNotification *)notification {
+    [[NSNotificationCenter defaultCenter] removeObserver:self 
name:NSMenuDidEndTrackingNotification object:[notification object]];
+    [self applyMenuHighlighted:NO];
+}
+
+- (void)willOpenMenu:(NSMenu *)menu
+           withEvent:(NSEvent *)event {
+    [self applyMenuHighlighted:YES];
+}
+
+- (void)didCloseMenu:(NSMenu *)menu
+           withEvent:(NSEvent *)event {
+    [self applyMenuHighlighted:NO];
+}
+
 - (NSMenu *)menuForEvent:(NSEvent *)theEvent {
     PDFPage *page = [[self thumbnail] page];
     NSMenu *menu = nil;
@@ -504,6 +542,10 @@
         menu = [[[NSMenu alloc] initWithTitle:@""] autorelease];
         [menu addItemWithTitle:NSLocalizedString(@"Copy", @"Menu item title") 
action:@selector(copy:) target:self];
         [menu addItemWithTitle:NSLocalizedString(@"Copy URL", @"Menu item 
title") action:@selector(copyURL:) target:self];
+        if (RUNNING(10_11)) {
+            [self applyMenuHighlighted:YES];
+            [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleMenuDidEndTracking:) 
name:NSMenuDidEndTrackingNotification object:menu];
+        }
     }
     return menu;
 }

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