Skip to content

Commit

Permalink
Add support for advanced paste to pointer prefs. Issue 6990
Browse files Browse the repository at this point in the history
  • Loading branch information
gnachman committed Feb 22, 2019
1 parent 07bf634 commit 0e4a91e
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 17 deletions.
12 changes: 9 additions & 3 deletions Interfaces/PreferencePanel.xib
Expand Up @@ -91,6 +91,7 @@
</customObject>
<customObject id="6117" customClass="PointerPrefsController">
<connections>
<outlet property="_pasteSpecialViewContainer" destination="XBQ-x3-51h" id="JaH-7U-Bch"/>
<outlet property="actionColumn_" destination="6099" id="6123"/>
<outlet property="buttonColumn_" destination="6095" id="6121"/>
<outlet property="editActionLabel_" destination="6160" id="6171"/>
Expand Down Expand Up @@ -293,7 +294,7 @@
</button>
<button verticalHuggingPriority="750" id="6181">
<rect key="frame" x="354" y="12" width="82" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="push" title="OK" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="6182">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -307,7 +308,7 @@ DQ
</button>
<button verticalHuggingPriority="750" id="6183">
<rect key="frame" x="272" y="12" width="82" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="6184">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand Down Expand Up @@ -365,9 +366,14 @@ Gw
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<customView hidden="YES" id="XBQ-x3-51h">
<rect key="frame" x="130" y="60" width="300" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</customView>
</subviews>
</view>
<accessibility identifier="editPointerSettingsPanel"/>
<point key="canvasLocation" x="317.5" y="-419"/>
</window>
<window title="Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="1923" userLabel="Main Preferences Window" customClass="iTermPrefsPanel">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
Expand Down Expand Up @@ -6037,7 +6043,7 @@ DQ
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<clipView key="contentView" id="2zv-hI-Vxj">
<rect key="frame" x="1" y="0.0" width="849" height="245"/>
<autoresizingMask key="autoresizingMask"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="none" alternatingRowBackgroundColors="YES" columnReordering="NO" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" headerView="6206" id="6091">
<rect key="frame" x="0.0" y="0.0" width="849" height="228"/>
Expand Down
7 changes: 7 additions & 0 deletions sources/PTYSession.m
Expand Up @@ -7393,6 +7393,13 @@ - (void)textViewSelectPreviousPane
[_delegate previousSession];
}

- (void)textViewPasteSpecialWithStringConfiguration:(NSString *)configuration
fromSelection:(BOOL)fromSelection {
NSString *string = fromSelection ? [[iTermController sharedInstance] lastSelection] : [NSString stringFromPasteboard];
[_pasteHelper pasteString:string
stringConfig:configuration];
}

- (void)textViewEditSession {
[[_delegate realParentWindow] editSession:self makeKey:YES];
}
Expand Down
2 changes: 2 additions & 0 deletions sources/PTYTextView.h
Expand Up @@ -128,6 +128,8 @@ typedef NS_ENUM(NSInteger, PTYTextViewSelectionExtensionUnit) {
- (void)textViewCreateTabWithProfileGuid:(NSString *)guid;
- (void)textViewSelectNextPane;
- (void)textViewSelectPreviousPane;
- (void)textViewPasteSpecialWithStringConfiguration:(NSString *)configuration
fromSelection:(BOOL)fromSelection;
- (void)textViewEditSession;
- (void)textViewToggleBroadcastingInput;
- (void)textViewCloseWithConfirmation;
Expand Down
7 changes: 7 additions & 0 deletions sources/PTYTextView.m
Expand Up @@ -2835,6 +2835,13 @@ - (void)selectPreviousPaneWithEvent:(NSEvent *)event
[_delegate textViewSelectPreviousPane];
}

- (void)advancedPasteWithConfiguration:(NSString *)configuration
fromSelection:(BOOL)fromSelection
withEvent:(NSEvent *)event {
[self.delegate textViewPasteSpecialWithStringConfiguration:configuration
fromSelection:fromSelection];
}

