@@ -207,6 +207,17 @@ def webView_runJavaScriptConfirmPanelWithMessage_initiatedByFrame_completionHand
207207 result = BrowserView .display_confirmation_dialog (ok , cancel , message )
208208 handler (result )
209209
210+ # Display a Javascript input panel
211+ def webView_runJavaScriptTextInputPanelWithPrompt_defaultText_initiatedByFrame_completionHandler_ (
212+ self , webview , prompt , default_text , frame , handler
213+ ):
214+ i = BrowserView .get_instance ('webview' , webview )
215+ ok = i .localization ['global.ok' ]
216+ cancel = i .localization ['global.cancel' ]
217+
218+ result = BrowserView .display_input_dialog (ok , cancel , prompt , default_text )
219+ handler (result )
220+
210221 # Display an open panel for <input type="file"> element
211222 def webView_runOpenPanelWithParameters_initiatedByFrame_completionHandler_ (
212223 self , webview , param , frame , handler
@@ -656,6 +667,7 @@ def first_show(self):
656667 self ._clear_main_menu ()
657668 self ._add_app_menu ()
658669 self ._add_view_menu ()
670+ self ._add_edit_menu ()
659671 self ._add_user_menu ()
660672
661673 BrowserView .app .activateIgnoringOtherApps_ (Foundation .YES )
@@ -1064,6 +1076,34 @@ def _add_view_menu(self):
10641076 AppKit .NSControlKeyMask | AppKit .NSCommandKeyMask
10651077 )
10661078
1079+ def _add_edit_menu (self ):
1080+ """
1081+ Create a default Edit menu that shows Copy/Paste/etc.
1082+ """
1083+ mainMenu = BrowserView .app .mainMenu ()
1084+
1085+ if not mainMenu :
1086+ mainMenu = AppKit .NSMenu .alloc ().init ()
1087+ BrowserView .app .setMainMenu_ (mainMenu )
1088+
1089+ # Create an Edit menu and make it a submenu of the main menu
1090+ editMenu = AppKit .NSMenu .alloc ().init ()
1091+ editMenu .setTitle_ (self .localization ['cocoa.menu.edit' ])
1092+ editMenuItem = AppKit .NSMenuItem .alloc ().init ()
1093+ editMenuItem .setSubmenu_ (editMenu )
1094+ # Make the edit menu the first item after the application menu
1095+ mainMenu .insertItem_atIndex_ (editMenuItem , 1 )
1096+
1097+ for (title , action , keyEquivalent ) in [
1098+ (self .localization ['cocoa.menu.cut' ], 'cut:' , 'x' ),
1099+ (self .localization ['cocoa.menu.copy' ], 'copy:' , 'c' ),
1100+ (self .localization ['cocoa.menu.paste' ], 'paste:' , 'v' ),
1101+ (self .localization ['cocoa.menu.selectAll' ], 'selectAll:' , 'a' ),
1102+ ]:
1103+ menuItem = editMenu .addItemWithTitle_action_keyEquivalent_ (
1104+ title , action , keyEquivalent
1105+ )
1106+
10671107 def _append_app_name (self , val ):
10681108 """
10691109 Append the application name to a string if it's available. If not, the
@@ -1128,6 +1168,29 @@ def display_confirmation_dialog(first_button, second_button, message):
11281168
11291169 return alert .runModal () == AppKit .NSAlertFirstButtonReturn
11301170
1171+ @staticmethod
1172+ def display_input_dialog (first_button , second_button , prompt , default_text ):
1173+ AppKit .NSApplication .sharedApplication ()
1174+ AppKit .NSRunningApplication .currentApplication ().activateWithOptions_ (
1175+ AppKit .NSApplicationActivateIgnoringOtherApps
1176+ )
1177+ alert = AppKit .NSAlert .alloc ().init ()
1178+ text_field = AppKit .NSTextField .alloc ().initWithFrame_ (
1179+ AppKit .NSMakeRect (0 , 0 , 240 , 24 )
1180+ )
1181+ text_field .cell ().setScrollable_ (True )
1182+ text_field .setStringValue_ (default_text )
1183+ alert .setAccessoryView_ (text_field )
1184+ alert .addButtonWithTitle_ (first_button )
1185+ alert .addButtonWithTitle_ (second_button )
1186+ alert .setMessageText_ (prompt )
1187+ alert .setAlertStyle_ (AppKit .NSWarningAlertStyle )
1188+
1189+ if alert .runModal () == AppKit .NSAlertFirstButtonReturn :
1190+ return text_field .stringValue ()
1191+ else :
1192+ return None
1193+
11311194 @staticmethod
11321195 def should_close (window ):
11331196 quit = window .localization ['global.quit' ]
0 commit comments