Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#5565: Prompt the user for every modified material on closing the dialog
  • Loading branch information
codereader committed Mar 28, 2021
1 parent a127ea4 commit 2175529
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
43 changes: 34 additions & 9 deletions radiant/ui/materials/editor/MaterialEditor.cpp
Expand Up @@ -218,6 +218,28 @@ int MaterialEditor::ShowModal()

void MaterialEditor::_onClose(wxCommandEvent& ev)
{
// Check all unsaved materials
std::list<MaterialPtr> modifiedMaterials;
GlobalMaterialManager().foreachMaterial([&](const MaterialPtr& material)
{
if (material->isModified())
{
modifiedMaterials.push_back(material);
}
});

for (const auto& material : modifiedMaterials)
{
selectMaterial(material);

// Prompt user to save or discard
if (!askUserAboutModifiedMaterial())
{
return; // cancel the close event
}
}

// At this point, everything is saved
EndModal(wxID_CLOSE);
}

Expand Down Expand Up @@ -1080,7 +1102,6 @@ void MaterialEditor::revertCurrentMaterial()

bool MaterialEditor::askUserAboutModifiedMaterial()
{
#if 0
// Get the original name
std::string origName = _material->getName();

Expand Down Expand Up @@ -1110,7 +1131,6 @@ bool MaterialEditor::askUserAboutModifiedMaterial()
return false; // user cancelled
}

#endif
// User doesn't want to save
return true;
}
Expand Down Expand Up @@ -1164,23 +1184,28 @@ void MaterialEditor::_onSaveMaterial(wxCommandEvent& ev)
// TODO
}

void MaterialEditor::_onNewMaterial(wxCommandEvent& ev)
void MaterialEditor::selectMaterial(const MaterialPtr& material)
{
auto materialName = "textures/darkmod/map_specific/unnamed";
auto newItem = _treeView->GetTreeModel()->FindString(material->getName(), _treeView->Columns().fullName);

auto newMaterial = GlobalMaterialManager().createEmptyMaterial(materialName);

auto newItem = _treeView->GetTreeModel()->FindString(newMaterial->getName(), _treeView->Columns().fullName);

if (newItem.IsOk())
{
_treeView->Select(newItem);
_treeView->EnsureVisible(newItem);
updateMaterialTreeItem();

handleMaterialSelectionChange();
updateMaterialTreeItem();
}
}

void MaterialEditor::_onNewMaterial(wxCommandEvent& ev)
{
auto materialName = "textures/darkmod/map_specific/unnamed";
auto newMaterial = GlobalMaterialManager().createEmptyMaterial(materialName);

selectMaterial(newMaterial);
}

void MaterialEditor::_onCopyMaterial(wxCommandEvent& ev)
{
if (!_material) return;
Expand Down
1 change: 1 addition & 0 deletions radiant/ui/materials/editor/MaterialEditor.h
Expand Up @@ -129,6 +129,7 @@ class MaterialEditor :
void updateMaterialPropertiesFromMaterial();

void selectStageByIndex(std::size_t index);
void selectMaterial(const MaterialPtr& material);
IShaderLayer::Ptr getSelectedStage();
IEditableShaderLayer::Ptr getEditableStageForSelection();

Expand Down

0 comments on commit 2175529

Please sign in to comment.