Skip to content
Snippets Groups Projects
Commit 531896a3 authored by George Nachman's avatar George Nachman
Browse files

Add base conversion to context menu

parent db2a5627
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -3261,6 +3261,11 @@ static double EuclideanDistance(NSPoint p1, NSPoint p2) {
return NO;
}
 
- (BOOL)_haveShortSelection
{
return startX > -1 && abs(startY - endY) <= 1;
}
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
{
PTYTextView* frontTextView = [[iTermController sharedInstance] frontTextView];
Loading
Loading
@@ -3288,6 +3293,32 @@ static double EuclideanDistance(NSPoint p1, NSPoint p2) {
// Allocate a menu
theMenu = [[NSMenu alloc] initWithTitle:@"Contextual Menu"];
 
if ([self _haveShortSelection]) {
NSString *text = [self selectedText];
if ([text intValue]) {
[theMenu addItemWithTitle:[NSString stringWithFormat:@"%d = 0x%x", [text intValue], [text intValue]]
action:@selector(bogusSelector)
keyEquivalent:@""];
} else if ([text hasPrefix:@"0x"] && [text length] <= 10) {
NSScanner *scanner = [NSScanner scannerWithString:text];
[scanner setScanLocation:2]; // bypass 0x
unsigned result;
if ([scanner scanHexInt:&result]) {
if ((int)result >= 0) {
[theMenu addItemWithTitle:[NSString stringWithFormat:@"0x%x = %d", result, result]
action:@selector(bogusSelector)
keyEquivalent:@""];
} else {
[theMenu addItemWithTitle:[NSString stringWithFormat:@"0x%x = %d or %u", result, result, result]
action:@selector(bogusSelector)
keyEquivalent:@""];
}
}
}
[theMenu addItem:[NSMenuItem separatorItem]];
}
// Menu items for acting on text selections
[theMenu addItemWithTitle:NSLocalizedStringFromTableInBundle(@"Open Selection as URL",@"iTerm", [NSBundle bundleForClass: [self class]], @"Context menu")
action:@selector(browse:) keyEquivalent:@""];
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment