Files
gitx/PBGitWindowController.m
T
Nathan Kinsinger 64f4276e21 Delete old toolbars and create new ones
- remove the separate window toolbars from the history and commit views and create a new window toolbar in the repository window
    - add new toolbars inside the history view
        - new class to draw a gradient in the background of a view
        - moved the search field from the main toolbar to the scope bar
2010-03-13 22:14:36 -07:00

186 lines
5.2 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"
#import "Terminal.h"
#import "PBCloneRepsitoryToSheet.h"
#import "PBGitSidebarController.h"
@implementation PBGitWindowController
@synthesize repository;
- (id)initWithRepository:(PBGitRepository*)theRepository displayDefault:(BOOL)displayDefault
{
if (!(self = [self initWithWindowNibName:@"RepositoryWindow"]))
return nil;
self.repository = theRepository;
return self;
}
- (void)windowWillClose:(NSNotification *)notification
{
NSLog(@"Window will close!");
if (sidebarController)
[sidebarController removeView];
}
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
{
if ([menuItem action] == @selector(showCommitView:) || [menuItem action] == @selector(showHistoryView:)) {
return ![repository isBareRepository];
}
return YES;
}
- (void) awakeFromNib
{
[[self window] setDelegate:self];
sidebarController = [[PBGitSidebarController alloc] initWithRepository:repository superController:self];
[[sidebarController view] setFrame:[sourceSplitView bounds]];
[sourceSplitView addSubview:[sidebarController view]];
[self showWindow:nil];
}
- (void) removeAllContentSubViews
{
if ([contentSplitView subviews])
while ([[contentSplitView subviews] count] > 0)
[[[contentSplitView subviews] lastObject] removeFromSuperviewWithoutNeedingDisplay];
}
- (void) changeContentController:(PBViewController *)controller
{
if (!controller || (contentController == controller))
return;
[self removeAllContentSubViews];
contentController = controller;
[[contentController view] setFrame:[contentSplitView bounds]];
[contentSplitView addSubview:[contentController view]];
[self setNextResponder: contentController];
[[self window] makeFirstResponder:[contentController firstResponder]];
[contentController updateView];
}
- (void) showCommitView:(id)sender
{
[sidebarController selectStage];
}
- (void) showHistoryView:(id)sender
{
[sidebarController selectCurrentBranch];
}
- (void)showMessageSheet:(NSString *)messageText infoText:(NSString *)infoText
{
[[NSAlert alertWithMessageText:messageText
defaultButton:nil
alternateButton:nil
otherButton:nil
informativeTextWithFormat:infoText] beginSheetModalForWindow: [self window] modalDelegate:self didEndSelector:nil contextInfo:nil];
}
- (void)showErrorSheet:(NSError *)error
{
[[NSAlert alertWithError:error] beginSheetModalForWindow: [self window] modalDelegate:self didEndSelector:nil contextInfo:nil];
}
- (void)showErrorSheetTitle:(NSString *)title message:(NSString *)message arguments:(NSArray *)arguments output:(NSString *)output
{
NSString *command = [arguments componentsJoinedByString:@" "];
NSString *reason = [NSString stringWithFormat:@"%@\n\ncommand: git %@\n%@", message, command, output];
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
title, NSLocalizedDescriptionKey,
reason, NSLocalizedRecoverySuggestionErrorKey,
nil];
NSError *error = [NSError errorWithDomain:PBGitRepositoryErrorDomain code:0 userInfo:userInfo];
[self showErrorSheet:error];
}
- (IBAction) revealInFinder:(id)sender
{
[[NSWorkspace sharedWorkspace] openFile:[repository workingDirectory]];
}
- (IBAction) openInTerminal:(id)sender
{
TerminalApplication *term = [SBApplication applicationWithBundleIdentifier: @"com.apple.Terminal"];
NSString *workingDirectory = [[repository workingDirectory] stringByAppendingString:@"/"];
NSString *cmd = [NSString stringWithFormat: @"cd \"%@\"; clear; echo '# Opened by GitX:'; git status", workingDirectory];
[term doScript: cmd in: nil];
[NSThread sleepForTimeInterval: 0.1];
[term activate];
}
- (IBAction) cloneTo:(id)sender
{
[PBCloneRepsitoryToSheet beginCloneRepsitoryToSheetForRepository:repository];
}
#pragma mark -
#pragma mark SplitView Delegates
#define kGitSplitViewMinWidth 150.0f
#define kGitSplitViewMaxWidth 300.0f
#pragma mark min/max widths while moving the divider
- (CGFloat)splitView:(NSSplitView *)view constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex
{
if (proposedMin < kGitSplitViewMinWidth)
return kGitSplitViewMinWidth;
return proposedMin;
}
- (CGFloat)splitView:(NSSplitView *)view constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex
{
if (dividerIndex == 0)
return kGitSplitViewMaxWidth;
return proposedMax;
}
#pragma mark constrain sidebar width while resizing the window
- (void)splitView:(NSSplitView *)sender resizeSubviewsWithOldSize:(NSSize)oldSize
{
NSRect newFrame = [sender frame];
float dividerThickness = [sender dividerThickness];
NSView *sourceView = [[sender subviews] objectAtIndex:0];
NSRect sourceFrame = [sourceView frame];
sourceFrame.size.height = newFrame.size.height;
NSView *mainView = [[sender subviews] objectAtIndex:1];
NSRect mainFrame = [mainView frame];
mainFrame.origin.x = sourceFrame.size.width + dividerThickness;
mainFrame.size.width = newFrame.size.width - mainFrame.origin.x;
mainFrame.size.height = newFrame.size.height;
[sourceView setFrame:sourceFrame];
[mainView setFrame:mainFrame];
}
@end