summaryrefslogtreecommitdiff
path: root/Userland/Applications/FontEditor/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Applications/FontEditor/main.cpp')
-rw-r--r--Userland/Applications/FontEditor/main.cpp31
1 files changed, 10 insertions, 21 deletions
diff --git a/Userland/Applications/FontEditor/main.cpp b/Userland/Applications/FontEditor/main.cpp
index 41dfae7798..8b197ead91 100644
--- a/Userland/Applications/FontEditor/main.cpp
+++ b/Userland/Applications/FontEditor/main.cpp
@@ -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;