Revision: 29589
http://sourceforge.net/p/bibdesk/svn/29589
Author: hofman
Date: 2025-09-16 16:16:43 +0000 (Tue, 16 Sep 2025)
Log Message:
-----------
create alert for javascript in separate method
Modified Paths:
--------------
trunk/bibdesk/BDSKTextImportController.m
trunk/bibdesk/BDSKWebView.m
Modified: trunk/bibdesk/BDSKTextImportController.m
===================================================================
--- trunk/bibdesk/BDSKTextImportController.m 2025-09-16 15:17:08 UTC (rev
29588)
+++ trunk/bibdesk/BDSKTextImportController.m 2025-09-16 16:16:43 UTC (rev
29589)
@@ -1002,25 +1002,33 @@
#pragma mark BDSKUIDelegate protocol
-- (NSString *)alertTitleForFrame:(WKFrameInfo *)frame {
+- (NSAlert *)javaScriptAlertWithMessage:(NSString *)message
initiatedByFrame:(WKFrameInfo *)frame withConfirm:(BOOL)confirm {
+ NSString *title = nil;
NSURL *url = [[frame request] URL];
NSString *scheme = [url scheme];
NSString *host = [url host];
- if (scheme != nil && host != nil)
- return [NSString stringWithFormat:@"%@://%@", scheme, host];
- NSString *string = [url absoluteString];
- NSUInteger l = [string rangeOfCharacterFromSet:[NSCharacterSet
characterSetWithCharactersInString:@"/?#"]].location;
- if (l != NSNotFound)
- string = [string substringToIndex:l];
- if ([NSString isEmptyString:string] == NO)
- return string;
- return NSLocalizedString(@"JavaScript", @"Default JavaScript alert title");
+ if (scheme != nil && host != nil) {
+ title = [NSString stringWithFormat:@"%@://%@", scheme, host];
+ } else {
+ title = [url absoluteString];
+ NSUInteger l = [title rangeOfCharacterFromSet:[NSCharacterSet
characterSetWithCharactersInString:@"/?#"]].location;
+ if (l != NSNotFound)
+ title = [title substringToIndex:l];
+ if ([NSString isEmptyString:title])
+ title = NSLocalizedString(@"JavaScript", @"Default JavaScript
alert title");
+ }
+ NSAlert *alert = [[NSAlert alloc] init];
+ [alert setMessageText:title];
+ [alert setInformativeText:message];
+ if (confirm) {
+ [alert addButtonWithTitle:NSLocalizedString(@"OK", @"Button title")];
+ [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"Button
title")];
+ }
+ return alert;
}
- (void)webView:(WKWebView *)aWebView
runJavaScriptAlertPanelWithMessage:(NSString *)message
initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void
(^)(void))completionHandler {
- NSAlert *alert = [[NSAlert alloc] init];
- [alert setMessageText:[self alertTitleForFrame:frame]];
- [alert setInformativeText:message];
+ NSAlert *alert = [self javaScriptAlertWithMessage:message
initiatedByFrame:frame withConfirm:NO];
if ([self window]) {
[alert beginSheetModalForWindow:[self window]
completionHandler:^(NSModalResponse result){
completionHandler();
@@ -1032,11 +1040,7 @@
}
- (void)webView:(WKWebView *)aWebView
runJavaScriptConfirmPanelWithMessage:(NSString *)message
initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL
result))completionHandler {
- NSAlert *alert = [[NSAlert alloc] init];
- [alert setMessageText:[self alertTitleForFrame:frame]];
- [alert setInformativeText:message];
- [alert addButtonWithTitle:NSLocalizedString(@"OK", @"Button title")];
- [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"Button title")];
+ NSAlert *alert = [self javaScriptAlertWithMessage:message
initiatedByFrame:frame withConfirm:YES];
if ([self window]) {
[alert beginSheetModalForWindow:[self window]
completionHandler:^(NSModalResponse result){
completionHandler(result == NSAlertFirstButtonReturn);
@@ -1047,11 +1051,7 @@
}
- (void)webView:(WKWebView *)webView
runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString
*)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void
(^)(NSString * result))completionHandler {
- NSAlert *alert = [[NSAlert alloc] init];
- [alert setMessageText:[self alertTitleForFrame:frame]];
- [alert setInformativeText:prompt];
- [alert addButtonWithTitle:NSLocalizedString(@"OK", @"Button title")];
- [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"Button title")];
+ NSAlert *alert = [self javaScriptAlertWithMessage:prompt
initiatedByFrame:frame withConfirm:YES];
NSTextField *textField = [[NSTextField alloc]
initWithFrame:NSMakeRect(0.0, 0.0, 300.0, 21.0)];
[textField sizeToFit];
[textField setFrameSize:NSMakeSize(300.0, NSHeight([textField frame]))];
Modified: trunk/bibdesk/BDSKWebView.m
===================================================================
--- trunk/bibdesk/BDSKWebView.m 2025-09-16 15:17:08 UTC (rev 29588)
+++ trunk/bibdesk/BDSKWebView.m 2025-09-16 16:16:43 UTC (rev 29589)
@@ -696,28 +696,43 @@
return NSLocalizedString(@"JavaScript", @"Default JavaScript alert title");
}
-- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString
*)message initiatedByFrame:(WebFrame *)frame {
+- (NSAlert *)javaScriptAlertPanelWithMessage:(NSString *)message
initiatedByFrame:(WebFrame *)frame withConfirm:(BOOL)confirm {
+ NSString *title = nil;
+ NSURL *url = [[[frame dataSource] request] URL];
+ NSString *scheme = [url scheme];
+ NSString *host = [url host];
+ if (scheme != nil && host != nil) {
+ title = [NSString stringWithFormat:@"%@://%@", scheme, host];
+ } else {
+ title = [url absoluteString];
+ NSUInteger l = [title rangeOfCharacterFromSet:[NSCharacterSet
characterSetWithCharactersInString:@"/?#"]].location;
+ if (l != NSNotFound)
+ title = [title substringToIndex:l];
+ if ([NSString isEmptyString:title])
+ title = NSLocalizedString(@"JavaScript", @"Default JavaScript
alert title");
+ }
NSAlert *alert = [[NSAlert alloc] init];
- [alert setMessageText:[self alertTitleForFrame:frame]];
+ [alert setMessageText:title];
[alert setInformativeText:message];
+ if (confirm) {
+ [alert addButtonWithTitle:NSLocalizedString(@"OK", @"Button title")];
+ [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"Button
title")];
+ }
+ return alert;
+}
+
+- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString
*)message initiatedByFrame:(WebFrame *)frame {
+ NSAlert *alert = [self javaScriptAlertPanelWithMessage:message
initiatedByFrame:frame withConfirm:NO];
[alert runModal];
}
- (BOOL)webView:(WebView *)sender
runJavaScriptConfirmPanelWithMessage:(NSString *)message
initiatedByFrame:(WebFrame *)frame {
- NSAlert *alert = [[NSAlert alloc] init];
- [alert setMessageText:[self alertTitleForFrame:frame]];
- [alert setInformativeText:message];
- [alert addButtonWithTitle:NSLocalizedString(@"OK", @"Button title")];
- [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"Button title")];
+ NSAlert *alert = [self javaScriptAlertPanelWithMessage:message
initiatedByFrame:frame withConfirm:YES];
return NSAlertFirstButtonReturn == [alert runModal];
}
- (NSString *)webView:(WebView *)sender
runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString
*)defaultText initiatedByFrame:(WebFrame *)frame {
- NSAlert *alert = [[NSAlert alloc] init];
- [alert setMessageText:[self alertTitleForFrame:frame]];
- [alert setInformativeText:prompt];
- [alert addButtonWithTitle:NSLocalizedString(@"OK", @"Button title")];
- [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"Button title")];
+ NSAlert *alert = [self javaScriptAlertPanelWithMessage:prompt
initiatedByFrame:frame withConfirm:YES];
NSTextField *textField = [[NSTextField alloc]
initWithFrame:NSMakeRect(0.0, 0.0, 300.0, 21.0)];
[textField sizeToFit];
[textField setFrameSize:NSMakeSize(300.0, NSHeight([textField frame]))];
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit