forked from gnachman/iTerm2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iTermMinimalComposerViewController.m
84 lines (66 loc) · 2.68 KB
/
iTermMinimalComposerViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// iTermMinimalComposerViewController.m
// iTerm2
//
// Created by George Nachman on 3/31/20.
//
#import "iTermMinimalComposerViewController.h"
#import "iTermStatusBarLargeComposerViewController.h"
static float kAnimationDuration = 0.25;
static CGFloat desiredHeight = 135;
@interface iTermMinimalComposerViewController ()<iTermComposerTextViewDelegate>
@end
@implementation iTermMinimalComposerViewController {
IBOutlet iTermStatusBarLargeComposerViewController *_largeComposerViewController;
IBOutlet NSView *_containerView;
IBOutlet NSVisualEffectView *_vev;
}
- (instancetype)init {
self = [super initWithNibName:NSStringFromClass(self.class) bundle:[NSBundle bundleForClass:self.class]];
return self;
}
- (void)awakeFromNib {
[_containerView addSubview:_largeComposerViewController.view];
_containerView.autoresizesSubviews = YES;
_largeComposerViewController.view.frame = _containerView.bounds;
_largeComposerViewController.textView.composerDelegate = self;
_largeComposerViewController.view.autoresizingMask = (NSViewWidthSizable | NSViewHeightSizable);
_vev.layer.cornerRadius = 6;
_vev.layer.borderColor = [[NSColor grayColor] CGColor];
_vev.layer.borderWidth = 1;
}
- (void)updateFrame {
NSRect newFrame = self.view.frame;
newFrame.origin.y = self.view.superview.frame.size.height;
self.view.frame = newFrame;
newFrame.origin.y += self.view.frame.size.height;
const CGFloat maxWidth = self.view.superview.bounds.size.width - self.view.frame.origin.x - 19;
newFrame = NSMakeRect(self.view.frame.origin.x,
self.view.superview.frame.size.height - desiredHeight,
MAX(217, maxWidth),
desiredHeight);
[[NSAnimationContext currentContext] setDuration:kAnimationDuration];
self.view.frame = newFrame;
self.view.animator.alphaValue = 1;
}
- (void)makeFirstResponder {
[_largeComposerViewController.textView.window makeFirstResponder:_largeComposerViewController.textView];
}
- (IBAction)performClose:(id)sender {
[self.delegate minimalComposer:self sendCommand:@""];
}
- (NSString *)stringValue {
return _largeComposerViewController.textView.string;
}
- (void)setStringValue:(NSString *)stringValue {
_largeComposerViewController.textView.string = stringValue;
}
#pragma mark - iTermComposerTextViewDelegate
- (void)composerTextViewDidFinishWithCancel:(BOOL)cancel {
NSString *string = cancel ? @"" : _largeComposerViewController.textView.string;
[self.delegate minimalComposer:self sendCommand:string ?: @""];
}
- (void)composerTextViewDidResignFirstResponder {
[self.delegate minimalComposer:self sendCommand:@""];
}
@end