Permalink
Browse files

Show long messages and errors in a scroll view

This stops really long sheets when the output from git is very long.
  • Loading branch information...
brotherbard committed Jul 5, 2010
1 parent 66e260f commit 549f2c1d6a5459c92aefe6e3a98798f3fa31b9da
Showing with 1,394 additions and 6 deletions.
  1. +10 −0 GitX.xcodeproj/project.pbxproj
  2. +6 −6 PBGitWindowController.m
  3. +32 −0 PBGitXMessageSheet.h
  4. +124 −0 PBGitXMessageSheet.m
  5. +1,222 −0 PBGitXMessageSheet.xib
@@ -46,6 +46,8 @@
93CB42C20EAB7B2200530609 /* PBGitDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 93CB42C10EAB7B2200530609 /* PBGitDefaults.m */; };
93F7857F0EA3ABF100C1F443 /* PBCommitMessageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 93F7857E0EA3ABF100C1F443 /* PBCommitMessageView.m */; };
D26DC6450E782C9000C777B2 /* gitx.icns in Resources */ = {isa = PBXBuildFile; fileRef = D26DC6440E782C9000C777B2 /* gitx.icns */; };
+ D8022FE811E124A0003C21F6 /* PBGitXMessageSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = D8022FE711E124A0003C21F6 /* PBGitXMessageSheet.xib */; };
+ D8022FED11E124C8003C21F6 /* PBGitXMessageSheet.m in Sources */ = {isa = PBXBuildFile; fileRef = D8022FEC11E124C8003C21F6 /* PBGitXMessageSheet.m */; };
D8083A43111E045D00337480 /* PBRemoteProgressSheet.m in Sources */ = {isa = PBXBuildFile; fileRef = D8083A42111E045D00337480 /* PBRemoteProgressSheet.m */; };
D8083C44111F106800337480 /* PBAddRemoteSheet.m in Sources */ = {isa = PBXBuildFile; fileRef = D8083C43111F106800337480 /* PBAddRemoteSheet.m */; };
D8083C47111F136400337480 /* PBAddRemoteSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = D8083C45111F136400337480 /* PBAddRemoteSheet.xib */; };
@@ -270,6 +272,9 @@
93FCCBA80EA8AF450061B02B /* PBGitConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitConfig.m; sourceTree = "<group>"; };
D26DC6440E782C9000C777B2 /* gitx.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = gitx.icns; sourceTree = "<group>"; };
D8022A3411DFCCA5003C21F6 /* build_libgit2.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = build_libgit2.sh; sourceTree = "<group>"; };
+ D8022FE711E124A0003C21F6 /* PBGitXMessageSheet.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = PBGitXMessageSheet.xib; path = ../GitX/PBGitXMessageSheet.xib; sourceTree = SOURCE_ROOT; };
+ D8022FEB11E124C8003C21F6 /* PBGitXMessageSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitXMessageSheet.h; sourceTree = "<group>"; };
+ D8022FEC11E124C8003C21F6 /* PBGitXMessageSheet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitXMessageSheet.m; sourceTree = "<group>"; };
D8083A2D111E045300337480 /* PBRemoteProgressSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBRemoteProgressSheet.h; sourceTree = "<group>"; };
D8083A42111E045D00337480 /* PBRemoteProgressSheet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBRemoteProgressSheet.m; sourceTree = "<group>"; };
D8083C42111F106800337480 /* PBAddRemoteSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBAddRemoteSheet.h; sourceTree = "<group>"; };
@@ -610,6 +615,7 @@
47DBDB680E94EF6500671A1E /* Preferences.xib */,
F569AE920F2CBD7C00C2FFA7 /* Credits.html */,
F58DB55F10566E3900CFDF4A /* PBGitSidebarView.xib */,
+ D8022FE711E124A0003C21F6 /* PBGitXMessageSheet.xib */,
);
name = Resources;
sourceTree = "<group>";
@@ -673,6 +679,8 @@
D8083DC3111F90F300337480 /* PBCloneRepsitoryToSheet.m */,
D8083E01111FA33700337480 /* PBCloneRepositoryPanel.h */,
D8083E02111FA33700337480 /* PBCloneRepositoryPanel.m */,
+ D8022FEB11E124C8003C21F6 /* PBGitXMessageSheet.h */,
+ D8022FEC11E124C8003C21F6 /* PBGitXMessageSheet.m */,
);
name = Sheets;
sourceTree = "<group>";
@@ -1119,6 +1127,7 @@
D8A4BD081134AD2900E92D51 /* MergeTemplate.png in Resources */,
D8A4BD091134AD2900E92D51 /* RebaseTemplate.png in Resources */,
D828AEEC112F411100F09D11 /* CloneRepositoryTemplate.png in Resources */,
+ D8022FE811E124A0003C21F6 /* PBGitXMessageSheet.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1248,6 +1257,7 @@
D8295DE01130E43900C838E8 /* PBGitHistoryGrapher.m in Sources */,
D8E105471157C18200FC28A4 /* PBQLTextView.m in Sources */,
D8FBCF19115FA20C0098676A /* PBGitSHA.m in Sources */,
+ D8022FED11E124C8003C21F6 /* PBGitXMessageSheet.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -11,6 +11,7 @@
#import "PBGitCommitController.h"
#import "Terminal.h"
#import "PBCloneRepsitoryToSheet.h"
+#import "PBGitXMessageSheet.h"
#import "PBGitSidebarController.h"
@implementation PBGitWindowController
@@ -110,16 +111,15 @@ - (void) showHistoryView:(id)sender
- (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];
+ [PBGitXMessageSheet beginMessageSheetForWindow:[self window] withMessageText:messageText infoText:infoText];
}
- (void)showErrorSheet:(NSError *)error
{
- [[NSAlert alertWithError:error] beginSheetModalForWindow: [self window] modalDelegate:self didEndSelector:nil contextInfo:nil];
+ if ([[error domain] isEqualToString:PBGitRepositoryErrorDomain])
+ [PBGitXMessageSheet beginMessageSheetForWindow:[self window] withError:error];
+ else
+ [[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
View
@@ -0,0 +1,32 @@
+//
+// PBGitXMessageSheet.h
+// GitX
+//
+// Created by BrotherBard on 7/4/10.
+// Copyright 2010 BrotherBard. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface PBGitXMessageSheet : NSWindowController
+{
+ NSImageView *iconView;
+ NSTextField *messageField;
+ NSTextView *infoView;
+ NSScrollView *scrollView;
+}
+
++ (void)beginMessageSheetForWindow:(NSWindow *)parentWindow withMessageText:(NSString *)message infoText:(NSString *)info;
++ (void)beginMessageSheetForWindow:(NSWindow *)parentWindow withError:(NSError *)error;
+
+
+- (IBAction)closeMessageSheet:(id)sender;
+
+
+@property (assign) IBOutlet NSImageView *iconView;
+@property (assign) IBOutlet NSTextField *messageField;
+@property (assign) IBOutlet NSTextView *infoView;
+@property (assign) IBOutlet NSScrollView *scrollView;
+
+@end
View
@@ -0,0 +1,124 @@
+//
+// PBGitXMessageSheet.m
+// GitX
+//
+// Created by BrotherBard on 7/4/10.
+// Copyright 2010 BrotherBard. All rights reserved.
+//
+
+#import "PBGitXMessageSheet.h"
+
+
+#define MaxScrollViewHeight 125.0f
+
+
+@interface PBGitXMessageSheet ()
+
+- (void)beginMessageSheetForWindow:(NSWindow *)parentWindow withMessageText:(NSString *)message infoText:(NSString *)info;
+
+- (void)setInfoString:(NSString *)info;
+- (void)resizeWindow;
+
+@end
+
+
+
+@implementation PBGitXMessageSheet
+
+
+@synthesize iconView;
+@synthesize messageField;
+@synthesize infoView;
+@synthesize scrollView;
+
+
+#pragma mark -
+#pragma mark PBGitXMessageSheet
+
++ (void)beginMessageSheetForWindow:(NSWindow *)parentWindow withMessageText:(NSString *)message infoText:(NSString *)info
+{
+ PBGitXMessageSheet *sheet = [[self alloc] initWithWindowNibName:@"PBGitXMessageSheet"];
+ [sheet beginMessageSheetForWindow:parentWindow withMessageText:message infoText:info];
+}
+
+
++ (void)beginMessageSheetForWindow:(NSWindow *)parentWindow withError:(NSError *)error
+{
+ PBGitXMessageSheet *sheet = [[self alloc] initWithWindowNibName:@"PBGitXMessageSheet"];
+ [sheet beginMessageSheetForWindow:parentWindow withMessageText:[error localizedDescription] infoText:[error localizedRecoverySuggestion]];
+}
+
+
+- (IBAction)closeMessageSheet:(id)sender
+{
+ [NSApp endSheet:[self window]];
+ [[self window] orderOut:self];
+}
+
+
+
+#pragma mark Private
+
+- (void)beginMessageSheetForWindow:(NSWindow *)parentWindow withMessageText:(NSString *)message infoText:(NSString *)info;
+{
+ [self window];
+
+ [self.messageField setStringValue:message];
+ [self setInfoString:info];
+ [self resizeWindow];
+
+ [NSApp beginSheet:[self window] modalForWindow:parentWindow modalDelegate:self didEndSelector:nil contextInfo:NULL];
+}
+
+
+- (void)setInfoString:(NSString *)info
+{
+ NSDictionary *attributes = [NSDictionary dictionaryWithObject:[NSFont labelFontOfSize:[NSFont smallSystemFontSize]]
+ forKey:NSFontAttributeName];
+ NSAttributedString *attributedInfoString = [[NSAttributedString alloc] initWithString:info attributes:attributes];
+ [[self.infoView textStorage] setAttributedString:attributedInfoString];
+}
+
+
+- (void)resizeWindow
+{
+ // resize for message text
+ NSRect messageFrame = [self.messageField frame];
+ NSSize boundingSize = messageFrame.size;
+ boundingSize.height = 0.0f;
+ NSAttributedString *attributedTitle = [self.messageField attributedStringValue];
+ NSRect boundingRect = [attributedTitle boundingRectWithSize:boundingSize options:NSStringDrawingUsesLineFragmentOrigin];
+ CGFloat heightDelta = boundingRect.size.height - messageFrame.size.height;
+ if (heightDelta > 0.0f) {
+ messageFrame.size.height += heightDelta;
+ messageFrame.origin.y -= heightDelta;
+ [self.messageField setFrame:messageFrame];
+
+ NSRect scrollFrame = [self.scrollView frame];
+ scrollFrame.size.height -= heightDelta;
+ [self.scrollView setFrame:scrollFrame];
+
+ NSRect windowFrame = [[self window] frame];
+ windowFrame.size.height += heightDelta;
+ [[self window] setFrame:windowFrame display:NO];
+ }
+
+ // resize for info text
+ NSRect scrollFrame = [self.scrollView frame];
+ boundingSize = [self.scrollView bounds].size;
+ boundingSize.height = 0.0f;
+ NSAttributedString *attributedInfo = [[self.infoView layoutManager] attributedString];
+ boundingRect = [attributedInfo boundingRectWithSize:boundingSize options:NSStringDrawingUsesLineFragmentOrigin];
+ heightDelta = boundingRect.size.height - scrollFrame.size.height;
+ if (heightDelta > MaxScrollViewHeight)
+ heightDelta = MaxScrollViewHeight;
+ if (heightDelta > 0.0f) {
+ NSRect windowFrame = [[self window] frame];
+ windowFrame.size.height += heightDelta;
+ [[self window] setFrame:windowFrame display:NO];
+ }
+ [self.infoView scrollRangeToVisible:NSMakeRange(0, 0)];
+}
+
+
+@end
Oops, something went wrong.

0 comments on commit 549f2c1

Please sign in to comment.