fix: empty tableview rows on macOS (#4333)

This commit is contained in:
SweetPPro 2022-12-10 06:06:00 +11:00 committed by GitHub
parent a937dfc897
commit 9f2a981c8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 103 additions and 3 deletions

View File

@ -21,6 +21,7 @@
3C7A11980D0B2EE300B5701F /* getgateway.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C7A11920D0B2EE300B5701F /* getgateway.h */; };
3C7A11990D0B2EE300B5701F /* natpmp.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C7A11930D0B2EE300B5701F /* natpmp.c */; };
3C7A119A0D0B2EE300B5701F /* natpmp.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C7A11940D0B2EE300B5701F /* natpmp.h */; };
454BB0562941E8D800F99F38 /* GroupTextCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = 454BB0542941E8D800F99F38 /* GroupTextCell.mm */; };
457AF8EB28604AFC00BCF74F /* Toolbar.mm in Sources */ = {isa = PBXBuildFile; fileRef = 457AF8EA28604AFC00BCF74F /* Toolbar.mm */; };
45A7D3292843B54D00F0C32A /* GroupPopUpButtonCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = 45A7D3282843B54D00F0C32A /* GroupPopUpButtonCell.mm */; };
45A7D32C2843B55F00F0C32A /* PriorityPopUpButtonCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = 45A7D32B2843B55F00F0C32A /* PriorityPopUpButtonCell.mm */; };
@ -621,6 +622,8 @@
3C7A11920D0B2EE300B5701F /* getgateway.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = getgateway.h; sourceTree = "<group>"; };
3C7A11930D0B2EE300B5701F /* natpmp.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = natpmp.c; sourceTree = "<group>"; };
3C7A11940D0B2EE300B5701F /* natpmp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = natpmp.h; sourceTree = "<group>"; };
454BB0542941E8D800F99F38 /* GroupTextCell.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GroupTextCell.mm; sourceTree = "<group>"; };
454BB0552941E8D800F99F38 /* GroupTextCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupTextCell.h; sourceTree = "<group>"; };
455C0939287767270003A078 /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/PrefsWindow.strings; sourceTree = "<group>"; };
455C093A287767290003A078 /* da */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = da; path = da.lproj/PrefsWindow.strings; sourceTree = "<group>"; };
455C093B2877672C0003A078 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/PrefsWindow.strings; sourceTree = "<group>"; };
@ -1095,7 +1098,6 @@
BEFC1E1D0C07861A00B0BB3C /* completion.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = completion.cc; sourceTree = "<group>"; };
BEFC1E1E0C07861A00B0BB3C /* clients.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = clients.h; sourceTree = "<group>"; };
BEFC1E1F0C07861A00B0BB3C /* clients.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = clients.cc; sourceTree = "<group>"; };
C1425B381EE9C805001DB853 /* peer-socket.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = "peer-socket.cc"; sourceTree = "<group>"; };
C1033E031A3279B800EF44D8 /* crypto-utils-fallback.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = "crypto-utils-fallback.cc"; sourceTree = "<group>"; };
C1033E041A3279B800EF44D8 /* crypto-utils-ccrypto.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = "crypto-utils-ccrypto.cc"; sourceTree = "<group>"; };
C1033E051A3279B800EF44D8 /* crypto-utils.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = "crypto-utils.cc"; sourceTree = "<group>"; };
@ -1115,6 +1117,7 @@
C1425B331EE9C5EA001DB85F /* tr-assert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "tr-assert.h"; sourceTree = "<group>"; };
C1425B341EE9C5EA001DB85F /* tr-macros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "tr-macros.h"; sourceTree = "<group>"; };
C1425B381EE9C805001DB851 /* peer-socket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "peer-socket.h"; sourceTree = "<group>"; };
C1425B381EE9C805001DB853 /* peer-socket.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = "peer-socket.cc"; sourceTree = "<group>"; };
C16089E41F092A1E00CEFC36 /* utp_api.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = utp_api.cpp; sourceTree = "<group>"; };
C16089E51F092A1E00CEFC36 /* utp_callbacks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = utp_callbacks.cpp; sourceTree = "<group>"; };
C16089E61F092A1E00CEFC36 /* utp_callbacks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = utp_callbacks.h; sourceTree = "<group>"; };
@ -1414,6 +1417,8 @@
4D364D9F091FBB2C00377D12 /* TorrentTableView.mm */,
4DCCBB3D09C3D71100D3CABF /* TorrentCell.h */,
4DCCBB3C09C3D71100D3CABF /* TorrentCell.mm */,
454BB0552941E8D800F99F38 /* GroupTextCell.h */,
454BB0542941E8D800F99F38 /* GroupTextCell.mm */,
A21A9BE0106D86A800F1C3C1 /* TrackerNode.h */,
A21A9BE1106D86A800F1C3C1 /* TrackerNode.mm */,
A2725B6C0DE5C4F5003445E7 /* FileListNode.h */,
@ -3062,6 +3067,7 @@
A2E57BA713109E6B00A7DAB1 /* FilterBarController.mm in Sources */,
A2B5B4E91880665E0071A66A /* ShareTorrentFileHelper.mm in Sources */,
A22BAE281388040500FB022F /* NSMutableArrayAdditions.mm in Sources */,
454BB0562941E8D800F99F38 /* GroupTextCell.mm in Sources */,
A2966E8713DAF74C007B52DF /* GlobalOptionsPopoverViewController.mm in Sources */,
A234EA541453563B000F3E97 /* NSImageAdditions.mm in Sources */,
A2AB883E16A399A6008FAD50 /* VDKQueue.mm in Sources */,

View File

