2023-11-03 13:31:39 +00:00
|
|
|
// This file Copyright © Transmission authors and contributors.
|
2023-06-27 19:40:44 +00:00
|
|
|
// It may be used under the MIT (SPDX: MIT) license.
|
|
|
|
// License text can be found in the licenses/ folder.
|
|
|
|
|
|
|
|
#import "TorrentCellControlButton.h"
|
|
|
|
#import "TorrentTableView.h"
|
|
|
|
#import "Torrent.h"
|
2023-11-05 20:35:22 +00:00
|
|
|
#import "TorrentCell.h"
|
2023-06-27 19:40:44 +00:00
|
|
|
|
|
|
|
@interface TorrentCellControlButton ()
|
|
|
|
@property(nonatomic) NSTrackingArea* fTrackingArea;
|
|
|
|
@property(nonatomic, copy) NSString* controlImageSuffix;
|
2023-11-05 20:35:22 +00:00
|
|
|
@property(nonatomic) IBOutlet TorrentCell* torrentCell;
|
|
|
|
@property(nonatomic, readonly) TorrentTableView* torrentTableView;
|
2023-06-27 19:40:44 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TorrentCellControlButton
|
|
|
|
|
2023-11-05 20:35:22 +00:00
|
|
|
- (TorrentTableView*)torrentTableView
|
|
|
|
{
|
|
|
|
return self.torrentCell.fTorrentTableView;
|
|
|
|
}
|
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
2023-11-05 20:35:22 +00:00
|
|
|
[super awakeFromNib];
|
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
self.controlImageSuffix = @"Off";
|
|
|
|
[self updateImage];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)resetImage
|
|
|
|
{
|
|
|
|
self.controlImageSuffix = @"Off";
|
|
|
|
[self updateImage];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseEntered:(NSEvent*)event
|
|
|
|
{
|
|
|
|
[super mouseEntered:event];
|
|
|
|
self.controlImageSuffix = @"Hover";
|
|
|
|
[self updateImage];
|
|
|
|
|
|
|
|
[self.torrentTableView hoverEventBeganForView:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseExited:(NSEvent*)event
|
|
|
|
{
|
|
|
|
[super mouseExited:event];
|
|
|
|
self.controlImageSuffix = @"Off";
|
|
|
|
[self updateImage];
|
|
|
|
|
|
|
|
[self.torrentTableView hoverEventEndedForView:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseDown:(NSEvent*)event
|
|
|
|
{
|
|
|
|
//when filterbar is shown, we need to remove focus otherwise action fails
|
|
|
|
[self.window makeFirstResponder:self.torrentTableView];
|
|
|
|
|
|
|
|
[super mouseDown:event];
|
|
|
|
self.controlImageSuffix = @"On";
|
|
|
|
[self updateImage];
|
|
|
|
|
|
|
|
[self.torrentTableView hoverEventEndedForView:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateImage
|
|
|
|
{
|
|
|
|
NSImage* controlImage;
|
|
|
|
Torrent* torrent = [self.torrentTableView itemAtRow:[self.torrentTableView rowForView:self]];
|
|
|
|
if (torrent.active)
|
|
|
|
{
|
|
|
|
controlImage = [NSImage imageNamed:[@"Pause" stringByAppendingString:self.controlImageSuffix]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (NSApp.currentEvent.modifierFlags & NSEventModifierFlagOption)
|
|
|
|
{
|
|
|
|
controlImage = [NSImage imageNamed:[@"ResumeNoWait" stringByAppendingString:self.controlImageSuffix]];
|
|
|
|
}
|
|
|
|
else if (torrent.waitingToStart)
|
|
|
|
{
|
|
|
|
controlImage = [NSImage imageNamed:[@"Pause" stringByAppendingString:self.controlImageSuffix]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
controlImage = [NSImage imageNamed:[@"Resume" stringByAppendingString:self.controlImageSuffix]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.image = controlImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateTrackingAreas
|
|
|
|
{
|
|
|
|
if (self.fTrackingArea != nil)
|
|
|
|
{
|
|
|
|
[self removeTrackingArea:self.fTrackingArea];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSTrackingAreaOptions opts = (NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways);
|
|
|
|
self.fTrackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds options:opts owner:self userInfo:nil];
|
|
|
|
[self addTrackingArea:self.fTrackingArea];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|