UI/AppKit: Implement download directory selection

This commit is contained in:
Timothy Flynn 2024-08-28 15:45:55 -04:00 committed by Tim Flynn
parent 4147d771a6
commit bf2dad5d38
Notes: github-actions[bot] 2024-09-03 18:14:39 +00:00
2 changed files with 19 additions and 0 deletions

View file

@ -13,6 +13,7 @@
#include <LibWebView/Application.h>
#include <LibWebView/WebContentClient.h>
#include <UI/LadybirdWebViewBridge.h>
#include <Utilities/Conversions.h>
#import <Application/Application.h>
@ -24,6 +25,21 @@ namespace Ladybird {
class ApplicationBridge : public WebView::Application {
WEB_VIEW_APPLICATION(ApplicationBridge)
private:
virtual Optional<ByteString> ask_user_for_download_folder() const override
{
auto* panel = [NSOpenPanel openPanel];
[panel setAllowsMultipleSelection:NO];
[panel setCanChooseDirectories:YES];
[panel setCanChooseFiles:NO];
[panel setMessage:@"Select download directory"];
if ([panel runModal] != NSModalResponseOK)
return {};
return Ladybird::ns_string_to_byte_string([[panel URL] path]);
}
};
ApplicationBridge::ApplicationBridge(Badge<WebView::Application>, Main::Arguments&)

View file

@ -1201,6 +1201,9 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_
}];
})
.when_rejected([self](auto const& error) {
if (error.is_errno() && error.code() == ECANCELED)
return;
auto error_message = MUST(String::formatted("{}", error));
auto* dialog = [[NSAlert alloc] init];