mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
HexEditor: Propagate errors when using "Save"
This commit is contained in:
parent
2bba743c24
commit
a2dca2b762
|
@ -83,15 +83,16 @@ HexDocumentFile::HexDocumentFile(NonnullOwnPtr<Core::Stream::File> file)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void HexDocumentFile::write_to_file()
|
ErrorOr<void> HexDocumentFile::write_to_file()
|
||||||
{
|
{
|
||||||
for (auto& change : m_changes) {
|
for (auto& change : m_changes) {
|
||||||
m_file->seek(change.key, SeekMode::SetPosition).release_value_but_fixme_should_propagate_errors();
|
TRY(m_file->seek(change.key, SeekMode::SetPosition));
|
||||||
m_file->write({ &change.value, 1 }).release_value_but_fixme_should_propagate_errors();
|
TRY(m_file->write({ &change.value, 1 }));
|
||||||
}
|
}
|
||||||
clear_changes();
|
clear_changes();
|
||||||
// make sure the next get operation triggers a read
|
// make sure the next get operation triggers a read
|
||||||
m_buffer_file_pos = m_file_size + 1;
|
m_buffer_file_pos = m_file_size + 1;
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> HexDocumentFile::write_to_file(Core::Stream::File& file)
|
ErrorOr<void> HexDocumentFile::write_to_file(Core::Stream::File& file)
|
||||||
|
|
|
@ -66,7 +66,7 @@ public:
|
||||||
|
|
||||||
void set_file(NonnullOwnPtr<Core::Stream::File> file);
|
void set_file(NonnullOwnPtr<Core::Stream::File> file);
|
||||||
NonnullOwnPtr<Core::Stream::File> const& file() const;
|
NonnullOwnPtr<Core::Stream::File> const& file() const;
|
||||||
void write_to_file();
|
ErrorOr<void> write_to_file();
|
||||||
ErrorOr<void> write_to_file(Core::Stream::File& file);
|
ErrorOr<void> write_to_file(Core::Stream::File& file);
|
||||||
Cell get(size_t position) override;
|
Cell get(size_t position) override;
|
||||||
u8 get_unchanged(size_t position) override;
|
u8 get_unchanged(size_t position) override;
|
||||||
|
|
|
@ -153,14 +153,13 @@ ErrorOr<void> HexEditor::save_as(NonnullOwnPtr<Core::Stream::File> new_file)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HexEditor::save()
|
ErrorOr<void> HexEditor::save()
|
||||||
{
|
{
|
||||||
if (m_document->type() != HexDocument::Type::File) {
|
if (m_document->type() != HexDocument::Type::File)
|
||||||
return false;
|
return Error::from_string_literal("Unable to save from a memory document");
|
||||||
}
|
|
||||||
|
|
||||||
static_cast<HexDocumentFile*>(m_document.ptr())->write_to_file();
|
TRY(static_cast<HexDocumentFile*>(m_document.ptr())->write_to_file());
|
||||||
return true;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t HexEditor::selection_size()
|
size_t HexEditor::selection_size()
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
ErrorOr<void> fill_selection(u8 fill_byte);
|
ErrorOr<void> fill_selection(u8 fill_byte);
|
||||||
Optional<u8> get_byte(size_t position);
|
Optional<u8> get_byte(size_t position);
|
||||||
ErrorOr<void> save_as(NonnullOwnPtr<Core::Stream::File>);
|
ErrorOr<void> save_as(NonnullOwnPtr<Core::Stream::File>);
|
||||||
bool save();
|
ErrorOr<void> save();
|
||||||
|
|
||||||
bool undo();
|
bool undo();
|
||||||
bool redo();
|
bool redo();
|
||||||
|
|
|
@ -132,8 +132,8 @@ HexEditorWidget::HexEditorWidget()
|
||||||
if (m_path.is_empty())
|
if (m_path.is_empty())
|
||||||
return m_save_as_action->activate();
|
return m_save_as_action->activate();
|
||||||
|
|
||||||
if (!m_editor->save()) {
|
if (auto result = m_editor->save(); result.is_error()) {
|
||||||
GUI::MessageBox::show(window(), "Unable to save file.\n"sv, "Error"sv, GUI::MessageBox::Type::Error);
|
GUI::MessageBox::show(window(), DeprecatedString::formatted("Unable to save file: {}\n"sv, result.error()), "Error"sv, GUI::MessageBox::Type::Error);
|
||||||
} else {
|
} else {
|
||||||
window()->set_modified(false);
|
window()->set_modified(false);
|
||||||
m_editor->update();
|
m_editor->update();
|
||||||
|
|
Loading…
Reference in a new issue