From a3638639a179f7b1deabe9e05b550a2cd6d585cd Mon Sep 17 00:00:00 2001 From: Adam Hodgen Date: Sat, 10 Jul 2021 23:48:41 +0100 Subject: [PATCH] TextEditor: Show an error dialog when failing to open/save a file --- Userland/Applications/TextEditor/MainWidget.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/TextEditor/MainWidget.cpp b/Userland/Applications/TextEditor/MainWidget.cpp index f15776f6d6..ab490a1185 100644 --- a/Userland/Applications/TextEditor/MainWidget.cpp +++ b/Userland/Applications/TextEditor/MainWidget.cpp @@ -262,8 +262,11 @@ MainWidget::MainWidget() m_open_action = GUI::CommonActions::make_open_action([this](auto&) { auto fd_response = m_file_system_access_client->prompt_open_file(Core::StandardPaths::home_directory(), Core::OpenMode::ReadWrite); - if (fd_response.error() != 0) + if (fd_response.error() != 0) { + if (fd_response.error() != -1) + GUI::MessageBox::show_error(window(), String::formatted("Opening \"{}\" failed: {}", fd_response.chosen_file().value(), strerror(fd_response.error()))); return; + } if (editor().document().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); @@ -279,8 +282,11 @@ MainWidget::MainWidget() m_save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) { auto response = m_file_system_access_client->prompt_save_file(m_name.is_null() ? "Untitled" : m_name, m_extension.is_null() ? "txt" : m_extension, Core::StandardPaths::home_directory(), Core::OpenMode::Truncate | Core::OpenMode::WriteOnly); - if (response.error() != 0) + if (response.error() != 0) { + if (response.error() != -1) + GUI::MessageBox::show_error(window(), String::formatted("Saving \"{}\" failed: {}", response.chosen_file().value(), strerror(response.error()))); return; + } if (!m_editor->write_to_file_and_close(response.fd()->take_fd())) { GUI::MessageBox::show(window(), "Unable to save file.\n", "Error", GUI::MessageBox::Type::Error); @@ -297,8 +303,11 @@ MainWidget::MainWidget() if (!m_path.is_empty()) { auto response = m_file_system_access_client->request_file(m_path, Core::OpenMode::Truncate | Core::OpenMode::WriteOnly); - if (response.error() != 0) + if (response.error() != 0) { + if (response.error() != -1) + GUI::MessageBox::show_error(window(), String::formatted("Unable to save file: {}", strerror(response.error()))); return; + } int fd = response.fd()->take_fd();