mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-03 23:25:20 +00:00
PDFViewer: Display error dialog if necessary instead of crashing
This commit is contained in:
committed by
Ali Mohammad Pur
parent
1ef5071d1b
commit
e7b70a1435
@@ -12,6 +12,7 @@
|
||||
#include <LibGUI/Label.h>
|
||||
#include <LibGUI/Menu.h>
|
||||
#include <LibGUI/Menubar.h>
|
||||
#include <LibGUI/MessageBox.h>
|
||||
#include <LibGUI/Splitter.h>
|
||||
#include <LibGUI/Toolbar.h>
|
||||
#include <LibGUI/ToolbarContainer.h>
|
||||
@@ -103,11 +104,18 @@ void PDFViewerWidget::open_file(const String& path)
|
||||
{
|
||||
window()->set_title(String::formatted("{} - PDF Viewer", path));
|
||||
auto file_result = Core::File::open(path, Core::OpenMode::ReadOnly);
|
||||
VERIFY(!file_result.is_error());
|
||||
if (file_result.is_error()) {
|
||||
GUI::MessageBox::show_error(nullptr, String::formatted("Couldn't open file: {}", path));
|
||||
return;
|
||||
}
|
||||
|
||||
m_buffer = file_result.value()->read_all();
|
||||
auto document = PDF::Document::create(m_buffer);
|
||||
// FIXME: Show error dialog if the Document is invalid
|
||||
VERIFY(document);
|
||||
if (!document) {
|
||||
GUI::MessageBox::show_error(nullptr, String::formatted("Couldn't load PDF: {}", path));
|
||||
return;
|
||||
}
|
||||
|
||||
m_viewer->set_document(document);
|
||||
m_total_page_label->set_text(String::formatted("of {}", document->get_page_count()));
|
||||
m_total_page_label->set_fixed_width(30);
|
||||
|
||||
Reference in New Issue
Block a user