mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:18:12 +00:00
FontEditor: Add FontEditorWidget::open_file() function
This part is also quite needed when opening files from drag-and-drop events.
This commit is contained in:
parent
72378fd36c
commit
a0cb8cfefd
2 changed files with 20 additions and 14 deletions
|
@ -172,20 +172,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
|
|||
if (!open_path.has_value())
|
||||
return;
|
||||
|
||||
auto bitmap_font = Gfx::BitmapFont::load_from_file(open_path.value());
|
||||
if (!bitmap_font) {
|
||||
String message = String::formatted("Couldn't load font: {}\n", open_path.value());
|
||||
GUI::MessageBox::show(window(), message, "Font Editor", GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
RefPtr<Gfx::BitmapFont> new_font = static_ptr_cast<Gfx::BitmapFont>(bitmap_font->unmasked_character_set());
|
||||
if (!new_font) {
|
||||
String message = String::formatted("Couldn't load font: {}\n", open_path.value());
|
||||
GUI::MessageBox::show(window(), message, "Font Editor", GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
window()->set_modified(false);
|
||||
initialize(open_path.value(), move(new_font));
|
||||
open_file(open_path.value());
|
||||
});
|
||||
m_save_action = GUI::CommonActions::make_save_action([&](auto&) {
|
||||
if (m_path.is_empty())
|
||||
|
@ -606,6 +593,24 @@ void FontEditorWidget::set_show_font_metadata(bool show)
|
|||
m_font_metadata_groupbox->set_visible(m_font_metadata);
|
||||
}
|
||||
|
||||
void FontEditorWidget::open_file(String const& path)
|
||||
{
|
||||
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(window(), message, "Font Editor", GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
RefPtr<Gfx::BitmapFont> new_font = static_ptr_cast<Gfx::BitmapFont>(bitmap_font->unmasked_character_set());
|
||||
if (!new_font) {
|
||||
String message = String::formatted("Couldn't load font: {}\n", path);
|
||||
GUI::MessageBox::show(window(), message, "Font Editor", GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
window()->set_modified(false);
|
||||
initialize(path, move(new_font));
|
||||
}
|
||||
|
||||
void FontEditorWidget::undo()
|
||||
{
|
||||
if (!m_undo_stack->can_undo())
|
||||
|
|
|
@ -37,6 +37,7 @@ public:
|
|||
private:
|
||||
FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&);
|
||||
|
||||
void open_file(String const&);
|
||||
void undo();
|
||||
void redo();
|
||||
void did_modify_font();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue