Skip to content

Commit

Permalink
Add option to wait for prompt to advanced paste. Fix animation of edi…
Browse files Browse the repository at this point in the history
…t key bindings window and clean up the code a bit.
  • Loading branch information
gnachman committed May 31, 2015
1 parent 4a2217c commit dc6d204
Show file tree
Hide file tree
Showing 14 changed files with 288 additions and 76 deletions.
6 changes: 3 additions & 3 deletions Interfaces/iTermEditKeyActionWindowController.xib
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6254" systemVersion="14C109" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7531" systemVersion="14D131" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6254"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7531"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="iTermEditKeyActionWindowController">
Expand All @@ -27,7 +27,7 @@
<rect key="contentRect" x="196" y="240" width="442" height="157"/>
<rect key="screenRect" x="0.0" y="0.0" width="1280" height="777"/>
<view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="442" height="157"/>
<rect key="frame" x="0.0" y="0" width="442" height="157"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view id="bKI-jb-USm">
Expand Down
73 changes: 46 additions & 27 deletions Interfaces/iTermPasteSpecialViewController.xib

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions Interfaces/iTermPasteSpecialWindow.xib
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7531" systemVersion="14C109" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7531" systemVersion="14D131" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7531"/>
</dependencies>
Expand All @@ -19,10 +19,10 @@
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" hidesOnDeactivate="YES" oneShot="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="QvC-M9-y7g">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="401" y="97" width="501" height="507"/>
<rect key="contentRect" x="401" y="97" width="501" height="542"/>
<rect key="screenRect" x="0.0" y="0.0" width="1280" height="777"/>
<view key="contentView" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="501" height="507"/>
<rect key="frame" x="0.0" y="5" width="501" height="542"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button verticalHuggingPriority="750" id="S2m-j3-AMJ">
Expand Down Expand Up @@ -54,7 +54,7 @@ Gw
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="TNo-3d-Gpd">
<rect key="frame" x="18" y="327" width="465" height="17"/>
<rect key="frame" x="18" y="362" width="465" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="xxx lines, xxx bytes." id="g9t-TC-J5B">
<font key="font" metaFont="system"/>
Expand All @@ -63,7 +63,7 @@ Gw
</textFieldCell>
</textField>
<scrollView horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" id="Ddv-Cd-cjo">
<rect key="frame" x="20" y="352" width="461" height="110"/>
<rect key="frame" x="20" y="387" width="461" height="110"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<clipView key="contentView" id="kWm-ga-g2X">
<rect key="frame" x="1" y="1" width="459" height="133"/>
Expand All @@ -76,6 +76,8 @@ Gw
<size key="minSize" width="459" height="108"/>
<size key="maxSize" width="10000000" height="10000000"/>
<color key="insertionPointColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="459" height="108"/>
<size key="maxSize" width="10000000" height="10000000"/>
</textView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
Expand All @@ -90,7 +92,7 @@ Gw
</scroller>
</scrollView>
<popUpButton verticalHuggingPriority="750" id="vVV-1I-dAt">
<rect key="frame" x="18" y="464" width="466" height="26"/>
<rect key="frame" x="18" y="499" width="466" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="ySh-W6-Jba">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
Expand Down Expand Up @@ -120,12 +122,12 @@ Gw
</textFieldCell>
</textField>
<customView id="rnF-BN-LAy" userLabel="iTermPasteSpecialView Container">
<rect key="frame" x="20" y="61" width="444" height="248"/>
<rect key="frame" x="20" y="40" width="444" height="304"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</customView>
</subviews>
</view>
<point key="canvasLocation" x="329.5" y="305.5"/>
<point key="canvasLocation" x="329.5" y="323"/>
</window>
</objects>
</document>
7 changes: 7 additions & 0 deletions sources/PTYSession.m
Expand Up @@ -4678,6 +4678,7 @@ - (void)pasteString:(NSString *)theString flags:(PTYSessionPasteFlags)flags {
[_pasteHelper pasteString:theString
slowly:!!(flags & kPTYSessionPasteSlowly)
escapeShellChars:!!(flags & kPTYSessionPasteEscapingSpecialCharacters)
commands:NO
tabTransform:tabTransform
spacesPerTab:spacesPerTab];
}
Expand Down Expand Up @@ -4936,6 +4937,7 @@ - (void)textViewPasteFileWithBase64Encoding {
[_pasteHelper pasteString:[data stringWithBase64EncodingWithLineBreak:@"\r"]
slowly:NO
escapeShellChars:NO
commands:NO
tabTransform:kTabTransformNone
spacesPerTab:0];
}
Expand Down Expand Up @@ -5767,6 +5769,7 @@ - (void)screenPromptDidStartAtLine:(int)line {
_lastPromptLine = (long long)line + [_screen totalScrollbackOverflow];
DLog(@"FinalTerm: prompt started on line %d. Add a mark there. Save it as lastPromptLine.", line);
[[self screenAddMarkOnLine:line] setIsPrompt:YES];
[_pasteHelper unblock];
}