- (VT100GridCoord)moveCursorHorizontallyTo:(VT100GridCoord)target from:(VT100GridCoord)cursor {
DLog(@"Moving cursor horizontally from %@ to %@",
VT100GridCoordDescription(cursor), VT100GridCoordDescription(target));
Expand Down
4 changes: 3 additions & 1 deletion sources/PointerController.h
Expand Up @@ -37,7 +37,9 @@
- (void)selectPreviousPaneWithEvent:(NSEvent *)event;
- (void)extendSelectionWithEvent:(NSEvent *)event;
- (void)quickLookWithEvent:(NSEvent *)event;

- (void)advancedPasteWithConfiguration:(NSString *)configuration
fromSelection:(BOOL)fromSelection
withEvent:(NSEvent *)event;
@end

@interface PointerController : NSObject
Expand Down
12 changes: 10 additions & 2 deletions sources/PointerController.m
Expand Up @@ -31,9 +31,17 @@ - (void)performAction:(NSString *)action
{
DLog(@"Perform action %@", action);
if ([action isEqualToString:kPasteFromClipboardPointerAction]) {
[delegate_ pasteFromClipboardWithEvent:event];
if (argument.length) {
[delegate_ advancedPasteWithConfiguration:argument fromSelection:NO withEvent:event];
} else {
[delegate_ pasteFromClipboardWithEvent:event];
}
} else if ([action isEqualToString:kPasteFromSelectionPointerAction]) {
[delegate_ pasteFromSelectionWithEvent:event];
if (argument.length) {
[delegate_ advancedPasteWithConfiguration:argument fromSelection:YES withEvent:event];
} else {
[delegate_ pasteFromSelectionWithEvent:event];
}
} else if ([action isEqualToString:kOpenTargetPointerAction]) {
[delegate_ openTargetWithEvent:event];
} else if ([action isEqualToString:kSmartSelectionPointerAction]) {
Expand Down
93 changes: 82 additions & 11 deletions sources/PointerPrefsController.m
Expand Up @@ -11,6 +11,7 @@
#import "PreferencePanel.h"
#import "NSPopUpButton+iTerm.h"
#import "iTermApplicationDelegate.h"
#import "iTermPasteSpecialViewController.h"
#import "ITAddressBookMgr.h"
#import "FutureMethods.h"
#import "NSTextField+iTerm.h"
Expand Down Expand Up @@ -79,7 +80,8 @@
kEscPlusArg,
kHexCodeArg,
kTextArg,
kProfileArg
kProfileArg,
kAdvancedPasteArg
} ArgumentType;

@interface NSString (PointerPrefsController)
Expand Down Expand Up @@ -144,6 +146,10 @@ @implementation PointerPrefsController {

IBOutlet NSButton *ok_;
IBOutlet NSButton *remove_;
iTermPasteSpecialViewController *_pasteSpecialViewController;
IBOutlet NSView *_pasteSpecialViewContainer;
NSRect _initialFrame;
NSRect _initialPasteContainerFrame;

NSString *origKey_;
}
Expand Down Expand Up @@ -384,8 +390,8 @@ + (NSString *)localizedModifiers:(int)keyMods {
+ (NSDictionary *)localizedActionMap
{
NSDictionary *names = [NSDictionary dictionaryWithObjectsAndKeys:
@"Paste from Clipboard", kPasteFromClipboardPointerAction,
@"Paste from Selection", kPasteFromSelectionPointerAction,
@"Paste from Clipboard", kPasteFromClipboardPointerAction,
@"Paste from Selection", kPasteFromSelectionPointerAction,
@"Extend Selection", kExtendSelectionPointerAction,
@"Open URL/Semantic History", kOpenTargetPointerAction,
@"Open URL in background", kOpenTargetInBackgroundPointerAction,
Expand Down Expand Up @@ -419,13 +425,15 @@ + (NSDictionary *)localizedActionMap
+ (ArgumentType)argumentTypeForAction:(NSString *)action
{
NSDictionary *args = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kEscPlusArg], kSendEscapeSequencePointerAction,
[NSNumber numberWithInt:kHexCodeArg], kSendHexCodePointerAction,
[NSNumber numberWithInt:kTextArg], kSendTextPointerAction,
[NSNumber numberWithInt:kProfileArg], kNewWindowWithProfilePointerAction,
[NSNumber numberWithInt:kProfileArg], kNewTabWithProfilePointerAction,
[NSNumber numberWithInt:kProfileArg], kNewVerticalSplitWithProfilePointerAction,
[NSNumber numberWithInt:kProfileArg], kNewHorizontalSplitWithProfilePointerAction,
@(kEscPlusArg), kSendEscapeSequencePointerAction,
@(kHexCodeArg), kSendHexCodePointerAction,
@(kTextArg), kSendTextPointerAction,
@(kProfileArg), kNewWindowWithProfilePointerAction,
@(kProfileArg), kNewTabWithProfilePointerAction,
@(kProfileArg), kNewVerticalSplitWithProfilePointerAction,
@(kProfileArg), kNewHorizontalSplitWithProfilePointerAction,
@(kAdvancedPasteArg), kPasteFromClipboardPointerAction,
@(kAdvancedPasteArg), kPasteFromSelectionPointerAction,
nil];
NSNumber *n = [args objectForKey:action];
if (n) {
Expand Down Expand Up @@ -480,6 +488,13 @@ + (NSString *)formattedLocalizedActionForDict:(NSDictionary *)dict
return [name stringByReplacingOccurrencesOfString:@""
withString:[NSString stringWithFormat:@" \"%@\"", bookmarkName]];
}
case kAdvancedPasteArg: {
if (argument.length) {
name = [NSString stringWithFormat:@"%@: %@",
[name stringByReplacingOccurrencesOfString:@"" withString:@""],
[iTermPasteSpecialViewController descriptionForCodedSettings:argument]];
}
}
}
}

Expand Down Expand Up @@ -800,6 +815,10 @@ + (NSString *)argumentForKey:(NSString *)key {

- (void)updateArgumentFieldsForAction:(NSString *)actionIdent argument:(NSString *)currentArg
{
if (NSEqualRects(NSZeroRect, _initialFrame)) {
_initialFrame = _pasteSpecialViewContainer.window.frame;
_initialPasteContainerFrame = _pasteSpecialViewContainer.frame;
}
ArgumentType argType = kNoArg;
if (actionIdent) {
argType = [PointerPrefsController argumentTypeForAction:actionIdent];
Expand All @@ -809,6 +828,7 @@ - (void)updateArgumentFieldsForAction:(NSString *)actionIdent argument:(NSString
[editArgumentLabel_ setHidden:YES];
[editArgumentField_ setHidden:YES];
[editArgumentButton_ setHidden:YES];
_pasteSpecialViewContainer.hidden = YES;
break;

case kEscPlusArg:
Expand All @@ -821,6 +841,7 @@ - (void)updateArgumentFieldsForAction:(NSString *)actionIdent argument:(NSString
[editArgumentField_ setStringValue:currentArg];
[editArgumentField_ setRefusesFirstResponder:NO];
[editArgumentField_ setSelectable:YES];
_pasteSpecialViewContainer.hidden = YES;
break;

case kHexCodeArg:
Expand All @@ -831,6 +852,7 @@ - (void)updateArgumentFieldsForAction:(NSString *)actionIdent argument:(NSString
[editArgumentLabel_ setStringValue:@"Hex codes:"];
[[editArgumentField_ cell] setPlaceholderString:@"ex: 0x7f 0x20"];
[editArgumentField_ setStringValue:currentArg];
_pasteSpecialViewContainer.hidden = YES;
break;

case kTextArg:
Expand All @@ -841,6 +863,7 @@ - (void)updateArgumentFieldsForAction:(NSString *)actionIdent argument:(NSString
[editArgumentLabel_ setStringValue:@"Text:"];
[[editArgumentField_ cell] setPlaceholderString:@"Enter value to send"];
[editArgumentField_ setStringValue:currentArg];
_pasteSpecialViewContainer.hidden = YES;
break;

case kProfileArg:
Expand All @@ -849,10 +872,18 @@ - (void)updateArgumentFieldsForAction:(NSString *)actionIdent argument:(NSString
[editArgumentButton_ setHidden:NO];
[editArgumentLabel_ setStringValue:@"Profile:"];
[editArgumentButton_ populateWithProfilesSelectingGuid:currentArg];

_pasteSpecialViewContainer.hidden = YES;
break;

case kAdvancedPasteArg:
editArgumentLabel_.hidden = YES;
editArgumentField_.hidden = YES;
editArgumentButton_.hidden = YES;
_pasteSpecialViewContainer.hidden = NO;
[self configurePasteSpecialWithArgument:currentArg];
break;
}
[self updateWindowFrame];
}

- (void)loadKeyIntoEditPane:(NSString *)key
Expand Down Expand Up @@ -980,6 +1011,11 @@ - (IBAction)ok:(id)sender {
[newValue setObject:[[editArgumentButton_ selectedItem] title]
forKey:kArgumentKey];
}
} else if (!_pasteSpecialViewContainer.isHidden) {
if ([PointerPrefsController argumentTypeForAction:theAction] == kAdvancedPasteArg) {
[newValue setObject:[_pasteSpecialViewController stringEncodedSettings] ?: @""
forKey:kArgumentKey];
}
}
NSString *newKey;
int modMask = 0;
Expand Down Expand Up @@ -1052,6 +1088,41 @@ - (IBAction)loadDefaults:(id)sender
[tableView_ reloadData];
}

- (void)configurePasteSpecialWithArgument:(NSString *)parameterValue {
_pasteSpecialViewController = [[iTermPasteSpecialViewController alloc] init];
[_pasteSpecialViewController view];

// Set a few defaults; otherwise everything is reasonable.
_pasteSpecialViewController.numberOfSpacesPerTab = [iTermPreferences intForKey:kPreferenceKeyPasteSpecialSpacesPerTab];
_pasteSpecialViewController.shouldRemoveNewlines = NO;
_pasteSpecialViewController.shouldBase64Encode = NO;
_pasteSpecialViewController.shouldWaitForPrompt = NO;
_pasteSpecialViewController.shouldEscapeShellCharsWithBackslash = NO;
if (parameterValue.length > 0) {
[_pasteSpecialViewController loadSettingsFromString:parameterValue];
}
_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];
}

- (void)updateWindowFrame {
NSRect frame;
if (_pasteSpecialViewContainer.isHidden) {
frame = _initialFrame;
} else {
frame = _initialFrame;
NSSize desiredSize = _pasteSpecialViewController.view.frame.size;
frame.size.width += desiredSize.width - _initialPasteContainerFrame.size.width;
frame.size.height += desiredSize.height - _initialPasteContainerFrame.size.height;
}
[_pasteSpecialViewContainer.window setFrame:frame display:YES animate:YES];
}

@end

@implementation NSString (PointerPrefsController)
Expand Down

0 comments on commit 0e4a91e

Please sign in to comment.