mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 06:02:07 +03:00
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:
parent
cb2cf6de99
commit
2ea8d2547e
Notes:
sideshowbarker
2024-07-17 03:03:41 +09:00
Author: https://github.com/rtobar Commit: https://github.com/SerenityOS/serenity/commit/2ea8d2547e Pull-request: https://github.com/SerenityOS/serenity/pull/16550
@ -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)
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
class OutlineModel final : public GUI::Model {
|
||||
public:
|
||||
static NonnullRefPtr<OutlineModel> create(NonnullRefPtr<PDF::OutlineDict> const& outline);
|
||||
static ErrorOr<NonnullRefPtr<OutlineModel>> create(NonnullRefPtr<PDF::OutlineDict> const& outline);
|
||||
|
||||
void set_index_open_state(const GUI::ModelIndex& index, bool is_open);
|
||||
|
||||
|
@ -376,11 +376,11 @@ PDF::PDFErrorOr<void> PDFViewerWidget::try_open_file(Core::File& file)
|
||||
|
||||
if (document->outline()) {
|
||||
auto outline = document->outline();
|
||||
m_sidebar->set_outline(outline.release_nonnull());
|
||||
TRY(m_sidebar->set_outline(outline.release_nonnull()));
|
||||
m_sidebar->set_visible(true);
|
||||
m_sidebar_open = true;
|
||||
} else {
|
||||
m_sidebar->set_outline({});
|
||||
TRY(m_sidebar->set_outline({}));
|
||||
m_sidebar->set_visible(false);
|
||||
m_sidebar_open = false;
|
||||
}
|
||||
|
@ -16,15 +16,16 @@ class SidebarWidget final : public GUI::Widget {
|
||||
public:
|
||||
~SidebarWidget() override = default;
|
||||
|
||||
void set_outline(RefPtr<PDF::OutlineDict> outline)
|
||||
ErrorOr<void> set_outline(RefPtr<PDF::OutlineDict> outline)
|
||||
{
|
||||
if (outline) {
|
||||
m_model = OutlineModel::create(outline.release_nonnull());
|
||||
m_model = TRY(OutlineModel::create(outline.release_nonnull()));
|
||||
m_outline_tree_view->set_model(m_model);
|
||||
} else {
|
||||
m_model = RefPtr<OutlineModel> {};
|
||||
m_outline_tree_view->set_model({});
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user