Skip to content

Commit

Permalink
#6049: Prompt the user whether to save unsaved modifications to mater…
Browse files Browse the repository at this point in the history
…ials when hitting ESC.
  • Loading branch information
codereader committed Aug 6, 2022
1 parent e285ae3 commit 8688743
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
21 changes: 18 additions & 3 deletions radiant/ui/materials/editor/MaterialEditor.cpp
Expand Up @@ -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<MaterialPtr> modifiedMaterials;
Expand All @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions radiant/ui/materials/editor/MaterialEditor.h
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 8688743

Please sign in to comment.