@ -57,6 +57,7 @@ set(${PROJECT_NAME}_SOURCES
FilterBarView.mm
FilterButton.mm
GlobalOptionsPopoverViewController.mm
GroupTextCell.mm
GroupToolbarItem.mm
GroupsController.mm
GroupsPrefsController.mm

View File

@ -5223,6 +5223,9 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool
self.fStackViewHeightConstraints = [NSLayoutConstraint constraintsWithVisualFormat:constraintsString options:0
metrics:nil
views:views];
//redraw table to avoid empty cells
[self.fTableView reloadData];
}
//add height constraint to fStackView

9
macosx/GroupTextCell.h Normal file
View File

@ -0,0 +1,9 @@
// This file Copyright © 2022 Transmission authors and contributors.
// It may be used under the MIT (SPDX: MIT) license.
// License text can be found in the licenses/ folder.
#import <AppKit/AppKit.h>
@interface GroupTextCell : NSTextFieldCell
@end

32
macosx/GroupTextCell.mm Normal file
View File

@ -0,0 +1,32 @@
// This file Copyright © 2022 Transmission authors and contributors.
// It may be used under the MIT (SPDX: MIT) license.
// License text can be found in the licenses/ folder.
#import "GroupTextCell.h"
#import "TorrentGroup.h"
@implementation GroupTextCell
//vertically align text
- (NSRect)titleRectForBounds:(NSRect)theRect
{
NSRect titleFrame = [super titleRectForBounds:theRect];
NSSize titleSize = [[self attributedStringValue] size];
titleFrame.origin.y = NSMidY(theRect) - (CGFloat)1.0 - titleSize.height * (CGFloat)0.5;
titleFrame.origin.x = theRect.origin.x;
return titleFrame;
}
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView
{
//set font size and color
NSRect titleRect = [self titleRectForBounds:cellFrame];
NSMutableAttributedString* string = [[self attributedStringValue] mutableCopy];
NSDictionary* attributes = [NSDictionary
dictionaryWithObjects:@[ [NSFont boldSystemFontOfSize:11.0], [NSColor secondaryLabelColor] ]
forKeys:@[ NSFontAttributeName, NSForegroundColorAttributeName ]];
[string addAttributes:attributes range:NSMakeRange(0, string.length)];
[string drawInRect:titleRect];
}
@end

View File

@ -13,6 +13,7 @@
#import "Torrent.h"
#import "TorrentCell.h"
#import "TorrentGroup.h"
#import "GroupTextCell.h"
CGFloat const kGroupSeparatorHeight = 18.0;
@ -38,6 +39,7 @@ static NSTimeInterval const kToggleProgressSeconds = 0.175;
@property(nonatomic) IBOutlet Controller* fController;
@property(nonatomic) TorrentCell* fTorrentCell;
@property(nonatomic) GroupTextCell* fGroupTextCell;
@property(nonatomic, readonly) NSUserDefaults* fDefaults;
@ -73,6 +75,7 @@ static NSTimeInterval const kToggleProgressSeconds = 0.175;
_fDefaults = NSUserDefaults.standardUserDefaults;
_fTorrentCell = [[TorrentCell alloc] init];
_fGroupTextCell = [[GroupTextCell alloc] init];
NSData* groupData;
if ((groupData = [_fDefaults dataForKey:@"CollapsedGroupIndexes"]))
@ -120,6 +123,9 @@ static NSTimeInterval const kToggleProgressSeconds = 0.175;
//set group columns to show ratio, needs to be in awakeFromNib to size columns correctly
[self setGroupStatusColumns];
//disable highlight color and set manually in drawRow
[self setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(setNeedsDisplay) name:@"RefreshTorrentTable" object:nil];
}
@ -155,7 +161,9 @@ static NSTimeInterval const kToggleProgressSeconds = 0.175;
- (BOOL)outlineView:(NSOutlineView*)outlineView isGroupItem:(id)item
{
return ![item isKindOfClass:[Torrent class]];
//return no and style the groupItem cell manually in willDisplayCell
//otherwise we get unwanted padding before each group header
return NO;
}
- (CGFloat)outlineView:(NSOutlineView*)outlineView heightOfRowByItem:(id)item
@ -172,7 +180,16 @@ static NSTimeInterval const kToggleProgressSeconds = 0.175;
}
else
{
return group ? [tableColumn dataCellForRow:[self rowForItem:item]] : nil;
NSString* ident = tableColumn.identifier;
NSArray* imageColumns = @[ @"Color", @"DL Image", @"UL Image" ];
if (![imageColumns containsObject:ident])
{
return group ? self.fGroupTextCell : nil;
}
else
{
return group ? [tableColumn dataCellForRow:[self rowForItem:item]] : nil;
}
}
}
@ -197,6 +214,38 @@ static NSTimeInterval const kToggleProgressSeconds = 0.175;
}
}
//we override row highlighting because we are custom drawing the group rows
//see isGroupItem
- (void)drawRow:(NSInteger)row clipRect:(NSRect)clipRect
{
NSColor* highlightColor = nil;
id item = [self itemAtRow:row];
//we only highlight torrent cells
if ([item isKindOfClass:[Torrent class]])
{
//use system highlight color when Transmission is active
if (self == [self.window firstResponder] && [self.window isMainWindow] && [self.window isKeyWindow])
{
highlightColor = [NSColor alternateSelectedControlColor];
}
else
{
highlightColor = [NSColor disabledControlTextColor];
}
NSIndexSet* selectedRowIndexes = [self selectedRowIndexes];
if ([selectedRowIndexes containsIndex:row])
{
[highlightColor setFill];
NSRectFill([self rectOfRow:row]);
}
}
[super drawRow:row clipRect:clipRect];
}
- (NSRect)frameOfCellAtColumn:(NSInteger)column row:(NSInteger)row
{
if (column == -1)