Skip to content

Commit

Permalink
Clean up PseudoTerminal a little and fix some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gnachman committed Dec 27, 2013
1 parent 51ca7cd commit 3340ffc
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 162 deletions.
19 changes: 7 additions & 12 deletions BottomBarView.m
Expand Up @@ -10,20 +10,15 @@

@implementation BottomBarView

- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}

- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];

// Drawing code here.
[[NSColor controlColor] setFill];
NSRectFill(dirtyRect);

// Draw a black line at the top of the view.
[[NSColor blackColor] setFill];
NSRect r = [self frame];
NSRectFill(NSMakeRect(0, r.size.height - 1, r.size.width, 1));
}

@end
43 changes: 5 additions & 38 deletions PseudoTerminal.h
@@ -1,32 +1,3 @@
// -*- mode:objc -*-
// $Id: PseudoTerminal.h,v 1.62 2009-02-06 15:07:24 delx Exp $
/*
** PseudoTerminal.h
**
** Copyright (c) 2002, 2003
**
** Author: Fabian, Ujwal S. Setlur
** Initial code by Kiichi Kusama
**
** Project: iTerm
**
** Description: Session and window controller for iTerm.
**
** 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 <Cocoa/Cocoa.h>
#import "PSMTabBarControl.h"
#import "PTYTabView.h"
Expand All @@ -39,8 +10,12 @@
#import "SolidColorView.h"
#import "FutureMethods.h"

@class PTYSession, iTermController, PTToolbarController, PSMTabBarControl;
@class BottomBarView;
@class PTYSession;
@class PSMTabBarControl;
@class PTToolbarController;
@class ToolbeltView;
@class iTermController;

typedef enum {
BROADCAST_OFF,
Expand All @@ -49,14 +24,6 @@ typedef enum {
BROADCAST_CUSTOM
} BroadcastMode;

// The BottomBar's view is of this class. It overrides drawing the background.
@interface BottomBarView : NSView
{
}
- (void)drawRect:(NSRect)dirtyRect;

@end

@class TmuxController;

// This class is 1:1 with windows. It controls the tabs, bottombar, toolbar,
Expand Down
157 changes: 48 additions & 109 deletions PseudoTerminal.m
@@ -1,5 +1,6 @@
#import "PseudoTerminal.h"

#import "BottomBarView.h"
#import "ColorsMenuItemView.h"
#import "Coprocess.h"
#import "FakeWindow.h"
Expand Down Expand Up @@ -52,7 +53,6 @@
static NSString* TERMINAL_ARRANGEMENT_OLD_Y_ORIGIN = @"Old Y Origin";
static NSString* TERMINAL_ARRANGEMENT_OLD_WIDTH = @"Old Width";
static NSString* TERMINAL_ARRANGEMENT_OLD_HEIGHT = @"Old Height";

static NSString* TERMINAL_ARRANGEMENT_X_ORIGIN = @"X Origin";
static NSString* TERMINAL_ARRANGEMENT_Y_ORIGIN = @"Y Origin";
static NSString* TERMINAL_ARRANGEMENT_WIDTH = @"Width";
Expand Down Expand Up @@ -81,68 +81,6 @@ - (void)setBottomCornerRounded:(BOOL)rounded;
// keys for to-many relationships:
NSString *kSessionsKVCKey = @"sessions";

#define TABVIEW_TOP_OFFSET 29
#define TABVIEW_BOTTOM_OFFSET 27
#define TABVIEW_LEFT_RIGHT_OFFSET 29
#define TOOLBAR_OFFSET 0

@class PTYSession, iTermController, PTToolbarController, PSMTabBarControl;

@interface PseudoTerminal ()
- (void)updateDivisionView;
- (NSRect)traditionalFullScreenFrameForScreen:(NSScreen *)screen;
- (void)_updateToolbeltParentage;
- (CGFloat)fullscreenToolbeltWidth;
- (BOOL)_haveLeftBorder;
- (BOOL)_haveRightBorder;
- (void)fitBottomBarToWindow;
- (void)repositionWidgets;
- (int)_screenAtPoint:(NSPoint)p;
- (void)copySettingsFrom:(PseudoTerminal*)other;
- (void)fitTabsToWindow;
- (BOOL)showCloseWindow;
- (void)_loadFindStringFromSharedPasteboard;
- (NSSize)windowDecorationSize;
- (void)hideFullScreenTabControl;
- (NSRect)maxFrame;
- (void)_drawFullScreenBlackBackground;
- (void)insertTab:(PTYTab*)aTab atIndex:(int)anIndex;
- (BOOL)_haveBottomBorder;
- (BOOL)_haveTopBorder;
- (float)maxCharHeight:(int*)numChars;
- (float)maxCharWidth:(int*)numChars;
- (void)assignUniqueNumberToWindow;
- (void)safelySetSessionSize:(PTYSession*)aSession
rows:(int)rows
columns:(int)columns;
- (void)setInstantReplayBarVisible:(BOOL)visible;
- (void)adjustFullScreenWindowForBottomBarChange;
- (void)fitTabToWindow:(PTYTab*)aTab;
- (void)setupSession:(PTYSession *)aSession
title:(NSString *)title
withSize:(NSSize*)size;
- (long long)timestampForFraction:(float)f;
- (PTYSession*)newSessionWithBookmark:(Profile*)bookmark;
- (void)runCommandInSession:(PTYSession*)aSession
inCwd:(NSString*)oldCWD
forObjectType:(iTermObjectType)objectType;
- (void)_refreshTerminal:(NSNotification *)aNotification;

@end

@implementation BottomBarView
- (void)drawRect:(NSRect)dirtyRect
{
[[NSColor controlColor] setFill];
NSRectFill(dirtyRect);

// Draw a black line at the top of the view.
[[NSColor blackColor] setFill];
NSRect r = [self frame];
NSRectFill(NSMakeRect(0, r.size.height - 1, r.size.width, 1));
}

@end
@implementation PseudoTerminal

- (id)init {
Expand Down Expand Up @@ -479,6 +417,53 @@ - (void)finishInitializationWithSmartLayout:(BOOL)smartLayout
terminalGuid_ = [[NSString stringWithFormat:@"pty-%@", [ProfileModel freshGuid]] retain];
}

- (void)dealloc
{
doNotSetRestorableState_ = YES;
wellFormed_ = NO;
[toolbelt_ shutdown];
[drawer_ release];

// Do not assume that [self window] is valid here. It may have been freed.
[[NSNotificationCenter defaultCenter] removeObserver:self];

// Cancel any SessionView timers.
for (PTYSession* aSession in [self sessions]) {
[[aSession view] cancelTimers];
}

// Release all our sessions
NSTabViewItem *aTabViewItem;
for (; [TABVIEW numberOfTabViewItems]; ) {
aTabViewItem = [TABVIEW tabViewItemAtIndex:0];
[[aTabViewItem identifier] terminateAllSessions];
PTYTab* theTab = [aTabViewItem identifier];
[theTab setParentWindow:nil];
[TABVIEW removeTabViewItem:aTabViewItem];
}

if ([[iTermController sharedInstance] currentTerminal] == self) {
NSLog(@"Red alert! Current terminal is being freed!");
[[iTermController sharedInstance] setCurrentTerminal:nil];
}
[broadcastViewIds_ release];
[commandField release];
[bottomBar release];
[_toolbarController release];
[autocompleteView shutdown];
[pbHistoryView shutdown];
[pbHistoryView release];
[autocompleteView release];
[tabBarControl release];
[terminalGuid_ release];
if (fullScreenTabviewTimer_) {
[fullScreenTabviewTimer_ invalidate];
}
[lastArrangement_ release];
[_divisionView release];
[super dealloc];
}

- (void)updateDivisionView {
// The division is only shown if there is a title bar and no tab bar. There
// are cases in fullscreen (e.g., when entering Lion fullscreen) when the
Expand Down Expand Up @@ -1048,52 +1033,6 @@ - (PTYSession *)currentSession
return [[[TABVIEW selectedTabViewItem] identifier] activeSession];
}

- (void)dealloc
{
doNotSetRestorableState_ = YES;
wellFormed_ = NO;
[toolbelt_ shutdown];
[drawer_ release];

// Do not assume that [self window] is valid here. It may have been freed.
[[NSNotificationCenter defaultCenter] removeObserver:self];

// Cancel any SessionView timers.
for (PTYSession* aSession in [self sessions]) {
[[aSession view] cancelTimers];
}

// Release all our sessions
NSTabViewItem *aTabViewItem;
for (; [TABVIEW numberOfTabViewItems]; ) {
aTabViewItem = [TABVIEW tabViewItemAtIndex:0];
[[aTabViewItem identifier] terminateAllSessions];
PTYTab* theTab = [aTabViewItem identifier];
[theTab setParentWindow:nil];
[TABVIEW removeTabViewItem:aTabViewItem];
}

if ([[iTermController sharedInstance] currentTerminal] == self) {
NSLog(@"Red alert! Current terminal is being freed!");
[[iTermController sharedInstance] setCurrentTerminal:nil];
}
[broadcastViewIds_ release];
[commandField release];
[bottomBar release];
[_toolbarController release];
[autocompleteView shutdown];
[pbHistoryView shutdown];
[pbHistoryView release];
[autocompleteView release];
[tabBarControl release];
[terminalGuid_ release];
if (fullScreenTabviewTimer_) {
[fullScreenTabviewTimer_ invalidate];
}
[lastArrangement_ release];
[_divisionView release];
[super dealloc];
}

- (void)setWindowTitle
{
Expand Down
1 change: 0 additions & 1 deletion SCPFile.m
Expand Up @@ -432,7 +432,6 @@ - (void)stop {
- (BOOL)session:(NMSSHSession *)session shouldConnectToHostWithFingerprint:(NSString *)fingerprint {
__block BOOL result;
dispatch_sync(dispatch_get_main_queue(), ^(void) {
BOOL known;
_okToAdd = NO;
NSString *message;
switch ([self.session knownHostStatus]) {
Expand Down
2 changes: 0 additions & 2 deletions VT100Screen.m
Expand Up @@ -1544,7 +1544,6 @@ - (id)objectOnOrBeforeLine:(int)line ofClass:(Class)cls {
line)].limit;
NSEnumerator *enumerator = [intervalTree_ reverseLimitEnumeratorAt:pos];
NSArray *objects;
int count;
do {
objects = [enumerator nextObject];
objects = [objects objectsOfClasses:@[ cls ]];
Expand Down Expand Up @@ -1725,7 +1724,6 @@ - (NSArray *)firstMarksOrNotes {
- (NSArray *)marksOrNotesBefore:(Interval *)location {
NSEnumerator *enumerator = [intervalTree_ reverseLimitEnumeratorAt:location.limit];
NSArray *objects;
int count;
do {
objects = [enumerator nextObject];
objects = [objects objectsOfClasses:@[ [PTYNoteViewController class],
Expand Down
10 changes: 10 additions & 0 deletions iTerm.xcodeproj/project.pbxproj
Expand Up @@ -631,6 +631,9 @@
A68A3105186D2973007F550F /* TemporaryNumberAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = A68A3103186D2973007F550F /* TemporaryNumberAllocator.h */; };
A68A3106186D2973007F550F /* TemporaryNumberAllocator.m in Sources */ = {isa = PBXBuildFile; fileRef = A68A3104186D2973007F550F /* TemporaryNumberAllocator.m */; };
A68A3107186D2973007F550F /* TemporaryNumberAllocator.m in Sources */ = {isa = PBXBuildFile; fileRef = A68A3104186D2973007F550F /* TemporaryNumberAllocator.m */; };
A68A310A186D2BCF007F550F /* BottomBarView.h in Headers */ = {isa = PBXBuildFile; fileRef = A68A3108186D2BCF007F550F /* BottomBarView.h */; };
A68A310B186D2BCF007F550F /* BottomBarView.m in Sources */ = {isa = PBXBuildFile; fileRef = A68A3109186D2BCF007F550F /* BottomBarView.m */; };
A68A310C186D2BCF007F550F /* BottomBarView.m in Sources */ = {isa = PBXBuildFile; fileRef = A68A3109186D2BCF007F550F /* BottomBarView.m */; };
A693395C1851A61D00EBEA20 /* VT100ScreenMark.h in Headers */ = {isa = PBXBuildFile; fileRef = A693395A1851A61D00EBEA20 /* VT100ScreenMark.h */; };
A693395D1851A61D00EBEA20 /* VT100ScreenMark.m in Sources */ = {isa = PBXBuildFile; fileRef = A693395B1851A61D00EBEA20 /* VT100ScreenMark.m */; };
A693395E1851A61D00EBEA20 /* VT100ScreenMark.m in Sources */ = {isa = PBXBuildFile; fileRef = A693395B1851A61D00EBEA20 /* VT100ScreenMark.m */; };
Expand Down Expand Up @@ -1070,6 +1073,8 @@
A68A30FE186D151E007F550F /* NMSSH.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = NMSSH.framework; sourceTree = "<group>"; };
A68A3103186D2973007F550F /* TemporaryNumberAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TemporaryNumberAllocator.h; sourceTree = "<group>"; };
A68A3104186D2973007F550F /* TemporaryNumberAllocator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TemporaryNumberAllocator.m; sourceTree = "<group>"; };
A68A3108186D2BCF007F550F /* BottomBarView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BottomBarView.h; sourceTree = "<group>"; };
A68A3109186D2BCF007F550F /* BottomBarView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BottomBarView.m; sourceTree = "<group>"; };
A693395A1851A61D00EBEA20 /* VT100ScreenMark.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VT100ScreenMark.h; sourceTree = "<group>"; };
A693395B1851A61D00EBEA20 /* VT100ScreenMark.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VT100ScreenMark.m; sourceTree = "<group>"; };
A6C4E8DC1846E13800CFAA77 /* IntervalTree.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IntervalTree.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1289,6 +1294,7 @@
0464AB15006CD2EC7F000001 /* Headers */ = {
isa = PBXGroup;
children = (
A68A3108186D2BCF007F550F /* BottomBarView.h */,
A68A3103186D2973007F550F /* TemporaryNumberAllocator.h */,
A68A30EA186D150A007F550F /* FileTransferManager.h */,
A68A30EB186D150A007F550F /* NSArray+iTerm.h */,
Expand Down Expand Up @@ -1832,6 +1838,7 @@
children = (
A6CFDAD6185D53C2005DC94B /* AsyncHostLookupController.m */,
1DA26ABF15007507004B5792 /* BackgroundThread.m */,
A68A3109186D2BCF007F550F /* BottomBarView.m */,
A073973F14C7694600786414 /* ColorsMenuItemView.m */,
1D53FD14181C4B4B00524D4F /* FindContext.m */,
A68A30C0186D0DC1007F550F /* FindCursorView.m */,
Expand Down Expand Up @@ -2100,6 +2107,7 @@
1D9DCBFE142D7BA60016228A /* Trigger.h in Headers */,
1D9DCC04142D7E570016228A /* GrowlTrigger.h in Headers */,
1D9DCC0A142D7F300016228A /* BounceTrigger.h in Headers */,
A68A310A186D2BCF007F550F /* BottomBarView.h in Headers */,
1D9DCC0E142D7F5F0016228A /* BellTrigger.h in Headers */,
A68A30FD186D150B007F550F /* VT100WorkingDirectory.h in Headers */,
1D9DCC12142D7F970016228A /* ScriptTrigger.h in Headers */,
Expand Down Expand Up @@ -2455,6 +2463,7 @@
1D9A5551180FA82E00B42CE9 /* TSVParser.m in Sources */,
1D9A559B180FA87000B42CE9 /* RoundedRectView.m in Sources */,
1D9A5573180FA85D00B42CE9 /* Trigger.m in Sources */,
A68A310C186D2BCF007F550F /* BottomBarView.m in Sources */,
A68A30E1186D1429007F550F /* TransferrableFile.m in Sources */,
1D9A554F180FA82E00B42CE9 /* TmuxWindowOpener.m in Sources */,
1D9A5535180FA78B00B42CE9 /* DVRBuffer.m in Sources */,
Expand Down Expand Up @@ -2593,6 +2602,7 @@
1D5FDDA91208E93600C46BA3 /* VT100Screen.m in Sources */,
1D5FDDAA1208E93600C46BA3 /* VT100Terminal.m in Sources */,
1D5FDDAB1208E93600C46BA3 /* iTermController.m in Sources */,
A68A310B186D2BCF007F550F /* BottomBarView.m in Sources */,
A63F40AA183F3CED003A6A6D /* LineBufferHelpers.m in Sources */,
1D5FDDAC1208E93600C46BA3 /* NSStringITerm.m in Sources */,
1D5FDDAD1208E93600C46BA3 /* PreferencePanel.m in Sources */,
Expand Down

0 comments on commit 3340ffc

Please sign in to comment.