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

Applications+Demos+LibGUI: Migrate to fallible WizardDialogs and Pages

And port page text to String. Also removes WizardDialog::show() helper
as all current implementations prefer to derive their own Dialog.
This commit is contained in:
thankyouverycool 2023-06-08 07:46:11 -04:00 committed by Andreas Kling
parent 96e60c98cf
commit caa8f43dbe
12 changed files with 178 additions and 115 deletions

View file

@ -116,10 +116,13 @@ ErrorOr<void> MainWidget::create_actions()
m_new_action = GUI::Action::create("&New Font...", { Mod_Ctrl, Key_N }, g_resources.new_font, [this](auto&) {
if (!request_close())
return;
auto new_font_wizard = NewFontDialog::construct(window());
if (new_font_wizard->exec() != GUI::Dialog::ExecResult::OK)
auto maybe_wizard = NewFontDialog::create(window());
if (maybe_wizard.is_error())
return show_error(maybe_wizard.release_error(), "Creating font wizard failed"sv);
auto wizard = maybe_wizard.release_value();
if (wizard->exec() != GUI::Dialog::ExecResult::OK)
return;
auto maybe_font = new_font_wizard->create_font();
auto maybe_font = wizard->create_font();
if (maybe_font.is_error())
return show_error(maybe_font.release_error(), "Creating new font failed"sv);
if (auto result = initialize({}, move(maybe_font.value())); result.is_error())

View file

@ -122,13 +122,19 @@ private:
REGISTER_WIDGET(FontEditor, GlyphPreviewWidget);
NewFontDialog::NewFontDialog(GUI::Window* parent_window)
: GUI::WizardDialog(parent_window)
ErrorOr<NonnullRefPtr<NewFontDialog>> NewFontDialog::create(GUI::Window* parent_window)
{
set_title("New Font");
auto dialog = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) NewFontDialog(parent_window)));
TRY(dialog->build());
return dialog;
}
m_font_properties_page = GUI::WizardPage::construct("Typeface properties", "Edit details about this font.");
m_font_properties_page->body_widget().load_from_gml(new_font_dialog_page_1_gml).release_value_but_fixme_should_propagate_errors();
ErrorOr<void> NewFontDialog::build()
{
TRY(GUI::WizardDialog::build());
m_font_properties_page = TRY(GUI::WizardPage::create("Typeface properties"sv, "Edit details about this font."sv));
TRY(m_font_properties_page->body_widget().load_from_gml(new_font_dialog_page_1_gml));
m_name_textbox = m_font_properties_page->body_widget().find_descendant_of_type_named<GUI::TextBox>("name_textbox");
m_family_textbox = m_font_properties_page->body_widget().find_descendant_of_type_named<GUI::TextBox>("family_textbox");
@ -136,14 +142,16 @@ NewFontDialog::NewFontDialog(GUI::Window* parent_window)
m_slope_combobox = m_font_properties_page->body_widget().find_descendant_of_type_named<GUI::ComboBox>("slope_combobox");
m_presentation_spinbox = m_font_properties_page->body_widget().find_descendant_of_type_named<GUI::SpinBox>("presentation_spinbox");
TRY(m_font_weight_list.try_ensure_capacity(Gfx::font_weight_names.size()));
for (auto& it : Gfx::font_weight_names)
m_font_weight_list.append(it.name);
m_weight_combobox->set_model(*GUI::ItemListModel<DeprecatedString>::create(m_font_weight_list));
m_font_weight_list.unchecked_append(TRY(String::from_utf8(it.name)));
m_weight_combobox->set_model(TRY(GUI::ItemListModel<String>::try_create(m_font_weight_list)));
m_weight_combobox->set_selected_index(3);
TRY(m_font_slope_list.try_ensure_capacity(Gfx::font_slope_names.size()));
for (auto& it : Gfx::font_slope_names)
m_font_slope_list.append(it.name);
m_slope_combobox->set_model(*GUI::ItemListModel<DeprecatedString>::create(m_font_slope_list));
m_font_slope_list.unchecked_append(TRY(String::from_utf8(it.name)));
m_slope_combobox->set_model(TRY(GUI::ItemListModel<String>::try_create(m_font_slope_list)));
m_slope_combobox->set_selected_index(0);
m_presentation_spinbox->set_value(12);
@ -155,8 +163,8 @@ NewFontDialog::NewFontDialog(GUI::Window* parent_window)
return m_glyph_properties_page;
};
m_glyph_properties_page = GUI::WizardPage::construct("Glyph properties", "Edit details about this font.");
m_glyph_properties_page->body_widget().load_from_gml(new_font_dialog_page_2_gml).release_value_but_fixme_should_propagate_errors();
m_glyph_properties_page = TRY(GUI::WizardPage::create("Glyph properties"sv, "Edit details about this font."sv));
TRY(m_glyph_properties_page->body_widget().load_from_gml(new_font_dialog_page_2_gml));
m_glyph_properties_page->set_is_final_page(true);
m_glyph_height_spinbox = m_glyph_properties_page->body_widget().find_descendant_of_type_named<GUI::SpinBox>("height_spinbox");
@ -197,6 +205,15 @@ NewFontDialog::NewFontDialog(GUI::Window* parent_window)
};
push_page(*m_font_properties_page);
return {};
}
NewFontDialog::NewFontDialog(GUI::Window* parent_window)
: GUI::WizardDialog(parent_window)
{
set_title("New Font");
set_icon(parent_window->icon());
}
void NewFontDialog::save_metadata()

