11
11
#import " PBChangedFile.h"
12
12
#import " PBWebChangesController.h"
13
13
#import " PBGitIndex.h"
14
+ #import " PBNiceSplitView.h"
15
+
16
+
17
+ #define kCommitSplitViewPositionDefault @" Commit SplitView Position"
14
18
15
19
@interface PBGitCommitController ()
16
20
- (void )refreshFinished : (NSNotification *)notification ;
@@ -22,6 +26,7 @@ - (void)commitHookFailed:(NSNotification *)notification;
22
26
- (void )amendCommit : (NSNotification *)notification ;
23
27
- (void )indexChanged : (NSNotification *)notification ;
24
28
- (void )indexOperationFailed : (NSNotification *)notification ;
29
+ - (void )saveCommitSplitViewPosition ;
25
30
@end
26
31
27
32
@implementation PBGitCommitController
@@ -65,10 +70,14 @@ - (void)awakeFromNib
65
70
66
71
[cachedFilesController setAutomaticallyRearrangesObjects: NO ];
67
72
[unstagedFilesController setAutomaticallyRearrangesObjects: NO ];
73
+
74
+ [commitSplitView setHidden: YES ];
75
+ [self performSelector: @selector (restoreCommitSplitViewPositiion ) withObject: nil afterDelay: 0 ];
68
76
}
69
77
70
78
- (void )closeView
71
79
{
80
+ [self saveCommitSplitViewPosition ];
72
81
[webController closeView ];
73
82
}
74
83
@@ -211,4 +220,78 @@ - (void)indexOperationFailed:(NSNotification *)notification
211
220
[[repository windowController ] showMessageSheet: @" Index operation failed" infoText: [[notification userInfo ] objectForKey: @" description" ]];
212
221
}
213
222
223
+
224
+ #pragma mark NSSplitView delegate methods
225
+
226
+ #define kCommitSplitViewTopViewMin 150
227
+ #define kCommitSplitViewBottomViewMin 100
228
+
229
+ - (CGFloat )splitView : (NSSplitView *)splitView constrainMinCoordinate : (CGFloat )proposedMin ofSubviewAt : (NSInteger )dividerIndex
230
+ {
231
+ if (splitView == commitSplitView)
232
+ return kCommitSplitViewTopViewMin ;
233
+
234
+ return proposedMin;
235
+ }
236
+
237
+ - (CGFloat )splitView : (NSSplitView *)splitView constrainMaxCoordinate : (CGFloat )proposedMax ofSubviewAt : (NSInteger )dividerIndex
238
+ {
239
+ if (splitView == commitSplitView)
240
+ return [splitView frame ].size .height - [splitView dividerThickness ] - kCommitSplitViewBottomViewMin ;
241
+
242
+ return proposedMax;
243
+ }
244
+
245
+ // while the user resizes the window keep the lower (changes/message) view constant and just resize the upper view
246
+ // unless the upper view gets too small
247
+ - (void )resizeCommitSplitView
248
+ {
249
+ NSRect newFrame = [commitSplitView frame ];
250
+
251
+ float dividerThickness = [commitSplitView dividerThickness ];
252
+
253
+ NSView *upperView = [[commitSplitView subviews ] objectAtIndex: 0 ];
254
+ NSRect upperFrame = [upperView frame ];
255
+ upperFrame.size .width = newFrame.size .width ;
256
+
257
+ NSView *lowerView = [[commitSplitView subviews ] objectAtIndex: 1 ];
258
+ NSRect lowerFrame = [lowerView frame ];
259
+ lowerFrame.size .width = newFrame.size .width ;
260
+
261
+ upperFrame.size .height = newFrame.size .height - lowerFrame.size .height - dividerThickness;
262
+ if (upperFrame.size .height < kCommitSplitViewTopViewMin )
263
+ upperFrame.size .height = kCommitSplitViewTopViewMin ;
264
+
265
+ lowerFrame.size .height = newFrame.size .height - upperFrame.size .height - dividerThickness;
266
+ lowerFrame.origin .y = newFrame.size .height - lowerFrame.size .height ;
267
+
268
+ [upperView setFrame: upperFrame];
269
+ [lowerView setFrame: lowerFrame];
270
+ }
271
+
272
+ - (void )splitView : (NSSplitView *)splitView resizeSubviewsWithOldSize : (NSSize )oldSize
273
+ {
274
+ if (splitView == commitSplitView)
275
+ [self resizeCommitSplitView ];
276
+ }
277
+
278
+ // NSSplitView does not save and restore the position of the splitView correctly so do it manually
279
+ - (void )saveCommitSplitViewPosition
280
+ {
281
+ float position = [[[commitSplitView subviews ] objectAtIndex: 0 ] frame ].size .height ;
282
+ [[NSUserDefaults standardUserDefaults ] setFloat: position forKey: kCommitSplitViewPositionDefault ];
283
+ [[NSUserDefaults standardUserDefaults ] synchronize ];
284
+ }
285
+
286
+ // make sure this happens after awakeFromNib
287
+ - (void )restoreCommitSplitViewPositiion
288
+ {
289
+ float position = [[NSUserDefaults standardUserDefaults ] floatForKey: kCommitSplitViewPositionDefault ];
290
+ if (position < 1.0 )
291
+ position = [commitSplitView frame ].size .height - 225 ;
292
+
293
+ [commitSplitView setPosition: position ofDividerAtIndex: 0 ];
294
+ [commitSplitView setHidden: NO ];
295
+ }
296
+
214
297
@end
0 commit comments