Skip to content

Commit 0378e8e

Browse files
authored
Merge pull request #103 from mangerlahn/feature/fluent-ui
Modern table views
2 parents fe6f3e2 + 67def17 commit 0378e8e

33 files changed

Lines changed: 1041 additions & 661 deletions

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ DerivedData/
55
.DS_Store
66
__pycache__/
77
*.pyc
8+
/GitX.xcworkspace/xcuserdata

‎Classes/Controllers/PBGitHistoryController.m‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
#import "GLFileView.h"
2525
#import "GitXCommitCopier.h"
2626
#import "NSSplitView+GitX.h"
27+
#import "PBGitRevisionRow.h"
28+
#import "PBRefMenuItem.h"
29+
#import "PBGitStash.h"
2730

2831
#define kHistorySelectedDetailIndexKey @"PBHistorySelectedDetailIndex"
2932
#define kHistoryDetailViewIndex 0
3033
#define kHistoryTreeViewIndex 1
3134

32-
@interface PBGitHistoryController () {
35+
@interface PBGitHistoryController () <NSTableViewDelegate> {
3336
IBOutlet NSArrayController *commitController;
3437
IBOutlet NSTreeController *treeController;
3538
IBOutlet PBWebHistoryController *webHistoryController;
@@ -72,6 +75,15 @@ @implementation PBGitHistoryController
7275

7376
- (void)awakeFromNib
7477
{
78+
/* FIXME: Be careful with this method: since PBGitRevisionRow & PBGitRevisionCell
79+
* have this controller in their outlets, this method is called *really* often
80+
* (vs. the expected *once*)
81+
*/
82+
}
83+
84+
- (void)loadView {
85+
[super loadView];
86+
7587
[historySplitView pb_restoreAutosavedPositions];
7688

7789
self.selectedCommitDetailsIndex = [[NSUserDefaults standardUserDefaults] integerForKey:kHistorySelectedDetailIndexKey];
@@ -112,7 +124,7 @@ - (void)awakeFromNib
112124
[[commitList headerView] setMenu:[self tableColumnMenu]];
113125

114126
[upperToolbarView setTopShade:237/255.0f bottomShade:216/255.0f];
115-
[scopeBarView setTopColor:[NSColor colorWithCalibratedHue:0.579 saturation:0.068 brightness:0.898 alpha:1.000]
127+
[scopeBarView setTopColor:[NSColor colorWithCalibratedHue:0.579 saturation:0.068 brightness:0.898 alpha:1.000]
116128
bottomColor:[NSColor colorWithCalibratedHue:0.579 saturation:0.119 brightness:0.765 alpha:1.000]];
117129
[self updateBranchFilterMatrix];
118130

@@ -135,6 +147,20 @@ - (void) _repositoryUpdatedNotification:(NSNotification *)notification {
135147
}
136148
}
137149

150+
- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row {
151+
NSTableRowView *view = [tableView rowViewAtRow:row makeIfNecessary:NO];
152+
153+
if (view) {
154+
return view;
155+
}
156+
157+
PBGitRevisionRow *rowView = [PBGitRevisionRow new];
158+
159+
rowView.controller = self;
160+
161+
return rowView;
162+
}
163+
138164
- (void) updateKeys
139165
{
140166
NSArray<PBGitCommit *> *newSelectedCommits = commitController.selectedObjects;
@@ -300,8 +326,11 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(
300326

301327
if([strContext isEqualToString:@"branchChange"]) {
302328
// Reset the sorting
303-
if ([[commitController sortDescriptors] count])
329+
if ([[commitController sortDescriptors] count]) {
304330
[commitController setSortDescriptors:[NSArray array]];
331+
[commitController rearrangeObjects];
332+
}
333+
305334
[self updateBranchFilterMatrix];
306335
return;
307336
}

‎Classes/Controllers/PBGitSidebarController.m‎

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@
1111
#import "PBGitHistoryController.h"
1212
#import "PBGitCommitController.h"
1313
#import "PBRefController.h"
14-
#import "PBSourceViewCell.h"
1514
#import "NSOutlineViewExt.h"
1615
#import "PBAddRemoteSheet.h"
1716
#import "PBGitDefaults.h"
1817
#import "PBHistorySearchController.h"
1918
#import "PBGitStash.h"
2019
#import "PBGitSVStashItem.h"
20+
#import "PBSidebarTableViewCell.h"
2121
#import "PBGitRef.h"
2222

23+
#define PBSidebarCellIdentifier @"PBSidebarCellIdentifier"
24+
2325
@interface PBGitSidebarController ()
2426

2527
- (void)populateList;
@@ -88,7 +90,9 @@ - (void)closeView
8890
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
8991
{
9092
if ([@"currentBranchChange" isEqualToString:(__bridge NSString*)context]) {
93+
NSInteger row = sourceView.selectedRow;
9194
[sourceView reloadData];
95+
[sourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
9296
[self selectCurrentBranch];
9397
return;
9498
}
@@ -151,15 +155,16 @@ - (void) selectCurrentBranch
151155
return;
152156
}
153157

154-
PBSourceViewItem *item = [self addRevSpec:rev];
155-
if (item) {
156-
[sourceView reloadData];
157-
158-
[sourceView PBExpandItem:item expandParents:YES];
159-
NSIndexSet *index = [NSIndexSet indexSetWithIndex:[sourceView rowForItem:item]];
160-
161-
[sourceView selectRowIndexes:index byExtendingSelection:NO];
162-
}
158+
dispatch_async(dispatch_get_main_queue(), ^{
159+
PBSourceViewItem *item = [self addRevSpec:rev];
160+
if (item) {
161+
[sourceView PBExpandItem:item expandParents:YES];
162+
NSIndexSet *index = [NSIndexSet indexSetWithIndex:[sourceView rowForItem:item]];
163+
164+
[sourceView deselectAll:nil];
165+
[sourceView selectRowIndexes:index byExtendingSelection:NO];
166+
}
167+
});
163168
}
164169

165170
- (PBSourceViewItem *) itemForRev:(PBGitRevSpecifier *)rev
@@ -229,8 +234,10 @@ - (void)outlineViewSelectionDidChange:(NSNotification *)notification
229234
PBSourceViewItem *item = [sourceView itemAtRow:index];
230235

231236
if ([item revSpecifier]) {
232-
if (![repository.currentBranch isEqual:[item revSpecifier]])
237+
if (![repository.currentBranch isEqual:[item revSpecifier]]) {
233238
repository.currentBranch = [item revSpecifier];
239+
}
240+
234241
[superController changeContentController:superController.historyViewController];
235242
[PBGitDefaults setShowStageView:NO];
236243
}
@@ -276,10 +283,24 @@ - (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
276283
return [item isGroupItem];
277284
}
278285

279-
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(PBSourceViewCell *)cell forTableColumn:(NSTableColumn *)tableColumn item:(PBSourceViewItem *)item
280-
{
286+
- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(PBSourceViewItem*)item {
287+
PBSidebarTableViewCell *cell = [outlineView makeViewWithIdentifier:PBSidebarCellIdentifier owner:outlineView];
288+
289+
cell.textField.stringValue = [[item title] copy];
290+
cell.imageView.image = item.icon;
281291
cell.isCheckedOut = [item.revSpecifier isEqual:[repository headRef]];
282-
[cell setImage:[item icon]];
292+
293+
return cell;
294+
}
295+
296+
- (NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item {
297+
NSTableRowView *view = [sourceView rowViewAtRow:[sourceView rowForItem:item] makeIfNecessary:NO];
298+
299+
if (view) {
300+
return view;
301+
}
302+
303+
return [NSTableRowView new];
283304
}
284305

285306
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item

‎Classes/Controllers/PBHistorySearchController.m‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ - (void)updateUI
214214
[numberOfMatchesField setStringValue:[self numberOfMatchesString]];
215215
[numberOfMatchesField setHidden:NO];
216216
[stepper setHidden:NO];
217+
218+
// Preserve selection
219+
NSIndexSet *selectedRowIndexes = historyController.commitList.selectedRowIndexes;
217220
[historyController.commitList reloadData];
221+
[historyController.commitList selectRowIndexes:selectedRowIndexes byExtendingSelection:NO];
218222
}
219223
[self clearProgressIndicator];
220224
}

‎Classes/Controllers/PBRefController.m‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ - (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexe
5858
NSInteger row = [tv rowAtPoint:location];
5959
NSInteger column = [tv columnAtPoint:location];
6060

61-
PBGitRevisionCell *cell = (PBGitRevisionCell *)[tv preparedCellAtColumn:column row:row];
61+
PBGitRevisionCell *cell = (PBGitRevisionCell *)[tv viewAtColumn:column row:row makeIfNecessary:NO];
6262
PBGitCommit *commit = [[commitController arrangedObjects] objectAtIndex:row];
6363

6464
int index = -1;

‎Classes/Controllers/PBWebController.m‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ - (void) awakeFromNib
3535
name:NSUserDefaultsDidChangeNotification
3636
object:nil];
3737

38+
[nc addObserver:self
39+
selector:@selector(windowWillStartLiveResitzeWithNotification:)
40+
name:NSWindowWillStartLiveResizeNotification
41+
object:self.view.window];
42+
43+
[nc addObserver:self
44+
selector:@selector(windowDidEndLiveResitzeWithNotification:)
45+
name:NSWindowDidEndLiveResizeNotification
46+
object:self.view.window];
47+
3848
finishedLoading = NO;
3949
[self.view setUIDelegate:self];
4050
[self.view setFrameLoadDelegate:self];
@@ -196,14 +206,28 @@ - (void) preferencesChanged
196206
{
197207
}
198208

209+
- (void)makeWebViewFirstResponder
210+
{
211+
[self.view.window makeFirstResponder:self.view];
212+
}
213+
214+
215+
#pragma mark - Notifications
216+
199217
- (void)preferencesChangedWithNotification:(NSNotification *)theNotification
200218
{
201219
[self preferencesChanged];
202220
}
203221

204-
- (void)makeWebViewFirstResponder
222+
- (void)windowWillStartLiveResitzeWithNotification:(NSNotification *)theNotification
205223
{
206-
[self.view.window makeFirstResponder:self.view];
224+
self.view.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin | NSViewHeightSizable;
225+
}
226+
227+
- (void)windowDidEndLiveResitzeWithNotification:(NSNotification *)theNotification
228+
{
229+
self.view.autoresizingMask = NSViewMinXMargin | NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin | NSViewWidthSizable | NSViewHeightSizable;
230+
self.view.frame = self.view.superview.bounds;
207231
}
208232

209233
@end

‎Classes/PBCommitList.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import <Cocoa/Cocoa.h>
10+
#import "PBRefContextDelegate.h"
1011
#import <WebKit/WebView.h>
1112

1213
@class PBGitHistoryController;
@@ -20,6 +21,7 @@ typedef void(^PBFindPanelActionBlock)(id sender);
2021
__weak IBOutlet PBWebHistoryController *webController;
2122
__weak IBOutlet PBGitHistoryController *controller;
2223
__weak IBOutlet PBHistorySearchController *searchController;
24+
__weak IBOutlet id<PBRefContextDelegate> contextMenuDelegate;
2325

2426
BOOL useAdjustScroll;
2527
NSPoint mouseDownPoint;

‎Classes/PBCommitList.m‎

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ - (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows
9393
NSPoint location = mouseDownPoint;
9494
NSInteger row = [self rowAtPoint:location];
9595
NSInteger column = [self columnAtPoint:location];
96-
PBGitRevisionCell *cell = (PBGitRevisionCell *)[self preparedCellAtColumn:column row:row];
96+
PBGitRevisionCell *cell = (PBGitRevisionCell *)[self viewAtColumn:column row:row makeIfNecessary:NO];
9797
NSRect cellFrame = [self frameOfCellAtColumn:column row:row];
9898

9999
int index = -1;
@@ -120,66 +120,42 @@ - (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows
120120
}
121121

122122

123-
#pragma mark Row highlighting
123+
#pragma mark Menu
124124

125-
- (NSColor *)searchResultHighlightColorForRow:(NSInteger)rowIndex
125+
- (NSMenu *)menuForEvent:(NSEvent *)event
126126
{
127-
// if the row is selected use default colors
128-
if ([self isRowSelected:rowIndex]) {
129-
if ([[self window] isKeyWindow]) {
130-
if ([[self window] firstResponder] == self) {
131-
return [NSColor alternateSelectedControlColor];
132-
}
133-
return [NSColor selectedControlColor];
134-
}
135-
return [NSColor secondarySelectedControlColor];
127+
[super menuForEvent:event];
128+
NSInteger index = self.clickedRow;
129+
130+
NSInteger column = [self columnWithIdentifier:@"SubjectColumn"];
131+
PBGitRevisionCell *cell = [self viewAtColumn:column row:index makeIfNecessary:NO];
132+
PBGitCommit *commit = cell.objectValue;
133+
134+
NSPoint point = [self.window.contentView convertPoint:[event locationInWindow] toView:cell];
135+
int i = [cell indexAtX:point.x];
136+
PBGitRef *clickedRef = (i >= 0 ? commit.refs[0] : nil);
137+
138+
NSArray <PBGitCommit*>* selectedCommits = controller.selectedCommits;
139+
NSArray <NSMenuItem *>* items;
140+
141+
if (clickedRef) {
142+
items = [contextMenuDelegate menuItemsForRef:clickedRef];
143+
} else if ([selectedCommits containsObject:commit]) {
144+
items = [contextMenuDelegate menuItemsForCommits:controller.selectedCommits];
145+
} else {
146+
items = [contextMenuDelegate menuItemsForCommits:@[commit]];
136147
}
137148

138-
// light blue color highlighting search results
139-
return [NSColor colorWithCalibratedRed:0.751f green:0.831f blue:0.943f alpha:0.800f];
140-
}
141-
142-
- (NSColor *)searchResultHighlightStrokeColorForRow:(NSInteger)rowIndex
143-
{
144-
if ([self isRowSelected:rowIndex])
145-
return [NSColor colorWithCalibratedWhite:0.0f alpha:0.30f];
149+
NSMenu *menu = [[NSMenu alloc] init];
150+
[menu setAutoenablesItems:NO];
151+
for (NSMenuItem *item in items)
152+
[menu addItem:item];
146153

147-
return [NSColor colorWithCalibratedWhite:0.0f alpha:0.05f];
154+
return menu;
148155
}
149156

150-
- (void)drawRow:(NSInteger)rowIndex clipRect:(NSRect)tableViewClipRect
151-
{
152-
NSRect rowRect = [self rectOfRow:rowIndex];
153-
BOOL isRowVisible = NSIntersectsRect(rowRect, tableViewClipRect);
154-
155-
// draw special highlighting if the row is part of search results
156-
if (isRowVisible && [searchController isRowInSearchResults:rowIndex]) {
157-
NSRect highlightRect = NSInsetRect(rowRect, 1.0f, 1.0f);
158-
CGFloat radius = highlightRect.size.height / 2.0f;
159-
160-
NSBezierPath *highlightPath = [NSBezierPath bezierPathWithRoundedRect:highlightRect xRadius:radius yRadius:radius];
161-
162-
[[self searchResultHighlightColorForRow:rowIndex] set];
163-
[highlightPath fill];
164-
165-
[[self searchResultHighlightStrokeColorForRow:rowIndex] set];
166-
[highlightPath stroke];
167-
}
168-
169-
// draws the content inside the row
170-
[super drawRow:rowIndex clipRect:tableViewClipRect];
171-
}
172-
173-
- (void)highlightSelectionInClipRect:(NSRect)tableViewClipRect
174-
{
175-
// disable highlighting if the selected row is part of search results
176-
// instead do the highlighting in drawRow:clipRect: above
177-
if ([searchController isRowInSearchResults:[self selectedRow]])
178-
return;
179-
180-
[super highlightSelectionInClipRect:tableViewClipRect];
181-
}
182157

158+
#pragma mark Row highlighting
183159

184160
- (IBAction)performFindPanelAction:(id)sender
185161
{

‎Classes/PBSidebarList.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// PBSidebarList.h
3+
// GitX
4+
//
5+
// Created by Max Langer on 05.12.17.
6+
//
7+
8+
#import <Cocoa/Cocoa.h>
9+
10+
NS_ASSUME_NONNULL_BEGIN
11+
12+
@interface PBSidebarList : NSOutlineView
13+
14+
@end
15+
16+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)