1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:27:45 +00:00

HexEditor: Use the constructor pattern

This commit is contained in:
Lucas CHOLLET 2023-01-14 22:24:48 -05:00 committed by Andrew Kaster
parent a621b5f015
commit b1d8404c92
3 changed files with 13 additions and 4 deletions

View file

@ -70,10 +70,18 @@ bool HexDocumentMemory::write_to_file(NonnullRefPtr<Core::File> file)
return true;
}
ErrorOr<NonnullOwnPtr<HexDocumentFile>> HexDocumentFile::create(NonnullRefPtr<Core::File> file)
{
auto document = TRY(adopt_nonnull_own_or_enomem(new HexDocumentFile(move(file))));
// FIXME: Remove this hackery
document->set_file(move(document->m_file));
return document;
}
HexDocumentFile::HexDocumentFile(NonnullRefPtr<Core::File> file)
: m_file(file)
{
set_file(file);
}
void HexDocumentFile::write_to_file()

View file

@ -58,7 +58,7 @@ private:
class HexDocumentFile final : public HexDocument {
public:
explicit HexDocumentFile(NonnullRefPtr<Core::File> file);
static ErrorOr<NonnullOwnPtr<HexDocumentFile>> create(NonnullRefPtr<Core::File> file);
virtual ~HexDocumentFile() = default;
HexDocumentFile(HexDocumentFile&&) = default;
@ -75,6 +75,7 @@ public:
void clear_changes() override;
private:
explicit HexDocumentFile(NonnullRefPtr<Core::File> file);
void ensure_position_in_buffer(size_t position);
NonnullRefPtr<Core::File> m_file;

View file

@ -65,7 +65,7 @@ ErrorOr<void> HexEditor::open_new_file(size_t size)
void HexEditor::open_file(NonnullRefPtr<Core::File> file)
{
m_document = make<HexDocumentFile>(file);
m_document = HexDocumentFile::create(move(file)).release_value_but_fixme_should_propagate_errors();
set_content_length(m_document->size());
m_position = 0;
m_cursor_at_low_nibble = false;
@ -146,7 +146,7 @@ bool HexEditor::save_as(NonnullRefPtr<Core::File> new_file)
auto& memory_document = static_cast<HexDocumentMemory&>(*m_document);
if (!memory_document.write_to_file(new_file))
return false;
m_document = make<HexDocumentFile>(new_file);
m_document = HexDocumentFile::create(move(new_file)).release_value_but_fixme_should_propagate_errors();
}
update();