mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
b2cd87cb72
Previously, we would try to copy the view selector from within the RepositoryWindow, so we could reuse it and change it if we need to. However, that causes problems if you have another window open: if we try to add an item using the insertItemWithIdentifier:atIndex: method, the item will be added to _all_ toolbars with the same identifier, even if those toolbars already have the item! As I see no easy way to fix that, we completely avoid the issue by not inserting any objects and just copying the view selector from view to view.
100 lines
2.5 KiB
Objective-C
100 lines
2.5 KiB
Objective-C
//
|
|
// PBDetailController.m
|
|
// GitX
|
|
//
|
|
// Created by Pieter de Bie on 16-06-08.
|
|
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
|
//
|
|
|
|
#import "PBGitWindowController.h"
|
|
#import "PBGitHistoryController.h"
|
|
#import "PBGitCommitController.h"
|
|
|
|
|
|
@implementation PBGitWindowController
|
|
|
|
|
|
@synthesize repository, viewController, selectedViewIndex;
|
|
|
|
- (id)initWithRepository:(PBGitRepository*)theRepository displayDefault:(BOOL)displayDefault
|
|
{
|
|
if(self = [self initWithWindowNibName:@"RepositoryWindow"])
|
|
{
|
|
self.repository = theRepository;
|
|
[self showWindow:nil];
|
|
}
|
|
|
|
if (displayDefault) {
|
|
self.selectedViewIndex = [[NSUserDefaults standardUserDefaults] integerForKey:@"selectedViewIndex"];
|
|
} else {
|
|
self.selectedViewIndex = -1;
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (void) setSelectedViewIndex: (int) i
|
|
{
|
|
selectedViewIndex = i;
|
|
[[NSUserDefaults standardUserDefaults] setInteger:i forKey:@"selectedViewIndex"];
|
|
[self changeViewController: i];
|
|
}
|
|
|
|
- (void)changeViewController:(NSInteger)whichViewTag
|
|
{
|
|
[self willChangeValueForKey:@"viewController"];
|
|
|
|
if ([viewController view] != nil)
|
|
[(PBViewController *)viewController removeView];
|
|
|
|
switch (whichViewTag)
|
|
{
|
|
case 0: // swap in the "CustomImageViewController - NSImageView"
|
|
viewController = [[PBGitHistoryController alloc] initWithRepository:repository superController:self];
|
|
break;
|
|
case 1:
|
|
viewController = [[PBGitCommitController alloc] initWithRepository:repository superController:self];
|
|
break;
|
|
}
|
|
|
|
// make sure we automatically resize the controller's view to the current window size
|
|
[[viewController view] setFrame: [contentView bounds]];
|
|
|
|
//// embed the current view to our host view
|
|
[contentView addSubview: [viewController view]];
|
|
|
|
// Allow the viewcontroller to catch actions
|
|
[self setNextResponder: viewController];
|
|
[self didChangeValueForKey:@"viewController"]; // this will trigger the NSTextField's value binding to change
|
|
}
|
|
|
|
- (void)awakeFromNib
|
|
{
|
|
[[self window] setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge];
|
|
[[self window] setContentBorderThickness:35.0f forEdge:NSMinYEdge];
|
|
[self showHistoryView:nil];
|
|
}
|
|
|
|
- (void) showCommitView:(id)sender
|
|
{
|
|
self.selectedViewIndex = 1;
|
|
}
|
|
|
|
- (void) showHistoryView:(id)sender
|
|
{
|
|
self.selectedViewIndex = 0;
|
|
}
|
|
|
|
#pragma mark -
|
|
#pragma mark Toolbar Delegates
|
|
|
|
- (void) useToolbar:(NSToolbar *)toolbar
|
|
{
|
|
NSSegmentedControl *item = (NSSegmentedControl *)[[[toolbar items] objectAtIndex:0] view];
|
|
[item bind:@"selectedIndex" toObject:self withKeyPath:@"selectedViewIndex" options:0];
|
|
|
|
[self.window setToolbar:toolbar];
|
|
}
|
|
|
|
@end
|