summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-01-04 17:44:32 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-04 21:49:44 +0100
commit5c68e91dd72e919d63ced309999c672712ab0e3f (patch)
treed363478df2929bab13cc8aad1ce370679809e88b /Userland/Applications
parent7178c39a78003404493bfd31197986708f8ef469 (diff)
downloadserenity-5c68e91dd72e919d63ced309999c672712ab0e3f.zip
TextEditor: Use early return style in "save" action callback
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/TextEditor/MainWidget.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/Userland/Applications/TextEditor/MainWidget.cpp b/Userland/Applications/TextEditor/MainWidget.cpp
index 21dad0c640..039c5f7047 100644
--- a/Userland/Applications/TextEditor/MainWidget.cpp
+++ b/Userland/Applications/TextEditor/MainWidget.cpp
@@ -303,24 +303,23 @@ MainWidget::MainWidget()
});
m_save_action = GUI::CommonActions::make_save_action([&](auto&) {
- if (!m_path.is_empty()) {
- auto response = FileSystemAccessClient::Client::the().request_file(window()->window_id(), m_path, Core::OpenMode::Truncate | Core::OpenMode::WriteOnly);
-
- 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;
+ if (m_path.is_empty()) {
+ m_save_as_action->activate();
+ return;
+ }
+ auto response = FileSystemAccessClient::Client::the().request_file(window()->window_id(), m_path, Core::OpenMode::Truncate | Core::OpenMode::WriteOnly);
- if (!m_editor->write_to_file_and_close(fd)) {
- GUI::MessageBox::show(window(), "Unable to save file.\n", "Error", GUI::MessageBox::Type::Error);
- }
+ if (response.error != 0) {
+ if (response.error != -1)
+ GUI::MessageBox::show_error(window(), String::formatted("Unable to save file: {}", strerror(response.error)));
return;
}
- m_save_as_action->activate();
+ int fd = *response.fd;
+
+ if (!m_editor->write_to_file_and_close(fd)) {
+ GUI::MessageBox::show(window(), "Unable to save file.\n", "Error", GUI::MessageBox::Type::Error);
+ }
});
m_toolbar->add_action(*m_new_action);