Skip to content

Commit

Permalink
Swift Package Support, switch to ARC
Browse files Browse the repository at this point in the history
  • Loading branch information
chbeer authored and hannesa2 committed Dec 20, 2023
1 parent dea7214 commit d8a83c2
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 33 deletions.
35 changes: 35 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -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"]),
]
)
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion MGScopeBar.h → Sources/MGScopeBar/MGScopeBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "MGScopeBarDelegateProtocol.h"

@interface MGScopeBar : NSView {
IBOutlet id <MGScopeBarDelegate, NSObject> delegate; // weak ref.
IBOutlet __unsafe_unretained id <MGScopeBarDelegate, NSObject> 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.
Expand Down
31 changes: 7 additions & 24 deletions MGScopeBar.m → Sources/MGScopeBar/MGScopeBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ - (void)dealloc
[_accessoryView removeFromSuperview];
_accessoryView = nil; // weak ref
}
[_separatorPositions release];
[_groups release];
[_identifiers release];
[_selectedItems release];

[super dealloc];
}


Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -712,7 +700,7 @@ - (NSButton *)buttonForItem:(NSString *)identifier inGroup:(NSInteger)groupNumbe

[self setControl:button forIdentifier:identifier inGroup:groupNumber];

return [button autorelease];
return button;
}


Expand All @@ -727,7 +715,7 @@ - (NSMenuItem *)menuItemForItem:(NSString *)identifier inGroup:(NSInteger)groupN

[self setControl:menuItem forIdentifier:identifier inGroup:groupNumber];

return [menuItem autorelease];
return menuItem;
}


Expand All @@ -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.
Expand Down Expand Up @@ -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;
}


Expand All @@ -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];
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -956,7 +941,6 @@ - (void)setSelected:(BOOL)selected forItem:(NSString *)identifier inGroup:(NSInt
informDelegate = NO;
}
}
[groupSelections release];
}

// Change selected state of this item.
Expand All @@ -967,7 +951,6 @@ - (void)setSelected:(BOOL)selected forItem:(NSString *)identifier inGroup:(NSInt
[self updateMenuTitleForGroupAtIndex:groupNumber];
}

[group release];
NSEnableScreenUpdates();
}
}
Expand Down Expand Up @@ -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;
{
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions Sources/MGScopeBar/include/MGScopeBar.h
Original file line number Diff line number Diff line change
@@ -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 */
File renamed without changes.
10 changes: 10 additions & 0 deletions Tests/MGScopeBarTests/MGScopeBarTests.swift
Original file line number Diff line number Diff line change
@@ -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.
}
}

0 comments on commit d8a83c2

Please sign in to comment.