PDFViewer: Propagate errors from OutlineModel construction

This follows the same idea that Andreas was doing in this latest videos,
where construction-time TRY()s were not present but should have been.
Like Andreas did, moving the initialisation of such fields to the
factory function, which then returns ErrorOr solves the issue.
This commit is contained in:
Rodrigo Tobar 2022-12-17 12:18:29 +08:00 committed by Andreas Kling
commit 2ea8d2547e
Notes: sideshowbarker 2024-07-17 03:03:41 +09:00
4 changed files with 11 additions and 9 deletions

View file

@ -7,16 +7,17 @@
#include "OutlineModel.h"
#include <LibGfx/Font/FontDatabase.h>
NonnullRefPtr<OutlineModel> OutlineModel::create(NonnullRefPtr<PDF::OutlineDict> const& outline)
ErrorOr<NonnullRefPtr<OutlineModel>> OutlineModel::create(NonnullRefPtr<PDF::OutlineDict> const& outline)
{
return adopt_ref(*new OutlineModel(outline));
auto outline_model = adopt_ref(*new OutlineModel(outline));
outline_model->m_closed_item_icon.set_bitmap_for_size(16, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/book.png"sv)));
outline_model->m_open_item_icon.set_bitmap_for_size(16, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/book-open.png"sv)));
return outline_model;
}
OutlineModel::OutlineModel(NonnullRefPtr<PDF::OutlineDict> const& outline)
: m_outline(outline)
{
m_closed_item_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/book.png"sv).release_value_but_fixme_should_propagate_errors());
m_open_item_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/book-open.png"sv).release_value_but_fixme_should_propagate_errors());
}
void OutlineModel::set_index_open_state(const GUI::ModelIndex& index, bool is_open)