Browse Source

HexEditor: Prompt the user to save changes when opening a file

Gunnar Beutner 4 years ago
parent
commit
b246221eac
1 changed files with 8 additions and 0 deletions
  1. 8 0
      Userland/Applications/HexEditor/HexEditorWidget.cpp

+ 8 - 0
Userland/Applications/HexEditor/HexEditorWidget.cpp

@@ -92,6 +92,14 @@ HexEditorWidget::HexEditorWidget()
         if (!open_path.has_value())
         if (!open_path.has_value())
             return;
             return;
 
 
+        if (m_document_dirty) {
+            auto save_document_first_result = GUI::MessageBox::show(window(), "Save changes to current document first?", "Warning", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel);
+            if (save_document_first_result == GUI::Dialog::ExecResult::ExecYes)
+                m_save_action->activate();
+            if (save_document_first_result != GUI::Dialog::ExecResult::ExecNo && m_document_dirty)
+                return;
+        }
+
         open_file(open_path.value());
         open_file(open_path.value());
     });
     });