View file

@ -12,13 +12,17 @@
#include <LibGfx/Font/BitmapFont.h>
class NewFontDialog final : public GUI::WizardDialog {
C_OBJECT(NewFontDialog);
C_OBJECT_ABSTRACT(NewFontDialog);
public:
static ErrorOr<NonnullRefPtr<NewFontDialog>> create(GUI::Window* parent_window);
ErrorOr<NonnullRefPtr<Gfx::BitmapFont>> create_font();
private:
NewFontDialog(GUI::Window* parent_window);
explicit NewFontDialog(GUI::Window* parent_window);
virtual ErrorOr<void> build() override;
void save_metadata();
@ -51,6 +55,6 @@ private:
RefPtr<GUI::SpinBox> m_spacing_spinbox;
RefPtr<GUI::CheckBox> m_fixed_width_checkbox;
Vector<DeprecatedString> m_font_weight_list;
Vector<DeprecatedString> m_font_slope_list;
Vector<String> m_font_weight_list;
Vector<String> m_font_slope_list;
};

View file

@ -34,9 +34,10 @@ CSVExportDialogPage::CSVExportDialogPage(Sheet const& sheet)
{
m_headers.extend(m_data.take_first());
m_page = GUI::WizardPage::construct(
"CSV Export Options",
"Please select the options for the csv file you wish to export to");
m_page = GUI::WizardPage::create(
"CSV Export Options"sv,
"Please select the options for the csv file you wish to export to"sv)
.release_value_but_fixme_should_propagate_errors();
m_page->body_widget().load_from_gml(csv_export_gml).release_value_but_fixme_should_propagate_errors();
m_page->set_is_final_page(true);
@ -180,7 +181,7 @@ void CSVExportDialogPage::update_preview()
ErrorOr<void> ExportDialog::make_and_run_for(StringView mime, Core::File& file, DeprecatedString filename, Workbook& workbook)
{
auto wizard = GUI::WizardDialog::construct(GUI::Application::the()->active_window());
auto wizard = TRY(GUI::WizardDialog::create(GUI::Application::the()->active_window()));
wizard->set_title("File Export Wizard");
wizard->set_icon(GUI::Icon::default_icon("app-spreadsheet"sv).bitmap_for_size(16));
@ -213,9 +214,9 @@ ErrorOr<void> ExportDialog::make_and_run_for(StringView mime, Core::File& file,
} else if (mime == "application/x-sheets+json") {
return export_worksheet();
} else {
auto page = GUI::WizardPage::construct(
"Export File Format",
DeprecatedString::formatted("Select the format you wish to export to '{}' as", LexicalPath::basename(filename)));
auto page = TRY(GUI::WizardPage::create(
"Export File Format"sv,
TRY(String::formatted("Select the format you wish to export to '{}' as", LexicalPath::basename(filename)))));
page->on_next_page = [] { return nullptr; };

View file

@ -27,9 +27,10 @@ namespace Spreadsheet {
CSVImportDialogPage::CSVImportDialogPage(StringView csv)
: m_csv(csv)
{
m_page = GUI::WizardPage::construct(
"CSV Import Options",
"Please select the options for the csv file you wish to import");
m_page = GUI::WizardPage::create(
"CSV Import Options"sv,
"Please select the options for the csv file you wish to import"sv)
.release_value_but_fixme_should_propagate_errors();
m_page->body_widget().load_from_gml(csv_import_gml).release_value_but_fixme_should_propagate_errors();
m_page->set_is_final_page(true);
@ -178,7 +179,7 @@ void CSVImportDialogPage::update_preview()
ErrorOr<Vector<NonnullRefPtr<Sheet>>, DeprecatedString> ImportDialog::make_and_run_for(GUI::Window& parent, StringView mime, String const& filename, Core::File& file, Workbook& workbook)
{
auto wizard = GUI::WizardDialog::construct(&parent);
auto wizard = GUI::WizardDialog::create(&parent).release_value_but_fixme_should_propagate_errors();
wizard->set_title("File Import Wizard");
wizard->set_icon(GUI::Icon::default_icon("app-spreadsheet"sv).bitmap_for_size(16));
@ -244,9 +245,10 @@ ErrorOr<Vector<NonnullRefPtr<Sheet>>, DeprecatedString> ImportDialog::make_and_r
} else if (mime == "application/x-sheets+json") {
return import_worksheet();
} else {
auto page = GUI::WizardPage::construct(
"Import File Format",
DeprecatedString::formatted("Select the format you wish to import '{}' as", LexicalPath::basename(filename.to_deprecated_string())));
auto page = GUI::WizardPage::create(
"Import File Format"sv,
DeprecatedString::formatted("Select the format you wish to import '{}' as", LexicalPath::basename(filename.to_deprecated_string())))
.release_value_but_fixme_should_propagate_errors();
page->on_next_page = [] { return nullptr; };