mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:17:34 +00:00
Playground: Add a menu action to save the file
There was already 'Save As' and now we also have 'Save'.
This commit is contained in:
parent
de84b3fa1c
commit
c2ae25967a
1 changed files with 19 additions and 4 deletions
|
@ -159,18 +159,32 @@ int main(int argc, char** argv)
|
||||||
auto menubar = GUI::Menubar::construct();
|
auto menubar = GUI::Menubar::construct();
|
||||||
auto& file_menu = menubar->add_menu("&File");
|
auto& file_menu = menubar->add_menu("&File");
|
||||||
|
|
||||||
auto save_action = GUI::CommonActions::make_save_as_action([&](auto&) {
|
auto save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) {
|
||||||
Optional<String> save_path = GUI::FilePicker::get_save_filepath(window, "Untitled", "gml");
|
Optional<String> new_save_path = GUI::FilePicker::get_save_filepath(window, "Untitled", "gml");
|
||||||
if (!save_path.has_value())
|
if (!new_save_path.has_value())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!editor.write_to_file(save_path.value())) {
|
if (!editor.write_to_file(new_save_path.value())) {
|
||||||
GUI::MessageBox::show(window, "Unable to save file.\n", "Error", GUI::MessageBox::Type::Error);
|
GUI::MessageBox::show(window, "Unable to save file.\n", "Error", GUI::MessageBox::Type::Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
file_path = new_save_path.value();
|
||||||
update_title();
|
update_title();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
auto save_action = GUI::CommonActions::make_save_action([&](auto&) {
|
||||||
|
if (!file_path.is_empty()) {
|
||||||
|
if (!editor.write_to_file(file_path)) {
|
||||||
|
GUI::MessageBox::show(window, "Unable to save file.\n", "Error", GUI::MessageBox::Type::Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
update_title();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
save_as_action->activate();
|
||||||
|
});
|
||||||
|
|
||||||
file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
|
file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
|
||||||
if (window->is_modified()) {
|
if (window->is_modified()) {
|
||||||
auto save_document_first_result = GUI::MessageBox::show(window, "Save changes to current document first?", "Warning", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel);
|
auto save_document_first_result = GUI::MessageBox::show(window, "Save changes to current document first?", "Warning", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel);
|
||||||
|
@ -202,6 +216,7 @@ int main(int argc, char** argv)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
file_menu.add_action(save_action);
|
file_menu.add_action(save_action);
|
||||||
|
file_menu.add_action(save_as_action);
|
||||||
file_menu.add_separator();
|
file_menu.add_separator();
|
||||||
|
|
||||||
file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) {
|
file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue