mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:27:45 +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:
parent
96e60c98cf
commit
caa8f43dbe
12 changed files with 178 additions and 115 deletions
|
@ -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())
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue