forked from gnachman/iTerm2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSessionView.m
More file actions
235 lines (208 loc) · 6.43 KB
/
Copy pathSessionView.m
File metadata and controls
235 lines (208 loc) · 6.43 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// -*- mode:objc -*-
/*
** SessionView.m
**
** Copyright (c) 2010
**
** Author: George Nachman
**
** Project: iTerm2
**
** Description: This view contains a session's scrollview.
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#import "SessionView.h"
#import "PTYSession.h"
#import "PTYTab.h"
#import "PTYTextView.h"
static const float kTargetFrameRate = 1.0/60.0;
static int nextViewId;
// Last time any window was resized TODO(georgen):it would be better to track per window.
static NSDate* lastResizeDate_;
@implementation SessionView
+ (void)initialize
{
lastResizeDate_ = [[NSDate date] retain];
}
+ (void)windowDidResize
{
[lastResizeDate_ release];
lastResizeDate_ = [[NSDate date] retain];
}
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[lastResizeDate_ release];
lastResizeDate_ = [[NSDate date] retain];
findView_ = [[FindViewController alloc] initWithNibName:@"FindView" bundle:nil];
[[findView_ view] setHidden:YES];
[self addSubview:[findView_ view]];
NSRect aRect = [self frame];
[findView_ setFrameOrigin:NSMakePoint(aRect.size.width - [[findView_ view] frame].size.width - 30,
aRect.size.height - [[findView_ view] frame].size.height)];
viewId_ = nextViewId++;
}
return self;
}
- (id)initWithFrame:(NSRect)frame session:(PTYSession*)session
{
self = [self initWithFrame:frame];
if (self) {
[lastResizeDate_ release];
lastResizeDate_ = [[NSDate date] retain];
session_ = [session retain];
}
return self;
}
- (void)addSubview:(NSView *)aView
{
static BOOL running;
BOOL wasRunning = running;
running = YES;
if (!wasRunning && findView_ && aView != [findView_ view]) {
[super addSubview:aView positioned:NSWindowBelow relativeTo:[findView_ view]];
} else {
[super addSubview:aView];
}
running = NO;
}
- (void)dealloc
{
[session_ release];
[super dealloc];
}
- (PTYSession*)session
{
return session_;
}
- (void)setSession:(PTYSession*)session
{
[session_ autorelease];
session_ = [session retain];
}
- (void)fadeAnimation
{
timer_ = nil;
float elapsed = [[NSDate date] timeIntervalSinceDate:previousUpdate_];
float newDimmingAmount = currentDimmingAmount_ + elapsed * changePerSecond_;
[previousUpdate_ release];
if ((changePerSecond_ > 0 && newDimmingAmount > targetDimmingAmount_) ||
(changePerSecond_ < 0 && newDimmingAmount < targetDimmingAmount_)) {
currentDimmingAmount_ = targetDimmingAmount_;
[[session_ TEXTVIEW] setDimmingAmount:targetDimmingAmount_];
} else {
[[session_ TEXTVIEW] setDimmingAmount:newDimmingAmount];
currentDimmingAmount_ = newDimmingAmount;
previousUpdate_ = [[NSDate date] retain];
timer_ = [NSTimer scheduledTimerWithTimeInterval:1.0/60.0
target:self
selector:@selector(fadeAnimation)
userInfo:nil
repeats:NO];
}
}
- (void)_dimShadeToDimmingAmount:(float)newDimmingAmount
{
targetDimmingAmount_ = newDimmingAmount;
previousUpdate_ = [[NSDate date] retain];
const double kAnimationDuration = 0.1;
changePerSecond_ = (targetDimmingAmount_ - currentDimmingAmount_) / kAnimationDuration;
if (changePerSecond_ == 0) {
// Nothing to do.
return;
}
if (timer_) {
[timer_ invalidate];
timer_ = nil;
}
[self fadeAnimation];
}
- (double)dimmedDimmingAmount
{
NSNumber* n = [[NSUserDefaults standardUserDefaults] objectForKey:@"SplitPaneDimmingAmount"];
return n ? [n doubleValue] : 0.15;
}
- (void)setDimmed:(BOOL)isDimmed
{
if (shuttingDown_) {
return;
}
if (isDimmed == dim_) {
return;
}
dim_ = isDimmed;
if (isDimmed) {
currentDimmingAmount_ = 0;
[[session_ TEXTVIEW] setDimmingAmount:0];
[self _dimShadeToDimmingAmount:[self dimmedDimmingAmount]];
} else {
[self _dimShadeToDimmingAmount:0];
}
}
- (void)cancelTimers
{
shuttingDown_ = YES;
[timer_ invalidate];
}
- (void)rightMouseDown:(NSEvent*)event
{
[[[self session] TEXTVIEW] rightMouseDown:event];
}
- (void)mouseDown:(NSEvent*)event
{
if ([[[self session] TEXTVIEW] mouseDownImpl:event]) {
[super mouseDown:event];
}
}
- (FindViewController*)findViewController
{
return findView_;
}
- (void)setViewId:(int)viewId
{
viewId_ = viewId;
}
- (int)viewId
{
return viewId_;
}
- (void)setFrameSize:(NSSize)frameSize
{
[super setFrameSize:frameSize];
if (frameSize.width < 340) {
[[findView_ view] setFrameSize:NSMakeSize(MAX(150, frameSize.width - 50),
[[findView_ view] frame].size.height)];
[findView_ setFrameOrigin:NSMakePoint(frameSize.width - [[findView_ view] frame].size.width - 30,
frameSize.height - [[findView_ view] frame].size.height)];
} else {
[[findView_ view] setFrameSize:NSMakeSize(290,
[[findView_ view] frame].size.height)];
[findView_ setFrameOrigin:NSMakePoint(frameSize.width - [[findView_ view] frame].size.width - 30,
frameSize.height - [[findView_ view] frame].size.height)];
}
}
+ (NSDate*)lastResizeDate
{
return lastResizeDate_;
}
// This is called as part of the live resizing protocol when you let up the mouse button.
- (void)viewDidEndLiveResize
{
[lastResizeDate_ release];
lastResizeDate_ = [[NSDate date] retain];
}
@end