diff options
author | Andrew Weller <andrewweller.cs@gmail.com> | 2019-09-05 23:05:28 -0600 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-09-06 18:38:26 +0200 |
commit | 16aba5100d24e75d9867126c4ccab2862201f146 (patch) | |
tree | 839dc2597ca9707b249dcda985da625e223f2f2f | |
parent | 73fdbba59c6b91a0ef1789d3f37b703215ea7cef (diff) | |
download | serenity-16aba5100d24e75d9867126c4ccab2862201f146.zip |
TextEditor: Implement File/New Action
The user is asked if they want to save a dirty file before they create
a new one.
-rw-r--r-- | Applications/TextEditor/TextEditorWidget.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp index fce711454b..6cb7c98fff 100644 --- a/Applications/TextEditor/TextEditorWidget.cpp +++ b/Applications/TextEditor/TextEditorWidget.cpp @@ -116,8 +116,20 @@ TextEditorWidget::TextEditorWidget() statusbar->set_text(builder.to_string()); }; - m_new_action = GAction::create("New", { Mod_Ctrl, Key_N }, GraphicsBitmap::load_from_file("/res/icons/16x16/new.png"), [](const GAction&) { - dbgprintf("FIXME: Implement File/New\n"); + m_new_action = GAction::create("New", { Mod_Ctrl, Key_N }, GraphicsBitmap::load_from_file("/res/icons/16x16/new.png"), [this](const GAction&) { + if (m_document_dirty) { + GMessageBox save_document_first_box("Save Document First?", "Warning", GMessageBox::Type::Warning, GMessageBox::InputType::OKCancel, window()); + auto save_document_first_result = save_document_first_box.exec(); + + if (save_document_first_result != GDialog::ExecResult::ExecOK) + return; + m_save_action->activate(); + } + + m_document_dirty = false; + m_editor->set_text(StringView()); + set_path(FileSystemPath()); + update_title(); }); m_open_action = GAction::create("Open...", { Mod_Ctrl, Key_O }, GraphicsBitmap::load_from_file("/res/icons/16x16/open.png"), [this](const GAction&) { |