Skip to content

Commit a6b943e

Browse files
committed
Modernize PBSourceViewItem
This also renames its subclasses for consistency, and remove 2 unused ones.
1 parent d4192a4 commit a6b943e

39 files changed

+571
-393
lines changed

Classes/Controllers/PBGitSidebarController.m

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#import "PBGitDefaults.h"
1717
#import "PBHistorySearchController.h"
1818
#import "PBGitStash.h"
19-
#import "PBGitSVStashItem.h"
19+
#import "PBSourceViewGitStashItem.h"
2020
#import "PBSidebarTableViewCell.h"
2121
#import "PBGitRef.h"
2222

@@ -117,11 +117,11 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(
117117

118118
if ([@"stashesModified" isEqualToString:(__bridge NSString*)context]) {
119119

120-
for (PBGitSVStashItem *stashItem in stashes.sortedChildren)
120+
for (PBSourceViewGitStashItem *stashItem in stashes.sortedChildren)
121121
[stashes removeChild:stashItem];
122122

123123
for (PBGitStash *stash in repository.stashes)
124-
[stashes addChild: [PBGitSVStashItem itemWithStash:stash]];
124+
[stashes addChild: [PBSourceViewGitStashItem itemWithStash:stash]];
125125

126126
[sourceView expandItem:stashes];
127127
[sourceView reloadItem:stashes reloadChildren:YES];
@@ -255,12 +255,12 @@ - (void)doubleClicked:(id)object {
255255
NSInteger rowNumber = [sourceView selectedRow];
256256

257257
id item = [sourceView itemAtRow:rowNumber];
258-
if ([item isKindOfClass:[PBGitSVSubmoduleItem class]]) {
259-
PBGitSVSubmoduleItem *subModule = item;
258+
if ([item isKindOfClass:[PBSourceViewGitSubmoduleItem class]]) {
259+
PBSourceViewGitSubmoduleItem *subModule = item;
260260

261261
[self openSubmoduleAtURL:[subModule path]];
262-
} else if ([item isKindOfClass:[PBGitSVBranchItem class]]) {
263-
PBGitSVBranchItem *branch = item;
262+
} else if ([item isKindOfClass:[PBSourceViewGitBranchItem class]]) {
263+
PBSourceViewGitBranchItem *branch = item;
264264

265265
NSError *error = nil;
266266
BOOL success = [repository checkoutRefish:[branch ref] error:&error];
@@ -272,7 +272,7 @@ - (void)doubleClicked:(id)object {
272272

273273
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
274274
{
275-
if ([item isKindOfClass:[PBGitSVSubmoduleItem class]]) {
275+
if ([item isKindOfClass:[PBSourceViewGitSubmoduleItem class]]) {
276276
NSLog(@"hi");
277277
}
278278
return NO;
@@ -320,9 +320,9 @@ - (BOOL) outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:(
320320
- (void)populateList
321321
{
322322
PBSourceViewItem *project = [PBSourceViewItem groupItemWithTitle:[repository projectName]];
323-
project.isUncollapsible = YES;
323+
project.uncollapsible = YES;
324324

325-
stage = [PBGitSVStageItem stageItem];
325+
stage = [PBSourceViewStageItem stageItem];
326326
[project addChild:stage];
327327

328328
branches = [PBSourceViewItem groupItemWithTitle:@"Branches"];
@@ -333,14 +333,14 @@ - (void)populateList
333333
others = [PBSourceViewItem groupItemWithTitle:@"Other"];
334334

335335
for (PBGitStash *stash in repository.stashes)
336-
[stashes addChild: [PBGitSVStashItem itemWithStash:stash]];
336+
[stashes addChild: [PBSourceViewGitStashItem itemWithStash:stash]];
337337

338338
for (PBGitRevSpecifier *rev in repository.branches) {
339339
[self addRevSpec:rev];
340340
}
341341

342342
for (GTSubmodule *sub in repository.submodules) {
343-
[submodules addChild: [PBGitSVSubmoduleItem itemWithSubmodule:sub]];
343+
[submodules addChild: [PBSourceViewGitSubmoduleItem itemWithSubmodule:sub]];
344344
}
345345

346346
[items addObject:project];
@@ -365,7 +365,7 @@ - (void)expandCollapseItem:(NSNotification*)aNotification
365365
{
366366
NSObject* child = [[aNotification userInfo] valueForKey:@"NSObject"];
367367
if ([child isKindOfClass:[PBSourceViewItem class]]) {
368-
((PBSourceViewItem*)child).isExpanded = [aNotification.name isEqualToString:NSOutlineViewItemWillExpandNotification];
368+
((PBSourceViewItem *)child).expanded = [aNotification.name isEqualToString:NSOutlineViewItemWillExpandNotification];
369369
}
370370
}
371371

@@ -402,7 +402,7 @@ - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTabl
402402

403403
- (void) updateActionMenu
404404
{
405-
[actionButton setEnabled:([[self selectedItem] ref] != nil || [[self selectedItem] isKindOfClass:[PBGitSVSubmoduleItem class]])];
405+
[actionButton setEnabled:([[self selectedItem] ref] != nil || [[self selectedItem] isKindOfClass:[PBSourceViewGitSubmoduleItem class]])];
406406
}
407407

408408
- (void) addMenuItemsForRef:(PBGitRef *)ref toMenu:(NSMenu *)menu
@@ -414,7 +414,7 @@ - (void) addMenuItemsForRef:(PBGitRef *)ref toMenu:(NSMenu *)menu
414414
[menu addItem:menuItem];
415415
}
416416

417-
- (void) addMenuItemsForSubmodule:(PBGitSVSubmoduleItem *)submodule toMenu:(NSMenu *)menu
417+
- (void) addMenuItemsForSubmodule:(PBSourceViewGitSubmoduleItem *)submodule toMenu:(NSMenu *)menu
418418
{
419419
if (!submodule)
420420
return;
@@ -447,8 +447,8 @@ - (NSMenu *) menuForRow:(NSInteger)row
447447
[self addMenuItemsForRef:ref toMenu:menu];
448448
}
449449

450-
if ([viewItem isKindOfClass:[PBGitSVSubmoduleItem class]]) {
451-
[self addMenuItemsForSubmodule:(PBGitSVSubmoduleItem *)viewItem toMenu:menu];
450+
if ([viewItem isKindOfClass:[PBSourceViewGitSubmoduleItem class]]) {
451+
[self addMenuItemsForSubmodule:(PBSourceViewGitSubmoduleItem *)viewItem toMenu:menu];
452452
}
453453

454454
return menu;
@@ -463,8 +463,8 @@ - (void) menuNeedsUpdate:(NSMenu *)menu
463463
PBGitRef *ref = [[self selectedItem] ref];
464464
[self addMenuItemsForRef:ref toMenu:menu];
465465

466-
if ([[self selectedItem] isKindOfClass:[PBGitSVSubmoduleItem class]]) {
467-
[self addMenuItemsForSubmodule:(PBGitSVSubmoduleItem *)[self selectedItem] toMenu:menu];
466+
if ([[self selectedItem] isKindOfClass:[PBSourceViewGitSubmoduleItem class]]) {
467+
[self addMenuItemsForSubmodule:(PBSourceViewGitSubmoduleItem *)[self selectedItem] toMenu:menu];
468468
}
469469
}
470470

Classes/Views/PBSourceViewAction.h

Lines changed: 0 additions & 17 deletions
This file was deleted.

Classes/Views/PBSourceViewAction.m

Lines changed: 0 additions & 15 deletions
This file was deleted.

Classes/Views/PBSourceViewItem.h

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,39 @@
1111
@class PBGitRevSpecifier;
1212
@class PBGitRef;
1313

14-
@interface PBSourceViewItem : NSObject {
15-
NSMutableOrderedSet *childrenSet;
14+
NS_ASSUME_NONNULL_BEGIN
1615

17-
NSString *title;
18-
PBGitRevSpecifier *revSpecifier;
16+
@interface PBSourceViewItem : NSObject
1917

20-
BOOL isGroupItem;
21-
BOOL isUncollapsible;
22-
}
18+
+ (instancetype)groupItemWithTitle:(NSString *)title;
19+
+ (instancetype)itemWithRevSpec:(PBGitRevSpecifier *)revSpecifier;
20+
+ (instancetype)itemWithTitle:(NSString *)title;
2321

24-
+ (id)groupItemWithTitle:(NSString *)title;
25-
+ (id)itemWithRevSpec:(PBGitRevSpecifier *)revSpecifier;
26-
+ (id)itemWithTitle:(NSString *)title;
22+
- (instancetype)initWithTitle:(NSString *)title revSpecifier:(nullable PBGitRevSpecifier *)spec NS_DESIGNATED_INITIALIZER;
23+
24+
- (instancetype)init NS_UNAVAILABLE;
2725

2826
- (void)addChild:(PBSourceViewItem *)child;
2927
- (void)removeChild:(PBSourceViewItem *)child;
30-
- (NSImage*)iconNamed:(NSString*)name;
3128

3229
// This adds the ref to the path, which should match the item's title,
3330
// so "refs/heads/pu/pb/sidebar" would have the path [@"pu", @"pb", @"sidebare"]
3431
// to the 'local' branch thing
3532
- (void)addRev:(PBGitRevSpecifier *)revSpecifier toPath:(NSArray *)path;
36-
- (PBSourceViewItem *)findRev:(PBGitRevSpecifier *)rev;
33+
- (nullable PBSourceViewItem *)findRev:(PBGitRevSpecifier *)rev;
3734

38-
- (PBGitRef *) ref;
35+
- (nullable PBGitRef *)ref;
3936

40-
@property NSString *title;
41-
@property(nonatomic, readonly) NSArray *sortedChildren;
42-
@property(assign) BOOL isGroupItem, isUncollapsible, isExpanded;
37+
@property (readonly) NSString *title;
38+
@property (readonly) NSArray *sortedChildren;
39+
@property (getter=isGroupItem) BOOL groupItem;
40+
@property (getter=isUncollapsible) BOOL uncollapsible;
41+
@property (getter=isExpanded) BOOL expanded;
4342
@property PBGitRevSpecifier *revSpecifier;
44-
@property (assign)PBSourceViewItem *parent;
45-
@property(readonly) NSString *iconName;
46-
@property(readonly) NSImage *icon;
43+
@property PBSourceViewItem *parent;
44+
@property (readonly) NSString *iconName;
45+
@property (nullable, readonly) NSImage *icon;
4746

4847
@end
48+
49+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)