mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:57:44 +00:00
LibGfx+Userland: Make Gfx::SystemTheme propagate errors
This patch introduces error propagation to Gfx::SystemTheme to remove instances of release_value_but_fixme_should_propagate_errors(). Userland applications that have been affected by this change have been updated to utilise this propagation and as a result 4 such instances of the aforementioned method have been removed.
This commit is contained in:
parent
bdd9bc16de
commit
806a55eda1
15 changed files with 64 additions and 39 deletions
|
@ -19,9 +19,11 @@ ThemePreviewWidget::ThemePreviewWidget(Gfx::Palette const& palette)
|
|||
set_fixed_size(304, 201);
|
||||
}
|
||||
|
||||
void ThemePreviewWidget::set_theme(DeprecatedString path)
|
||||
ErrorOr<void> ThemePreviewWidget::set_theme(DeprecatedString path)
|
||||
{
|
||||
set_theme_from_file(*Core::File::open(path, Core::OpenMode::ReadOnly).release_value_but_fixme_should_propagate_errors());
|
||||
auto config_file = TRY(Core::File::open(path, Core::OpenMode::ReadOnly));
|
||||
TRY(set_theme_from_file(config_file));
|
||||
return {};
|
||||
}
|
||||
|
||||
void ThemePreviewWidget::paint_preview(GUI::PaintEvent&)
|
||||
|
|
|
@ -18,7 +18,7 @@ class ThemePreviewWidget final : public GUI::AbstractThemePreview {
|
|||
C_OBJECT(ThemePreviewWidget);
|
||||
|
||||
public:
|
||||
void set_theme(DeprecatedString path);
|
||||
ErrorOr<void> set_theme(DeprecatedString path);
|
||||
|
||||
private:
|
||||
explicit ThemePreviewWidget(Gfx::Palette const& palette);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/ConnectionToWindowServer.h>
|
||||
#include <LibGUI/ItemListModel.h>
|
||||
#include <LibGUI/MessageBox.h>
|
||||
#include <LibGUI/Process.h>
|
||||
|
||||
namespace DisplaySettings {
|
||||
|
@ -21,7 +22,7 @@ ThemesSettingsWidget::ThemesSettingsWidget(bool& background_settings_changed)
|
|||
: m_background_settings_changed { background_settings_changed }
|
||||
{
|
||||
load_from_gml(themes_settings_gml);
|
||||
m_themes = Gfx::list_installed_system_themes();
|
||||
m_themes = MUST(Gfx::list_installed_system_themes());
|
||||
|
||||
size_t current_theme_index;
|
||||
auto current_theme_name = GUI::ConnectionToWindowServer::the().get_system_theme();
|
||||
|
@ -39,7 +40,10 @@ ThemesSettingsWidget::ThemesSettingsWidget(bool& background_settings_changed)
|
|||
m_themes_combo->set_model(*GUI::ItemListModel<DeprecatedString>::create(m_theme_names));
|
||||
m_themes_combo->on_change = [this](auto&, const GUI::ModelIndex& index) {
|
||||
m_selected_theme = &m_themes.at(index.row());
|
||||
m_theme_preview->set_theme(m_selected_theme->path);
|
||||
auto set_theme_result = m_theme_preview->set_theme(m_selected_theme->path);
|
||||
if (set_theme_result.is_error()) {
|
||||
GUI::MessageBox::show_error(window(), DeprecatedString::formatted("There was an error generating the theme preview: {}", set_theme_result.error()));
|
||||
}
|
||||
set_modified(true);
|
||||
};
|
||||
m_themes_combo->set_selected_index(current_theme_index, GUI::AllowCallback::No);
|
||||
|
@ -66,7 +70,10 @@ ThemesSettingsWidget::ThemesSettingsWidget(bool& background_settings_changed)
|
|||
if (current_theme_name == theme_meta.name) {
|
||||
m_themes_combo->set_selected_index(index, GUI::AllowCallback::No);
|
||||
m_selected_theme = &m_themes.at(index);
|
||||
m_theme_preview->set_theme(m_selected_theme->path);
|
||||
auto set_theme_result = m_theme_preview->set_theme(m_selected_theme->path);
|
||||
if (set_theme_result.is_error()) {
|
||||
GUI::MessageBox::show_error(window(), DeprecatedString::formatted("There was an error setting the new theme: {}", set_theme_result.error()));
|
||||
}
|
||||
}
|
||||
++index;
|
||||
}
|
||||
|
|
|
@ -208,7 +208,11 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
|
|||
auto response = FileSystemAccessClient::Client::the().try_open_file(&window, "Select theme file", "/res/themes"sv);
|
||||
if (response.is_error())
|
||||
return;
|
||||
load_from_file(*response.value());
|
||||
auto load_from_file_result = load_from_file(*response.value());
|
||||
if (load_from_file_result.is_error()) {
|
||||
GUI::MessageBox::show_error(&window, DeprecatedString::formatted("Can't open file named {}: {}", response.value()->filename(), load_from_file_result.error()));
|
||||
return;
|
||||
}
|
||||
})));
|
||||
|
||||
m_save_action = GUI::CommonActions::make_save_action([&](auto&) {
|
||||
|
@ -557,10 +561,10 @@ void MainWidget::show_path_picker_dialog(StringView property_display_name, GUI::
|
|||
path_input.set_text(*result);
|
||||
}
|
||||
|
||||
void MainWidget::load_from_file(Core::File& file)
|
||||
ErrorOr<void> MainWidget::load_from_file(Core::File& file)
|
||||
{
|
||||
auto config_file = Core::ConfigFile::open(file.filename(), file.leak_fd()).release_value_but_fixme_should_propagate_errors();
|
||||
auto theme = Gfx::load_system_theme(config_file);
|
||||
auto config_file = TRY(Core::ConfigFile::open(file.filename(), file.leak_fd()));
|
||||
auto theme = TRY(Gfx::load_system_theme(config_file));
|
||||
VERIFY(theme.is_valid());
|
||||
|
||||
auto new_palette = Gfx::Palette(Gfx::PaletteImpl::create_with_anonymous_buffer(theme));
|
||||
|
@ -599,6 +603,7 @@ void MainWidget::load_from_file(Core::File& file)
|
|||
|
||||
m_last_modified_time = Time::now_monotonic();
|
||||
window()->set_modified(false);
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ public:
|
|||
ErrorOr<void> initialize_menubar(GUI::Window&);
|
||||
GUI::Window::CloseRequestDecision request_close();
|
||||
void update_title();
|
||||
void load_from_file(Core::File&);
|
||||
ErrorOr<void> load_from_file(Core::File&);
|
||||
|
||||
private:
|
||||
MainWidget();
|
||||
|
|
|
@ -160,7 +160,10 @@ void PreviewWidget::drop_event(GUI::DropEvent& event)
|
|||
auto response = FileSystemAccessClient::Client::the().try_request_file(window(), urls.first().path(), Core::OpenMode::ReadOnly);
|
||||
if (response.is_error())
|
||||
return;
|
||||
set_theme_from_file(*response.value());
|
||||
|
||||
auto set_theme_from_file_result = set_theme_from_file(response.release_value());
|
||||
if (set_theme_from_file_result.is_error())
|
||||
GUI::MessageBox::show_error(window(), DeprecatedString::formatted("Setting theme from file has failed: {}", set_theme_from_file_result.error()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,8 +56,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window, path.value());
|
||||
if (response.is_error())
|
||||
GUI::MessageBox::show_error(window, DeprecatedString::formatted("Opening \"{}\" failed: {}", path.value(), response.error()));
|
||||
else
|
||||
main_widget->load_from_file(response.release_value());
|
||||
else {
|
||||
auto load_from_file_result = main_widget->load_from_file(response.release_value());
|
||||
if (load_from_file_result.is_error())
|
||||
GUI::MessageBox::show_error(window, DeprecatedString::formatted("Loading theme from file has failed: {}", load_from_file_result.error()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue