1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:57:35 +00:00

LibGUI: Base write_to_file(StringView path) on the stream overload

`write_to_file(StringView path)` was based on the `Core::File` overload.
The return type also changed from `bool` to `ErrorOr<void>` to ease
error propagation.
This commit is contained in:
Lucas CHOLLET 2023-01-15 00:30:51 -05:00 committed by Sam Atkins
parent be28800e0d
commit 107e15c5bc
3 changed files with 6 additions and 10 deletions

View file

@ -79,7 +79,7 @@ void EditorWrapper::save()
}); });
file_picker_action->activate(); file_picker_action->activate();
} }
editor().write_to_file(filename()); editor().write_to_file(filename()).release_value_but_fixme_should_propagate_errors();
update_diff(); update_diff();
editor().update(); editor().update();
} }

View file

@ -1458,15 +1458,11 @@ void TextEditor::timer_event(Core::TimerEvent&)
update_cursor(); update_cursor();
} }
bool TextEditor::write_to_file(DeprecatedString const& path) ErrorOr<void> TextEditor::write_to_file(StringView path)
{ {
auto file = Core::File::construct(path); auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Write | Core::Stream::OpenMode::Truncate));
if (!file->open(Core::OpenMode::WriteOnly | Core::OpenMode::Truncate)) { TRY(write_to_file(*file));
warnln("Error opening {}: {}", path, strerror(file->error())); return {};
return false;
}
return write_to_file(*file);
} }
bool TextEditor::write_to_file(Core::File& file) bool TextEditor::write_to_file(Core::File& file)

View file

@ -129,7 +129,7 @@ public:
void insert_at_cursor_or_replace_selection(StringView); void insert_at_cursor_or_replace_selection(StringView);
void replace_all_text_without_resetting_undo_stack(StringView text); void replace_all_text_without_resetting_undo_stack(StringView text);
bool write_to_file(DeprecatedString const& path); ErrorOr<void> write_to_file(StringView path);
bool write_to_file(Core::File&); bool write_to_file(Core::File&);
ErrorOr<void> write_to_file(Core::Stream::File&); ErrorOr<void> write_to_file(Core::Stream::File&);
bool has_selection() const { return m_selection.is_valid(); } bool has_selection() const { return m_selection.is_valid(); }