diff --git a/radiant/ui/materials/editor/MaterialEditor.cpp b/radiant/ui/materials/editor/MaterialEditor.cpp index 0038fbfb1c..c71779c332 100644 --- a/radiant/ui/materials/editor/MaterialEditor.cpp +++ b/radiant/ui/materials/editor/MaterialEditor.cpp @@ -348,7 +348,7 @@ void MaterialEditor::_onReloadImages(wxCommandEvent& ev) _material->refreshImageMaps(); } -void MaterialEditor::_onClose(wxCommandEvent& ev) +bool MaterialEditor::okToCloseDialog() { // Check all unsaved materials std::list modifiedMaterials; @@ -367,12 +367,27 @@ void MaterialEditor::_onClose(wxCommandEvent& ev) // Prompt user to save or discard if (!askUserAboutModifiedMaterial()) { - return; // cancel the close event + return false; // cancel the close event } } // At this point, everything is saved - EndModal(wxID_CLOSE); + return true; +} + +bool MaterialEditor::_onDeleteEvent() +{ + // Return true if preClose() vetoes the close event + return !okToCloseDialog(); +} + +void MaterialEditor::_onClose(wxCommandEvent& ev) +{ + // Check if it's ok to close the dialog + if (okToCloseDialog()) + { + EndModal(wxID_CLOSE); + } } void MaterialEditor::ShowDialog(const cmd::ArgumentList& args) diff --git a/radiant/ui/materials/editor/MaterialEditor.h b/radiant/ui/materials/editor/MaterialEditor.h index 1f8d559fe8..40974573c8 100644 --- a/radiant/ui/materials/editor/MaterialEditor.h +++ b/radiant/ui/materials/editor/MaterialEditor.h @@ -100,10 +100,15 @@ class MaterialEditor : static void ShowDialog(const cmd::ArgumentList& args); - void _onClose(wxCommandEvent& ev); - void _onReloadImages(wxCommandEvent& ev); +protected: + // Intercept close commands from pressing ESC keys + bool _onDeleteEvent() override; private: + // Asks user to save each unmodified material. + // Returns true if it is safe to go ahead and close the dialog + bool okToCloseDialog(); + void setupBasicMaterialPage(); void setupMaterialTreeView(); void setupMaterialStageView(); @@ -196,6 +201,8 @@ class MaterialEditor : void _onBasicAddFrobStages(wxCommandEvent& ev); void _onBasicRemoveFrobStages(wxCommandEvent& ev); void _onBasicTestFrobStages(wxMouseEvent& ev); + void _onClose(wxCommandEvent& ev); + void _onReloadImages(wxCommandEvent& ev); void toggleSelectedStage(); void onMaterialChanged();