Skip to content

Commit

Permalink
macOS migrate mainwindow to autolayout
Browse files Browse the repository at this point in the history
* updated MainMenu.xib to use autolayout
* reverted a number of changes from transmission#3278 transmission#3261
* removed unused *GearshapeTemplate* from macoxs/CMakeLists.txt
  • Loading branch information
sweetppro committed Jun 14, 2022
1 parent 438653a commit cfb716a
Show file tree
Hide file tree
Showing 21 changed files with 1,950 additions and 1,689 deletions.
2 changes: 0 additions & 2 deletions macosx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ set(${PROJECT_NAME}_SOURCES
InfoTrackersViewController.mm
InfoWindowController.mm
main.mm
MainWindow.mm
MessageWindowController.mm
NSApplicationAdditions.mm
NSImageAdditions.mm
Expand Down Expand Up @@ -248,7 +247,6 @@ set(${PROJECT_NAME}_HIDPI_IMAGES
DownArrowTemplate
EllipsisTemplate
FavIcon
GearshapeTemplate
Globe
Groups
InfoActivity
Expand Down
5 changes: 3 additions & 2 deletions macosx/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#import "VDKQueue.h"
#import "TorrentTableView.h"
#import "MainWindow.h"

@class AddMagnetWindowController;
@class AddWindowController;
Expand Down Expand Up @@ -185,7 +184,9 @@ typedef NS_ENUM(unsigned int, addType) { //
- (void)rpcMovedTorrent:(Torrent*)torrent;
- (void)rpcUpdateQueue;

@property(nonatomic) IBOutlet MainWindow* fWindow;
@property(nonatomic) IBOutlet NSWindow* fWindow;
@property(nonatomic) IBOutlet NSStackView* fStackView;
@property(nonatomic) NSArray* fStackViewHeightConstraints;
@property(nonatomic) IBOutlet TorrentTableView* fTableView;

@property(nonatomic) IBOutlet NSMenuItem* fOpenIgnoreDownloadFolder;
Expand Down
71 changes: 24 additions & 47 deletions macosx/Controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#import "NSStringAdditions.h"
#import "ExpandedPathToPathTransformer.h"
#import "ExpandedPathToIconTransformer.h"
#import "MainWindow.h"

#define TOOLBAR_CREATE @"Toolbar Create"
#define TOOLBAR_OPEN_FILE @"Toolbar Open"
Expand Down Expand Up @@ -548,6 +547,10 @@ - (void)awakeFromNib
[self.fSortMenu insertItem:item atIndex:sortMenuIndex++];
}

//you would think this would be called later in this method from updateUI, but it's not reached in awakeFromNib
//this must be called after showStatusBar:
[self.fStatusBar updateWithDownload:0.0 upload:0.0];

//register for sleep notifications
IONotificationPortRef notify;
io_object_t iterator;
Expand Down Expand Up @@ -659,7 +662,7 @@ - (void)awakeFromNib
#warning rename
[nc addObserver:self selector:@selector(fullUpdateUI) name:@"UpdateQueue" object:nil];

[nc addObserver:self selector:@selector(drawMainWindow) name:@"ApplyFilter" object:nil];
[nc addObserver:self selector:@selector(applyFilter) name:@"ApplyFilter" object:nil];

//open newly created torrent file
[nc addObserver:self selector:@selector(beginCreateFile:) name:@"BeginCreateTorrentFile" object:nil];
Expand All @@ -669,7 +672,7 @@ - (void)awakeFromNib

[nc addObserver:self selector:@selector(applyFilter) name:@"UpdateGroups" object:nil];

[self drawMainWindow];
[self updateMainWindow];

//timer to update the interface every second
[self updateUI];
Expand All @@ -685,6 +688,9 @@ - (void)awakeFromNib
{
[self showInfo:nil];
}

//redraw filterbar to avoid clipping
[NSNotificationCenter.defaultCenter postNotificationName:@"ResizeBar" object:nil];
}

- (void)applicationDidFinishLaunching:(NSNotification*)notification
Expand Down Expand Up @@ -1115,7 +1121,7 @@ - (void)openFiles:(NSArray*)filenames addType:(addType)type forcePath:(NSString*
}
}

[self drawMainWindow];
[self fullUpdateUI];
}

- (void)askOpenConfirmed:(AddWindowController*)addController add:(BOOL)add
Expand All @@ -1135,7 +1141,7 @@ - (void)askOpenConfirmed:(AddWindowController*)addController add:(BOOL)add
}
[self.fAddingTransfers addObject:torrent];

[self drawMainWindow];
[self fullUpdateUI];
}
else
{
Expand Down Expand Up @@ -1209,7 +1215,7 @@ - (void)openMagnet:(NSString*)address
[self.fAddingTransfers addObject:torrent];
}

[self drawMainWindow];
[self fullUpdateUI];
}

- (void)askOpenMagnetConfirmed:(AddMagnetWindowController*)addController add:(BOOL)add
Expand All @@ -1229,7 +1235,7 @@ - (void)askOpenMagnetConfirmed:(AddMagnetWindowController*)addController add:(BO
}
[self.fAddingTransfers addObject:torrent];

[self drawMainWindow];
[self fullUpdateUI];
}
else
{
Expand Down Expand Up @@ -1727,7 +1733,7 @@ - (void)confirmRemoveTorrents:(NSArray<Torrent*>*)torrents deleteData:(BOOL)dele
[torrent closeRemoveTorrent:deleteData];
}

[self drawMainWindow];
[self fullUpdateUI];
};

[self.fTableView beginUpdates];
Expand Down Expand Up @@ -1769,8 +1775,6 @@ - (void)confirmRemoveTorrents:(NSArray<Torrent*>*)torrents deleteData:(BOOL)dele
{
[torrent closeRemoveTorrent:deleteData];
}

[self drawMainWindow];
}
}

Expand Down Expand Up @@ -3065,10 +3069,11 @@ - (void)applyFilter
{
[self.fTableView endUpdates];
}
self.fTableView.needsDisplay = YES;

[NSAnimationContext endGrouping];

//reloaddata, otherwise the tableview has a bunch of empty cells
[self.fTableView reloadData];

[self resetInfo]; //if group is already selected, but the torrents in it change

[self setBottomCountText:groupRows || filterStatus || filterGroup || searchStrings];
Expand Down Expand Up @@ -3728,32 +3733,9 @@ - (void)toggleSmallView:(id)sender
noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.fTableView.numberOfRows)]];
[self.fTableView endUpdates];

//resize for larger min height if not set to auto size
if (![self.fDefaults boolForKey:@"AutoSize"] || self.isFullScreen)
{
NSSize const contentSize = self.fWindow.contentView.frame.size;

NSSize contentMinSize = self.fWindow.contentMinSize;
contentMinSize.height = self.minWindowContentSizeAllowed;
self.fWindow.contentMinSize = contentMinSize;

//make sure the window already isn't too small
if (!makeSmall && contentSize.height < contentMinSize.height)
{
NSRect frame = self.fWindow.frame;
CGFloat heightChange = contentMinSize.height - contentSize.height;
frame.size.height += heightChange;
frame.origin.y -= heightChange;

[self.fWindow setFrame:frame display:YES];
}
}
else
{
[self setWindowSizeToFit];
}

[self drawMainWindow];
//reloaddata, otherwise the tableview has a bunch of empty cells
[self.fTableView reloadData];
[self updateForAutoSize];
}

- (void)togglePiecesBar:(id)sender
Expand All @@ -3772,26 +3754,21 @@ - (void)toggleStatusBar:(id)sender
{
BOOL const show = self.fStatusBar == nil;
[self.fDefaults setBool:show forKey:@"StatusBar"];
[self drawMainWindow];
[self updateMainWindow];
}

- (void)toggleFilterBar:(id)sender
{
BOOL const show = self.fFilterBar == nil;

//disable filtering when hiding (have to do before drawMainWindow:)
//disable filtering when hiding (have to do before updateMainWindow:)
if (!show)
{
[self.fFilterBar reset:NO];
}

[self.fDefaults setBool:show forKey:@"FilterBar"];
[self drawMainWindow];

if (show)
{
[self focusFilterField];
}
[self updateMainWindow];
}

- (void)focusFilterField
Expand Down Expand Up @@ -5008,7 +4985,7 @@ - (void)rpcAddTorrentStruct:(struct tr_torrent*)torrentStruct
}
[self.fAddingTransfers addObject:torrent];

[self drawMainWindow];
[self fullUpdateUI];
}

- (void)rpcRemoveTorrent:(Torrent*)torrent deleteData:(BOOL)deleteData
Expand Down
12 changes: 7 additions & 5 deletions macosx/ControllerWindowMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@

@interface Controller (ControllerWindowMethods)

- (void)drawMainWindow;
- (void)updateMainWindow;

- (void)setWindowSizeToFit;
- (void)updateForAutoSize;
- (void)setWindowMinMaxToCurrent;
- (void)removeWindowMinMax;
- (void)setMinWindowContentSizeAllowed;
- (void)setMaxWindowContentSizeAllowed;
- (void)removeStackViewHeightConstraints;

@property(nonatomic, readonly) NSRect sizedWindowFrame;
@property(nonatomic, readonly) CGFloat titlebarHeight;
@property(nonatomic, readonly) CGFloat minWindowContentHeightAllowed;
@property(nonatomic, readonly) CGFloat toolbarHeight;
@property(nonatomic, readonly) CGFloat mainWindowComponentHeight;
@property(nonatomic, readonly) CGFloat scrollViewHeight;
@property(nonatomic, readonly) CGFloat fullScreenScrollViewHeight;
@property(nonatomic, readonly) CGFloat minWindowContentSizeAllowed;
@property(nonatomic, readonly) BOOL isFullScreen;

@end

0 comments on commit cfb716a

Please sign in to comment.