mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:48:10 +00:00
TextEditor: Use early return style in "save" action callback
This commit is contained in:
parent
7178c39a78
commit
5c68e91dd7
1 changed files with 13 additions and 14 deletions
|
@ -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 (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 (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_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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue