// // ErrorPanelController.m // Perforce // // Created by Adam Czubernat on 17.06.2014. // Copyright (c) 2014 Perforce Software, Inc. All rights reserved. // #import "ErrorPanelController.h" #import "P4Connection.h" @interface ErrorPanelController () { void (^completionBlock)(void); __weak IBOutlet NSTextField *titleLabel; __unsafe_unretained IBOutlet NSTextView *textView; __weak IBOutlet NSLayoutConstraint *textViewConstraint; __weak IBOutlet NSButton *detailsButton; __weak IBOutlet NSView *detailsView; __unsafe_unretained IBOutlet NSTextView *detailsTextView; __weak IBOutlet NSLayoutConstraint *detailsViewConstraint; } - (IBAction)dismissPressed:(id)sender; - (IBAction)detailsPressed:(id)sender; @end @implementation ErrorPanelController @synthesize title, message, details, detailsTitle; - (void)windowDidLoad { [super windowDidLoad]; NSSize layoutSize = (NSSize) { 1000000, 1000000 }; // Text wrapping [[detailsTextView textContainer] setWidthTracksTextView:NO]; [[detailsTextView textContainer] setContainerSize:layoutSize]; // Text scrolling [detailsTextView setMaxSize:layoutSize]; // Clipping [detailsTextView setHorizontallyResizable:YES]; // Scrolling self.title = title; self.message = message; detailsViewConstraint.constant = 0.0; if (detailsTitle) detailsButton.title = detailsTitle; if (!details) [detailsView removeFromSuperview]; // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // [self.window visualizeConstraints:[self.window.contentView constraints]]; // }); } - (void)close { [super close]; if (completionBlock) completionBlock(); completionBlock = nil; } - (void)setTitle:(NSString *)string { title = [string copy]; titleLabel.stringValue = title; } - (void)setMessage:(NSString *)string { message = [string copy]; textView.string = message; // Set textview size for autolayout's constraint NSTextContainer *textContainer = [textView textContainer]; NSLayoutManager *layoutManager = [textView layoutManager]; [layoutManager ensureLayoutForTextContainer:textContainer]; textViewConstraint.constant = [layoutManager usedRectForTextContainer: textContainer].size.height; } #pragma mark - Actions - (IBAction)dismissPressed:(id)sender { [self dismiss]; } - (IBAction)detailsPressed:(NSButton *)sender { [NSView animateWithDuration:0.1f animations:^{ [[detailsViewConstraint animator] setConstant:sender.state ? 215.0 : 0.0]; } completion:^{ detailsTextView.string = details; }]; } #pragma mark - Public - (void)setCompletionBlock:(void (^)(void))block { completionBlock = [block copy]; } @end