From 16aba5100d24e75d9867126c4ccab2862201f146 Mon Sep 17 00:00:00 2001 From: Andrew Weller Date: Thu, 5 Sep 2019 23:05:28 -0600 Subject: [PATCH] TextEditor: Implement File/New Action The user is asked if they want to save a dirty file before they create a new one. --- Applications/TextEditor/TextEditorWidget.cpp | 16 ++++++++++++++-- 1 file 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&) {