mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:57:43 +00:00
FontEditor: Add a "Save as..." menu item
This commit is contained in:
parent
03e722f664
commit
315dc8d81b
3 changed files with 25 additions and 6 deletions
|
@ -219,12 +219,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::Font>&& edite
|
||||||
save_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
save_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
||||||
save_button.set_preferred_size(80, 0);
|
save_button.set_preferred_size(80, 0);
|
||||||
save_button.set_text("Save");
|
save_button.set_text("Save");
|
||||||
save_button.on_click = [this](auto) {
|
save_button.on_click = [this](auto) { save_as(m_path); };
|
||||||
auto ret_val = m_edited_font->write_to_file(m_path);
|
|
||||||
if (!ret_val) {
|
|
||||||
GUI::MessageBox::show("The font file could not be saved.", "Save failed", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
auto& quit_button = bottom_container.add<GUI::Button>();
|
auto& quit_button = bottom_container.add<GUI::Button>();
|
||||||
quit_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
quit_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
||||||
|
@ -296,3 +291,14 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::Font>&& edite
|
||||||
FontEditorWidget::~FontEditorWidget()
|
FontEditorWidget::~FontEditorWidget()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FontEditorWidget::save_as(const String& path)
|
||||||
|
{
|
||||||
|
auto ret_val = m_edited_font->write_to_file(path);
|
||||||
|
if (!ret_val) {
|
||||||
|
GUI::MessageBox::show("The font file could not be saved.", "Save failed", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
m_path = path;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -40,6 +40,10 @@ public:
|
||||||
int preferred_width() { return m_preferred_width; }
|
int preferred_width() { return m_preferred_width; }
|
||||||
int preferred_height() { return m_preferred_height; }
|
int preferred_height() { return m_preferred_height; }
|
||||||
|
|
||||||
|
bool save_as(const String&);
|
||||||
|
|
||||||
|
const String& path() { return m_path; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FontEditorWidget(const String& path, RefPtr<Gfx::Font>&&);
|
FontEditorWidget(const String& path, RefPtr<Gfx::Font>&&);
|
||||||
RefPtr<Gfx::Font> m_edited_font;
|
RefPtr<Gfx::Font> m_edited_font;
|
||||||
|
|
|
@ -105,6 +105,15 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
set_edited_font(open_path.value(), move(new_font), window->position());
|
set_edited_font(open_path.value(), move(new_font), window->position());
|
||||||
}));
|
}));
|
||||||
|
app_menu.add_action(GUI::Action::create("Save as...", { Mod_Ctrl | Mod_Shift, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [&](auto&) {
|
||||||
|
FontEditorWidget* editor = static_cast<FontEditorWidget*>(window->main_widget());
|
||||||
|
Optional<String> save_path = GUI::FilePicker::get_save_filepath(editor->path(), ".font");
|
||||||
|
if (!save_path.has_value())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (editor->save_as(save_path.value()))
|
||||||
|
window->set_title(String::format("%s - Font Editor", save_path.value().characters()));
|
||||||
|
}));
|
||||||
app_menu.add_separator();
|
app_menu.add_separator();
|
||||||
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) {
|
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) {
|
||||||
app->quit();
|
app->quit();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue