Skip to content

Commit b558873

Browse files
committed
Enable copy/paste/cut in macOS MSAuth web view
Add a basic application main menu bar, with 'Edit' submenu containing the standard text manipulation commands (cut, copy, paste, select all, delete) to enable these actions in the authentication webview. This is useful for users who use password managers and need to paste into the webview.
1 parent 4fe2f80 commit b558873

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/osx/Microsoft.Authentication.Helper.Mac/Source/Core/AHAppDelegate.m

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33

44
#import "AHAppDelegate.h"
5+
#import <Cocoa/Cocoa.h>
56

67
extern const NSString* kErrorDomain;
78

@@ -21,7 +22,10 @@ -(id)initWithBlock:(AHAppWorkBlock)block logger:(AHLogger*)logger;
2122

2223
-(void)run
2324
{
24-
NSApplication * application = [NSApplication sharedApplication];
25+
NSApplication *application = [NSApplication sharedApplication];
26+
NSMenu *mainMenu = [self createMainMenu];
27+
[application setMainMenu:mainMenu];
28+
2529
[self setApplication:application];
2630
[application setDelegate:self];
2731
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
@@ -57,6 +61,35 @@ -(void) stop
5761
[[self application] postEvent:event atStart:NO];
5862
}
5963

64+
-(NSMenu*) createMainMenu
65+
{
66+
NSMenu *mainMenu = [NSMenu new];
67+
68+
// Create top-level menu items
69+
NSMenuItem *appMenuItem = [NSMenuItem new];
70+
NSMenuItem *editMenuItem = [NSMenuItem new];
71+
[mainMenu addItem:appMenuItem];
72+
[mainMenu addItem:editMenuItem];
73+
74+
// Create app menu items
75+
NSMenu *appMenu = [NSMenu new];
76+
[appMenuItem setSubmenu:appMenu];
77+
[appMenu addItemWithTitle:@"Quit"
78+
action:@selector(terminate:)
79+
keyEquivalent:@"q"];
80+
81+
// Create edit menu items
82+
NSMenu *editMenu = [[NSMenu alloc] initWithTitle:@"Edit"];
83+
[editMenuItem setSubmenu:editMenu];
84+
[editMenu addItemWithTitle:@"Cut" action:@selector(cut:) keyEquivalent:@"x"];
85+
[editMenu addItemWithTitle:@"Copy" action:@selector(copy:) keyEquivalent:@"c"];
86+
[editMenu addItemWithTitle:@"Paste" action:@selector(paste:) keyEquivalent:@"v"];
87+
[editMenu addItemWithTitle:@"Delete" action:@selector(delete:) keyEquivalent:@""];
88+
[editMenu addItemWithTitle:@"Select All" action:@selector(selectAll:) keyEquivalent:@"a"];
89+
90+
return mainMenu;
91+
}
92+
6093
+ (NSError*)runDelegate:(AHAppWorkBlock)completionBlock logger:(AHLogger*)logger
6194
{
6295
AHAppDelegate * delegate = [[AHAppDelegate alloc] initWithBlock:completionBlock logger:logger];

0 commit comments

Comments
 (0)