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

LibGfx: Use ErrorOr<T> for Bitmap::try_load_from_file()

This was used in a lot of places, so this patch makes liberal use of
ErrorOr<T>::release_value_but_fixme_should_propagate_errors().
This commit is contained in:
Andreas Kling 2021-11-06 16:25:29 +01:00
parent 16f064d9be
commit 235f39e449
104 changed files with 412 additions and 397 deletions

View file

@ -25,19 +25,19 @@ namespace HackStudio {
void DebugInfoWidget::init_toolbar()
{
m_continue_action = GUI::Action::create("Continue", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-continue.png"), [](auto&) {
m_continue_action = GUI::Action::create("Continue", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-continue.png").release_value_but_fixme_should_propagate_errors(), [](auto&) {
Debugger::the().set_requested_debugger_action(Debugger::DebuggerAction::Continue);
});
m_singlestep_action = GUI::Action::create("Step Over", { Mod_None, Key_F10 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-step-over.png"), [](auto&) {
m_singlestep_action = GUI::Action::create("Step Over", { Mod_None, Key_F10 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-step-over.png").release_value_but_fixme_should_propagate_errors(), [](auto&) {
Debugger::the().set_requested_debugger_action(Debugger::DebuggerAction::SourceStepOver);
});
m_step_in_action = GUI::Action::create("Step In", { Mod_None, Key_F11 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-step-in.png"), [](auto&) {
m_step_in_action = GUI::Action::create("Step In", { Mod_None, Key_F11 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-step-in.png").release_value_but_fixme_should_propagate_errors(), [](auto&) {
Debugger::the().set_requested_debugger_action(Debugger::DebuggerAction::SourceSingleStep);
});
m_step_out_action = GUI::Action::create("Step Out", { Mod_Shift, Key_F11 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-step-out.png"), [](auto&) {
m_step_out_action = GUI::Action::create("Step Out", { Mod_Shift, Key_F11 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-step-out.png").release_value_but_fixme_should_propagate_errors(), [](auto&) {
Debugger::the().set_requested_debugger_action(Debugger::DebuggerAction::SourceStepOut);
});

View file

@ -31,7 +31,7 @@ private:
: m_variables(move(variables))
, m_regs(regs)
{
m_variable_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/inspector-object.png"));
m_variable_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/inspector-object.png").release_value_but_fixme_should_propagate_errors());
}
NonnullOwnPtrVector<Debug::DebugInfo::VariableInfo> m_variables;
PtraceRegisters m_regs;

View file

@ -433,13 +433,13 @@ void Editor::clear_execution_position()
const Gfx::Bitmap& Editor::breakpoint_icon_bitmap()
{
static auto bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/breakpoint.png");
static auto bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/breakpoint.png").release_value_but_fixme_should_propagate_errors();
return *bitmap;
}
const Gfx::Bitmap& Editor::current_position_icon_bitmap()
{
static auto bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png");
static auto bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png").release_value_but_fixme_should_propagate_errors();
return *bitmap;
}

View file

@ -31,7 +31,7 @@ GitWidget::GitWidget(const LexicalPath& repo_root)
unstaged_header.set_layout<GUI::HorizontalBoxLayout>();
auto& refresh_button = unstaged_header.add<GUI::Button>();
refresh_button.set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png"));
refresh_button.set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png").release_value_but_fixme_should_propagate_errors());
refresh_button.set_fixed_size(16, 16);
refresh_button.set_tooltip("refresh");
refresh_button.on_click = [this](int) { refresh(); };
@ -42,7 +42,7 @@ GitWidget::GitWidget(const LexicalPath& repo_root)
unstaged_header.set_fixed_height(20);
m_unstaged_files = unstaged.add<GitFilesView>(
[this](const auto& file) { stage_file(file); },
Gfx::Bitmap::try_load_from_file("/res/icons/16x16/plus.png").release_nonnull());
Gfx::Bitmap::try_load_from_file("/res/icons/16x16/plus.png").release_value_but_fixme_should_propagate_errors());
m_unstaged_files->on_selection_change = [this] {
const auto& index = m_unstaged_files->selection().first();
const auto& selected = index.data().as_string();
@ -56,7 +56,7 @@ GitWidget::GitWidget(const LexicalPath& repo_root)
staged_header.set_layout<GUI::HorizontalBoxLayout>();
auto& commit_button = staged_header.add<GUI::Button>();
commit_button.set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/commit.png"));
commit_button.set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/commit.png").release_value_but_fixme_should_propagate_errors());
commit_button.set_fixed_size(16, 16);
commit_button.set_tooltip("commit");
commit_button.on_click = [this](int) { commit(); };
@ -67,7 +67,7 @@ GitWidget::GitWidget(const LexicalPath& repo_root)
staged_header.set_fixed_height(20);
m_staged_files = staged.add<GitFilesView>(
[this](const auto& file) { unstage_file(file); },
Gfx::Bitmap::try_load_from_file("/res/icons/16x16/minus.png").release_nonnull());
Gfx::Bitmap::try_load_from_file("/res/icons/16x16/minus.png").release_value_but_fixme_should_propagate_errors());
}
bool GitWidget::initialize()

View file

@ -418,7 +418,7 @@ NonnullRefPtr<GUI::Menu> HackStudioWidget::create_project_tree_view_context_menu
NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_file_action(String const& label, String const& icon, String const& extension)
{
return GUI::Action::create(label, Gfx::Bitmap::try_load_from_file(icon), [this, extension](const GUI::Action&) {
return GUI::Action::create(label, Gfx::Bitmap::try_load_from_file(icon).release_value_but_fixme_should_propagate_errors(), [this, extension](const GUI::Action&) {
String filename;
if (GUI::InputBox::show(window(), filename, "Enter name of new file:", "Add new file to project") != GUI::InputBox::ExecOK)
return;
@ -459,7 +459,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_file_action(String const
NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_directory_action()
{
return GUI::Action::create("&New Directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/mkdir.png"), [this](const GUI::Action&) {
return GUI::Action::create("&New Directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/mkdir.png").release_value_but_fixme_should_propagate_errors(), [this](const GUI::Action&) {
String directory_name;
if (GUI::InputBox::show(window(), directory_name, "Enter name of new directory:", "Add new folder to project") != GUI::InputBox::ExecOK)
return;
@ -569,7 +569,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_delete_action()
NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_project_action()
{
return GUI::Action::create("&New Project...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/hackstudio-project.png"), [this](const GUI::Action&) {
return GUI::Action::create("&New Project...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/hackstudio-project.png").release_value_but_fixme_should_propagate_errors(), [this](const GUI::Action&) {
auto dialog = NewProjectDialog::construct(window());
dialog->set_icon(window()->icon());
auto result = dialog->exec();
@ -666,7 +666,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_remove_current_editor_action
NonnullRefPtr<GUI::Action> HackStudioWidget::create_open_action()
{
return GUI::Action::create("&Open Project...", { Mod_Ctrl | Mod_Shift, Key_O }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png"), [this](auto&) {
return GUI::Action::create("&Open Project...", { Mod_Ctrl | Mod_Shift, Key_O }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png").release_value_but_fixme_should_propagate_errors(), [this](auto&) {
auto open_path = GUI::FilePicker::get_open_filepath(window(), "Open project", m_project->root_path(), true);
if (!open_path.has_value())
return;
@ -746,7 +746,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_remove_current_terminal_acti
NonnullRefPtr<GUI::Action> HackStudioWidget::create_add_editor_action()
{
return GUI::Action::create("Add New &Editor", { Mod_Ctrl | Mod_Alt, Key_E },
Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-text-editor.png"),
Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-text-editor.png").release_value_but_fixme_should_propagate_errors(),
[this](auto&) {
add_new_editor(*m_editors_splitter);
update_actions();
@ -756,7 +756,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_add_editor_action()
NonnullRefPtr<GUI::Action> HackStudioWidget::create_add_terminal_action()
{
return GUI::Action::create("Add New &Terminal", { Mod_Ctrl | Mod_Alt, Key_T },
Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-terminal.png"),
Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-terminal.png").release_value_but_fixme_should_propagate_errors(),
[this](auto&) {
auto& terminal_wrapper = m_action_tab_widget->add_tab<TerminalWrapper>("Terminal");
reveal_action_tab(terminal_wrapper);
@ -774,7 +774,7 @@ void HackStudioWidget::reveal_action_tab(GUI::Widget& widget)
NonnullRefPtr<GUI::Action> HackStudioWidget::create_debug_action()
{
return GUI::Action::create("&Debug", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-run.png"), [this](auto&) {
return GUI::Action::create("&Debug", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-run.png").release_value_but_fixme_should_propagate_errors(), [this](auto&) {
if (!Core::File::exists(get_project_executable_path())) {
GUI::MessageBox::show(window(), String::formatted("Could not find file: {}. (did you build the project?)", get_project_executable_path()), "Error", GUI::MessageBox::Type::Error);
return;
@ -1024,7 +1024,7 @@ void HackStudioWidget::create_toolbar(GUI::Widget& parent)
NonnullRefPtr<GUI::Action> HackStudioWidget::create_build_action()
{
return GUI::Action::create("&Build", { Mod_Ctrl, Key_B }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/build.png"), [this](auto&) {
return GUI::Action::create("&Build", { Mod_Ctrl, Key_B }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/build.png").release_value_but_fixme_should_propagate_errors(), [this](auto&) {
if (warn_unsaved_changes("There are unsaved changes, do you want to save before building?") == ContinueDecision::No)
return;
@ -1036,7 +1036,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_build_action()
NonnullRefPtr<GUI::Action> HackStudioWidget::create_run_action()
{
return GUI::Action::create("&Run", { Mod_Ctrl, Key_R }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/program-run.png"), [this](auto&) {
return GUI::Action::create("&Run", { Mod_Ctrl, Key_R }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/program-run.png").release_value_but_fixme_should_propagate_errors(), [this](auto&) {
reveal_action_tab(*m_terminal_wrapper);
run(*m_terminal_wrapper);
m_stop_action->set_enabled(true);
@ -1125,7 +1125,7 @@ void HackStudioWidget::create_project_menu(GUI::Window& window)
void HackStudioWidget::create_edit_menu(GUI::Window& window)
{
auto& edit_menu = window.add_menu("&Edit");
edit_menu.add_action(GUI::Action::create("&Find in Files...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/find.png"), [this](auto&) {
edit_menu.add_action(GUI::Action::create("&Find in Files...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/find.png").release_value_but_fixme_should_propagate_errors(), [this](auto&) {
reveal_action_tab(*m_find_in_files_widget);
m_find_in_files_widget->focus_textbox_and_select_all();
}));
@ -1196,7 +1196,7 @@ void HackStudioWidget::create_view_menu(GUI::Window& window)
m_no_wrapping_action->set_checked(true);
m_editor_font_action = GUI::Action::create("Editor &Font...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-font-editor.png"),
m_editor_font_action = GUI::Action::create("Editor &Font...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-font-editor.png").release_value_but_fixme_should_propagate_errors(),
[&](auto&) {
auto picker = GUI::FontPicker::construct(&window, m_editor_font, false);
if (picker->exec() == GUI::Dialog::ExecOK) {
@ -1226,7 +1226,7 @@ void HackStudioWidget::create_help_menu(GUI::Window& window)
NonnullRefPtr<GUI::Action> HackStudioWidget::create_stop_action()
{
auto action = GUI::Action::create("&Stop", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/program-stop.png"), [this](auto&) {
auto action = GUI::Action::create("&Stop", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/program-stop.png").release_value_but_fixme_should_propagate_errors(), [this](auto&) {
if (!Debugger::the().session()) {
m_terminal_wrapper->kill_running_command();
return;
@ -1380,7 +1380,7 @@ void HackStudioWidget::on_cursor_change()
void HackStudioWidget::create_location_history_actions()
{
m_locations_history_back_action = GUI::Action::create("Go Back", { Mod_Alt | Mod_Shift, Key_Left }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-back.png"), [this](auto&) {
m_locations_history_back_action = GUI::Action::create("Go Back", { Mod_Alt | Mod_Shift, Key_Left }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-back.png").release_value_but_fixme_should_propagate_errors(), [this](auto&) {
if (m_locations_history_end_index <= 1)
return;
@ -1394,7 +1394,7 @@ void HackStudioWidget::create_location_history_actions()
update_history_actions();
});
m_locations_history_forward_action = GUI::Action::create("Go Forward", { Mod_Alt | Mod_Shift, Key_Right }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png"), [this](auto&) {
m_locations_history_forward_action = GUI::Action::create("Go Forward", { Mod_Alt | Mod_Shift, Key_Right }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png").release_value_but_fixme_should_propagate_errors(), [this](auto&) {
if (m_locations_history_end_index == m_locations_history.size())
return;

View file

@ -185,7 +185,7 @@ void ServerConnectionWrapper::on_crash()
void ServerConnectionWrapper::show_frequenct_crashes_notification() const
{
auto notification = GUI::Notification::construct();
notification->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/32x32/app-hack-studio.png"));
notification->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/32x32/app-hack-studio.png").release_value_but_fixme_should_propagate_errors());
notification->set_title("LanguageServer Crashes too much!");
notification->set_text("LanguageServer aided features will not be available in this session");
notification->show();
@ -193,7 +193,7 @@ void ServerConnectionWrapper::show_frequenct_crashes_notification() const
void ServerConnectionWrapper::show_crash_notification() const
{
auto notification = GUI::Notification::construct();
notification->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/32x32/app-hack-studio.png"));
notification->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/32x32/app-hack-studio.png").release_value_but_fixme_should_propagate_errors());
notification->set_title("Oops!");
notification->set_text(String::formatted("LanguageServer has crashed"));
notification->show();

View file

@ -20,13 +20,13 @@ void HackStudio::ProjectDeclarations::set_declared_symbols(const String& filenam
Optional<GUI::Icon> HackStudio::ProjectDeclarations::get_icon_for(GUI::AutocompleteProvider::DeclarationType type)
{
static GUI::Icon struct_icon(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/Struct.png"));
static GUI::Icon class_icon(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/Class.png"));
static GUI::Icon function_icon(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/Function.png"));
static GUI::Icon variable_icon(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/Variable.png"));
static GUI::Icon preprocessor_icon(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/Preprocessor.png"));
static GUI::Icon member_icon(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/Member.png"));
static GUI::Icon namespace_icon(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/Namespace.png"));
static GUI::Icon struct_icon(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/Struct.png").release_value_but_fixme_should_propagate_errors());
static GUI::Icon class_icon(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/Class.png").release_value_but_fixme_should_propagate_errors());
static GUI::Icon function_icon(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/Function.png").release_value_but_fixme_should_propagate_errors());
static GUI::Icon variable_icon(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/Variable.png").release_value_but_fixme_should_propagate_errors());
static GUI::Icon preprocessor_icon(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/Preprocessor.png").release_value_but_fixme_should_propagate_errors());
static GUI::Icon member_icon(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/Member.png").release_value_but_fixme_should_propagate_errors());
static GUI::Icon namespace_icon(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/Namespace.png").release_value_but_fixme_should_propagate_errors());
switch (type) {
case GUI::AutocompleteProvider::DeclarationType::Struct:
return struct_icon;

View file

@ -50,8 +50,9 @@ RefPtr<ProjectTemplate> ProjectTemplate::load_from_manifest(const String& manife
auto bitmap_path_32 = String::formatted("/res/icons/hackstudio/templates-32x32/{}.png", config->read_entry("HackStudioTemplate", "IconName32x"));
if (Core::File::exists(bitmap_path_32)) {
auto bitmap32 = Gfx::Bitmap::try_load_from_file(bitmap_path_32);
icon = GUI::Icon(move(bitmap32));
auto bitmap_or_error = Gfx::Bitmap::try_load_from_file(bitmap_path_32);
if (!bitmap_or_error.is_error())
icon = GUI::Icon(bitmap_or_error.release_value());
}
return adopt_ref(*new ProjectTemplate(id, name, description, icon, priority));

View file

@ -43,7 +43,7 @@ int main(int argc, char** argv)
auto window = GUI::Window::construct();
window->resize(840, 600);
window->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-hack-studio.png"));
window->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-hack-studio.png").release_value_but_fixme_should_propagate_errors());
update_path_environment_variable();
@ -103,7 +103,7 @@ static bool make_is_available()
static void notify_make_not_available()
{
auto notification = GUI::Notification::construct();
notification->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/32x32/app-hack-studio.png"));
notification->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/32x32/app-hack-studio.png").release_value_but_fixme_should_propagate_errors());
notification->set_title("'make' Not Available");
notification->set_text("You probably want to install the binutils, gcc, and make ports from the root of the Serenity repository");
notification->show();