mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
Playground: Prompt to save changes after the user picked a file to open
There's no point in saving the file - and potentially having to ask the user for a file name - if the user abandons the 'Open' action by clicking 'Cancel' in the file picker. This now also matches TextEditor's behavior.
This commit is contained in:
parent
c2ae25967a
commit
92fdc5bd69
Notes:
sideshowbarker
2024-07-18 11:38:45 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/92fdc5bd69a Pull-request: https://github.com/SerenityOS/serenity/pull/8206
1 changed files with 5 additions and 5 deletions
|
@ -186,6 +186,11 @@ int main(int argc, char** argv)
|
|||
});
|
||||
|
||||
file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
|
||||
Optional<String> open_path = GUI::FilePicker::get_open_filepath(window);
|
||||
|
||||
if (!open_path.has_value())
|
||||
return;
|
||||
|
||||
if (window->is_modified()) {
|
||||
auto save_document_first_result = GUI::MessageBox::show(window, "Save changes to current document first?", "Warning", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel);
|
||||
if (save_document_first_result == GUI::Dialog::ExecResult::ExecYes)
|
||||
|
@ -194,11 +199,6 @@ int main(int argc, char** argv)
|
|||
return;
|
||||
}
|
||||
|
||||
Optional<String> open_path = GUI::FilePicker::get_open_filepath(window);
|
||||
|
||||
if (!open_path.has_value())
|
||||
return;
|
||||
|
||||
auto file = Core::File::construct(open_path.value());
|
||||
if (!file->open(Core::OpenMode::ReadOnly) && file->error() != ENOENT) {
|
||||
GUI::MessageBox::show(window, String::formatted("Opening \"{}\" failed: {}", open_path.value(), strerror(errno)), "Error", GUI::MessageBox::Type::Error);
|
||||
|
|
Loading…
Reference in a new issue