diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..235a5bf --- /dev/null +++ b/Package.swift @@ -0,0 +1,35 @@ +// swift-tools-version: 5.6 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "MGScopeBar", + defaultLocalization: "en", + platforms: [ + .macOS(.v11) + ], + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "MGScopeBar", + targets: ["MGScopeBar"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "MGScopeBar", + dependencies: [], + resources: [ + .process("Resources") + ]), + .testTarget( + name: "MGScopeBarTests", + dependencies: ["MGScopeBar"]), + ] +) diff --git a/ReadMe.txt b/README.md similarity index 100% rename from ReadMe.txt rename to README.md diff --git a/MGRecessedPopUpButtonCell.h b/Sources/MGScopeBar/MGRecessedPopUpButtonCell.h similarity index 100% rename from MGRecessedPopUpButtonCell.h rename to Sources/MGScopeBar/MGRecessedPopUpButtonCell.h diff --git a/MGRecessedPopUpButtonCell.m b/Sources/MGScopeBar/MGRecessedPopUpButtonCell.m similarity index 94% rename from MGRecessedPopUpButtonCell.m rename to Sources/MGScopeBar/MGRecessedPopUpButtonCell.m index d41bb92..99b3373 100644 --- a/MGRecessedPopUpButtonCell.m +++ b/Sources/MGScopeBar/MGRecessedPopUpButtonCell.m @@ -26,14 +26,6 @@ - (id)initTextCell:(NSString *)title pullsDown:(BOOL)pullsDown return self; } - -- (void)dealloc -{ - [recessedButton release]; - [super dealloc]; -} - - - (void)drawTitleWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { // Inset title rect since its position is broken when NSPopUpButton diff --git a/MGScopeBar.h b/Sources/MGScopeBar/MGScopeBar.h similarity index 97% rename from MGScopeBar.h rename to Sources/MGScopeBar/MGScopeBar.h index 9505748..60c3cc3 100644 --- a/MGScopeBar.h +++ b/Sources/MGScopeBar/MGScopeBar.h @@ -10,7 +10,7 @@ #import "MGScopeBarDelegateProtocol.h" @interface MGScopeBar : NSView { - IBOutlet id delegate; // weak ref. + IBOutlet __unsafe_unretained id delegate; // weak ref. NSMutableArray *_separatorPositions; // x-coords of separators, indexed by their group-number. NSMutableArray *_groups; // groups of items. NSView *_accessoryView; // weak ref since it's a subview. diff --git a/MGScopeBar.m b/Sources/MGScopeBar/MGScopeBar.m similarity index 97% rename from MGScopeBar.m rename to Sources/MGScopeBar/MGScopeBar.m index 60272de..0c39162 100644 --- a/MGScopeBar.m +++ b/Sources/MGScopeBar/MGScopeBar.m @@ -99,12 +99,6 @@ - (void)dealloc [_accessoryView removeFromSuperview]; _accessoryView = nil; // weak ref } - [_separatorPositions release]; - [_groups release]; - [_identifiers release]; - [_selectedItems release]; - - [super dealloc]; } @@ -124,15 +118,10 @@ - (void)reloadData NSArray *subviews = [[self subviews] copy]; // so we don't mutate the collection we're iterating over. [subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; - [subviews release]; // because copies are retained. - [_separatorPositions release]; _separatorPositions = nil; - [_groups release]; _groups = nil; - [_identifiers release]; _identifiers = nil; - [_selectedItems release]; _selectedItems = nil; _firstCollapsedGroup = NSNotFound; _lastWidth = NSNotFound; @@ -187,7 +176,6 @@ - (void)reloadData ctrlRect.size = [labelField frame].size; [labelField setFrame:ctrlRect]; [self addSubview:labelField]; - [labelField release]; xCoord += ctrlRect.size.width + SCOPE_BAR_ITEM_SPACING; @@ -712,7 +700,7 @@ - (NSButton *)buttonForItem:(NSString *)identifier inGroup:(NSInteger)groupNumbe [self setControl:button forIdentifier:identifier inGroup:groupNumber]; - return [button autorelease]; + return button; } @@ -727,7 +715,7 @@ - (NSMenuItem *)menuItemForItem:(NSString *)identifier inGroup:(NSInteger)groupN [self setControl:menuItem forIdentifier:identifier inGroup:groupNumber]; - return [menuItem autorelease]; + return menuItem; } @@ -742,12 +730,10 @@ - (NSPopUpButton *)popupButtonForGroup:(NSDictionary *)group if (multiSelect) { MGRecessedPopUpButtonCell *cell = [[MGRecessedPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO]; [popup setCell:cell]; - [cell release]; [[popup cell] setUsesItemFromMenu:NO]; NSMenuItem *titleItem = [[NSMenuItem alloc] init]; [[popup cell] setMenuItem:titleItem]; - [titleItem release]; } // Configure appearance and behaviour. @@ -782,7 +768,7 @@ - (NSPopUpButton *)popupButtonForGroup:(NSDictionary *)group popFrame.origin.y = ceil(([self frame].size.height - popFrame.size.height) / 2.0); [popup setFrame:popFrame]; - return [popup autorelease]; + return popup; } @@ -794,7 +780,7 @@ - (void)setControl:(NSObject *)control forIdentifier:(NSString *)identifier inGr NSMutableArray *identArray = [_identifiers objectForKey:identifier]; if (!identArray) { - identArray = [[[NSMutableArray alloc] initWithCapacity:groupNumber + 1] autorelease]; + identArray = [[NSMutableArray alloc] initWithCapacity:groupNumber + 1]; [_identifiers setObject:identArray forKey:identifier]; } @@ -872,8 +858,8 @@ - (void)updateMenuTitleForGroupAtIndex:(NSInteger)groupNumber - (void)drawRect:(NSRect)rect { // Draw gradient background. - NSGradient *gradient = [[[NSGradient alloc] initWithStartingColor:SCOPE_BAR_START_COLOR_GRAY - endingColor:SCOPE_BAR_END_COLOR_GRAY] autorelease]; + NSGradient *gradient = [[NSGradient alloc] initWithStartingColor:SCOPE_BAR_START_COLOR_GRAY + endingColor:SCOPE_BAR_END_COLOR_GRAY]; [gradient drawInRect:[self bounds] angle:90.0]; // Draw border. @@ -932,7 +918,6 @@ - (void)setSelected:(BOOL)selected forItem:(NSString *)identifier inGroup:(NSInt BOOL informDelegate = YES; if (group) { - [group retain]; NSDisableScreenUpdates(); // We found the group which this item belongs to. Obtain selection-mode and identifiers. @@ -956,7 +941,6 @@ - (void)setSelected:(BOOL)selected forItem:(NSString *)identifier inGroup:(NSInt informDelegate = NO; } } - [groupSelections release]; } // Change selected state of this item. @@ -967,7 +951,6 @@ - (void)setSelected:(BOOL)selected forItem:(NSString *)identifier inGroup:(NSInt [self updateMenuTitleForGroupAtIndex:groupNumber]; } - [group release]; NSEnableScreenUpdates(); } } @@ -1012,7 +995,7 @@ - (void)updateSelectedState:(BOOL)selected forItem:(NSString *)identifier inGrou - (NSArray *)selectedItems { - return [[_selectedItems copy] autorelease]; + return [_selectedItems copy]; } - (BOOL) isItemSelectedWithIdentifier:(NSString*)identifier inGroup:(NSInteger)groupNumber; { diff --git a/Base.lproj/MainMenu.xib b/Sources/MGScopeBar/Resources/Base.lproj/MainMenu.xib similarity index 100% rename from Base.lproj/MainMenu.xib rename to Sources/MGScopeBar/Resources/Base.lproj/MainMenu.xib diff --git a/en.lproj/InfoPlist.strings b/Sources/MGScopeBar/Resources/en.lproj/InfoPlist.strings similarity index 100% rename from en.lproj/InfoPlist.strings rename to Sources/MGScopeBar/Resources/en.lproj/InfoPlist.strings diff --git a/Sources/MGScopeBar/include/MGScopeBar.h b/Sources/MGScopeBar/include/MGScopeBar.h new file mode 100644 index 0000000..c958767 --- /dev/null +++ b/Sources/MGScopeBar/include/MGScopeBar.h @@ -0,0 +1,14 @@ +// +// Header.h +// +// +// Created by Christian Beer on 29.08.22. +// + +#ifndef Header_h +#define Header_h + +#include "../MGScopeBar.h" +#include "../MGRecessedPopUpButtonCell.h" + +#endif /* Header_h */ diff --git a/MGScopeBarDelegateProtocol.h b/Sources/MGScopeBar/include/MGScopeBarDelegateProtocol.h similarity index 100% rename from MGScopeBarDelegateProtocol.h rename to Sources/MGScopeBar/include/MGScopeBarDelegateProtocol.h diff --git a/Tests/MGScopeBarTests/MGScopeBarTests.swift b/Tests/MGScopeBarTests/MGScopeBarTests.swift new file mode 100644 index 0000000..11347b4 --- /dev/null +++ b/Tests/MGScopeBarTests/MGScopeBarTests.swift @@ -0,0 +1,10 @@ +import XCTest +@testable import MGScopeBar + +final class MGScopeBarTests: XCTestCase { + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct + // results. + } +}