- (VT100ScreenMark *)screenAddMarkOnLine:(int)line {
Expand Down Expand Up @@ -6577,4 +6580,8 @@ - (BOOL)pasteHelperIsAtShellPrompt {
return !_shellIntegrationEverUsed || [self currentCommand] != nil;
}

- (BOOL)pasteHelperCanWaitForPrompt {
return _shellIntegrationEverUsed;
}

@end
10 changes: 4 additions & 6 deletions sources/PasteContext.h
Expand Up @@ -8,18 +8,16 @@

#import <Foundation/Foundation.h>

@interface PasteContext : NSObject {
NSString *bytesPerCallKey_;
int bytesPerCall_;
NSString *delayBetweenCallsKey_;
float delayBetweenCalls_;
}
@interface PasteContext : NSObject

- (id)initWithBytesPerCallPrefKey:(NSString*)bytesPerCallKey
defaultValue:(int)bytesPerCallDefault
delayBetweenCallsPrefKey:(NSString*)delayBetweenCallsKey
defaultValue:(float)delayBetweenCallsDefault;

@property(nonatomic, assign) BOOL blockAtNewline;
@property(nonatomic, assign) BOOL isBlocked;

- (int)bytesPerCall;
- (void)setBytesPerCall:(int)newBytesPerCall;
- (float)delayBetweenCalls;
Expand Down
7 changes: 6 additions & 1 deletion sources/PasteContext.m
Expand Up @@ -9,7 +9,12 @@
#import "PasteContext.h"
#import "iTermAdvancedSettingsModel.h"

@implementation PasteContext
@implementation PasteContext {
NSString *bytesPerCallKey_;
int bytesPerCall_;
NSString *delayBetweenCallsKey_;
float delayBetweenCalls_;
}

- (id)initWithBytesPerCallPrefKey:(NSString*)bytesPerCallKey
defaultValue:(int)bytesPerCallDefault
Expand Down
3 changes: 3 additions & 0 deletions sources/PasteEvent.h
Expand Up @@ -35,6 +35,9 @@ typedef NS_OPTIONS(NSUInteger, iTermPasteFlags) {

// Only used by key actions and paste special
kPasteFlagsBase64Encode = (1 << 6),

// Wait for prompt before each line
kPasteFlagsCommands = (1 << 7)
};

@interface PasteEvent : NSEvent
Expand Down
91 changes: 79 additions & 12 deletions sources/iTermEditKeyActionWindowController.m
Expand Up @@ -66,27 +66,33 @@ - (void)windowDidLoad
[_menuToSelectPopup selectItemWithTitle:self.parameterValue];
}

[self updateViews];
_pasteSpecialViewController = [[iTermPasteSpecialViewController alloc] init];
[_pasteSpecialViewController view];

[self updateViewsAnimated:NO];
if (!_profilePopup.isHidden) {
[_profilePopup populateWithProfilesSelectingGuid:self.parameterValue];
}
if (!_colorPresetsPopup.isHidden) {
[_colorPresetsPopup loadColorPresetsSelecting:self.parameterValue];
}

_pasteSpecialViewController = [[iTermPasteSpecialViewController alloc] init];
[_pasteSpecialViewController view];

if (self.action == KEY_ACTION_PASTE_SPECIAL ||
self.action == KEY_ACTION_PASTE_SPECIAL_FROM_SELECTION) {
[_pasteSpecialViewController loadSettingsFromString:self.parameterValue];
} else {
// Set a few defaults; otherwise everything is reasonable.
_pasteSpecialViewController.numberOfSpacesPerTab = [iTermPreferences intForKey:kPreferenceKeyPasteSpecialSpacesPerTab];
_pasteSpecialViewController.shouldBase64Encode = NO;
_pasteSpecialViewController.shouldWaitForPrompt = NO;
_pasteSpecialViewController.shouldEscapeShellCharsWithBackslash = NO;
}
_pasteSpecialViewController.view.frame = _pasteSpecialViewController.view.bounds;
NSRect theFrame = _pasteSpecialViewContainer.frame;
CGFloat originalHeight = theFrame.size.height;
theFrame.size = _pasteSpecialViewController.view.bounds.size;
theFrame.origin.y -= (theFrame.size.height - originalHeight);
_pasteSpecialViewContainer.frame = theFrame;
[_pasteSpecialViewContainer addSubview:_pasteSpecialViewController.view];
}

Expand Down Expand Up @@ -130,7 +136,7 @@ - (void)shortcutInputView:(iTermShortcutInputView *)view didReceiveKeyPressEvent

#pragma mark - Private

- (void)updateViews {
- (void)updateViewsAnimated:(BOOL)animated {
int tag = [[_actionPopup selectedItem] tag];
switch (tag) {
case KEY_ACTION_HEX_CODE:
Expand Down Expand Up @@ -282,17 +288,78 @@ - (void)updateViews {
[self setPasteSpecialHidden:YES];
break;
}

[self updateFrameAnimated:animated];
}

- (void)setPasteSpecialHidden:(BOOL)hidden {
_pasteSpecialViewContainer.hidden = hidden;
- (BOOL)anyAccessoryVisible {
return (!_parameter.isHidden ||
!_profilePopup.isHidden ||
!_menuToSelectPopup.isHidden ||
!_colorPresetsPopup.isHidden ||
!_pasteSpecialViewContainer.isHidden ||
!_parameterLabel.isHidden);
}

- (void)updateFrameAnimated:(BOOL)animated {
NSRect rect = self.window.frame;
if (hidden) {
rect.size = NSMakeSize(442, 157);
/*
* Side margin Side margin
* | |
* |-| |-|
* +---------------------------------+
* | |
* | Keyboard shortcut: [ ] |
* | Action: [v Popup ] | _
* | Basic Accessory | _|-- Basic accessory height
* | |
* | [Cancel] [OK] |
* +---------------------------------+
* |---------------------------|
* Normal width excluding margins
*
* +---------------------------------+ -
* | | |
* | Keyboard shortcut: [ ] | |
* | Action: [v Popup ] | |-- Height excluding accessory
* | | |
* | [Cancel] [OK] | |
* +---------------------------------+ -
*
*/
const CGFloat heightExcludingAccessory = 126;
const CGFloat sideMarginWidth = 20;
const CGFloat basicAccessoryHeight = 31;
const CGFloat normalWidthExcludingMargins = 402;
if ([self anyAccessoryVisible]) {
if (!_pasteSpecialViewContainer.hidden) {
const CGFloat widthExcludingMargins = MAX(normalWidthExcludingMargins,
_pasteSpecialViewController.view.frame.size.width);
rect.size = NSMakeSize(widthExcludingMargins + sideMarginWidth * 2,
_pasteSpecialViewController.view.frame.size.height + heightExcludingAccessory);
} else {
rect.size = NSMakeSize(normalWidthExcludingMargins + sideMarginWidth * 2,
heightExcludingAccessory + basicAccessoryHeight);
}
} else {
rect.size = NSMakeSize(normalWidthExcludingMargins + sideMarginWidth * 2,
heightExcludingAccessory);
}
if (animated) {
[self retain];
[self.window retain];
dispatch_async(dispatch_get_main_queue(), ^{
[self.window setFrame:rect display:YES animate:YES];
[self autorelease];
[self.window autorelease];
});
} else {
rect.size = NSMakeSize(484, 382);
[self.window setFrame:rect display:YES animate:NO];
}
[self.window setFrame:rect display:YES animate:YES];
}

- (void)setPasteSpecialHidden:(BOOL)hidden {
_pasteSpecialViewContainer.hidden = hidden;
}

+ (void)populatePopUpButtonWithMenuItems:(NSPopUpButton *)button
Expand Down Expand Up @@ -344,7 +411,7 @@ - (IBAction)actionChanged:(id)sender {
[_colorPresetsPopup loadColorPresetsSelecting:_colorPresetsPopup.selectedItem.representedObject];
[[self class] populatePopUpButtonWithMenuItems:_menuToSelectPopup
selectedValue:[[_menuToSelectPopup selectedItem] title]];
[self updateViews];
[self updateViewsAnimated:YES];
}


Expand Down
8 changes: 8 additions & 0 deletions sources/iTermPasteHelper.h
Expand Up @@ -27,6 +27,9 @@

- (BOOL)pasteHelperIsAtShellPrompt;

// Is shell integration installed?
- (BOOL)pasteHelperCanWaitForPrompt;

@end

@interface iTermPasteHelper : NSObject
Expand All @@ -44,6 +47,7 @@
- (void)pasteString:(NSString *)theString
slowly:(BOOL)slowly
escapeShellChars:(BOOL)escapeShellChars
commands:(BOOL)commands
tabTransform:(iTermTabTransformTags)tabTransform
spacesPerTab:(int)spacesPerTab;

Expand All @@ -61,6 +65,10 @@
// Convert tabs to spaces in source, perhaps asking the user questions in modal alerts.
- (int)numberOfSpacesToConvertTabsTo:(NSString *)source;

// Call this when a shell prompt begins. If pasting in "commands" mode this
// allows one more line to be pasted.
- (void)unblock;

#pragma mark - Testing

// This method can be overridden for testing.
Expand Down

0 comments on commit dc6d204

Please sign in to comment.