mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:07:46 +00:00
FontEditor: Simplify start-up
Previusly a cloned or newly loaded font was moved twice from main to the constructor and then from constructor to an init routine where it was finally used. The unmasked font is now moved only once, directly to initialization, and redundant error checking is discarded.
This commit is contained in:
parent
56a8a2b493
commit
922e80e72b
4 changed files with 20 additions and 34 deletions
|
@ -34,35 +34,24 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
args_parser.add_positional_argument(path, "The font file for editing.", "file", Core::ArgsParser::Required::No);
|
||||
args_parser.parse(arguments);
|
||||
|
||||
RefPtr<Gfx::BitmapFont> edited_font;
|
||||
if (path == nullptr) {
|
||||
auto bitmap_font = static_ptr_cast<Gfx::BitmapFont>(Gfx::FontDatabase::default_font().clone());
|
||||
edited_font = static_ptr_cast<Gfx::BitmapFont>(bitmap_font->unmasked_character_set());
|
||||
} else {
|
||||
auto bitmap_font = Gfx::BitmapFont::load_from_file(path);
|
||||
if (!bitmap_font) {
|
||||
String message = String::formatted("Couldn't load font: {}\n", path);
|
||||
GUI::MessageBox::show(nullptr, message, "Font Editor", GUI::MessageBox::Type::Error);
|
||||
return 1;
|
||||
}
|
||||
edited_font = static_ptr_cast<Gfx::BitmapFont>(bitmap_font->unmasked_character_set());
|
||||
if (!edited_font) {
|
||||
String message = String::formatted("Couldn't load font: {}\n", path);
|
||||
GUI::MessageBox::show(nullptr, message, "Font Editor", GUI::MessageBox::Type::Error);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
auto app_icon = GUI::Icon::default_icon("app-font-editor");
|
||||
|
||||
auto window = TRY(GUI::Window::try_create());
|
||||
window->set_icon(app_icon.bitmap_for_size(16));
|
||||
window->resize(440, 470);
|
||||
|
||||
auto& font_editor = window->set_main_widget<FontEditorWidget>(path, move(edited_font));
|
||||
|
||||
auto& font_editor = window->set_main_widget<FontEditorWidget>();
|
||||
font_editor.initialize_menubar(*window);
|
||||
|
||||
if (path) {
|
||||
auto success = font_editor.open_file(path);
|
||||
if (!success)
|
||||
return 1;
|
||||
} else {
|
||||
auto mutable_font = static_ptr_cast<Gfx::BitmapFont>(Gfx::FontDatabase::default_font().clone())->unmasked_character_set();
|
||||
font_editor.initialize({}, move(mutable_font));
|
||||
}
|
||||
|
||||
window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision {
|
||||
if (font_editor.request_close())
|
||||
return GUI::Window::CloseRequestDecision::Close;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue