From 15fb1928fee56b28a8a64d119622401318dbbdce Mon Sep 17 00:00:00 2001 From: codereader Date: Sun, 28 Mar 2021 12:14:41 +0200 Subject: [PATCH] #5565: Discarding unsaved materials means to remove them again. --- install/ui/materialeditor.fbp | 832 ++++++++++-------- install/ui/materialeditor.xrc | 127 +-- .../ui/materials/editor/MaterialEditor.cpp | 23 +- 3 files changed, 528 insertions(+), 454 deletions(-) diff --git a/install/ui/materialeditor.fbp b/install/ui/materialeditor.fbp index 6460ccd990..d9bd1a138f 100644 --- a/install/ui/materialeditor.fbp +++ b/install/ui/materialeditor.fbp @@ -799,403 +799,455 @@ wxVERTICAL none - 6 - wxBOTTOM|wxEXPAND + 0 + wxEXPAND | wxALL 0 - - 2 - wxBOTH - 1 - - 6 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 - fgSizer182 - wxFLEX_GROWMODE_SPECIFIED - none - 0 - 6 - - 0 - wxALIGN_CENTER_VERTICAL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Name: - 0 - - 0 - - - 0 - - 1 - m_staticText61 - 1 - - - protected - 1 - - Resizable - 1 - - - ; ; forward_declare - 0 - - - - - -1 + 1 + MaterialNameAndDescription + 1 + + + protected + 1 + + Resizable + 1 + + ; ; forward_declare + 0 + + + + wxTAB_TRAVERSAL + + 2 + wxBOTH + 1 + + 6 + + fgSizer182 + wxFLEX_GROWMODE_SPECIFIED + none + 0 + 6 + + 0 + wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Name: + 0 + + 0 + + + 0 + + 1 + m_staticText61 + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + - - - 0 - wxEXPAND - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - - 0 - - 1 - MaterialName - 1 - - - protected - 1 - - Resizable - 1 - - wxTE_PROCESS_ENTER - ; ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - + + 0 + wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + + 1 + MaterialName + 1 + + + protected + 1 + + Resizable + 1 + + wxTE_PROCESS_ENTER + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + - - - 0 - wxALIGN_CENTER_VERTICAL|wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Material: - 0 - - 0 - - - 0 - - 1 - m_staticText571 - 1 - - - protected - 1 - - Resizable - 1 - - - ; ; forward_declare - 0 - - - - - -1 + + 0 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Material: + 0 + + 0 + + + 0 + + 1 + m_staticText571 + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + - - - 0 - wxEXPAND - 1 - - - bSizer71 - wxHORIZONTAL - none - - 12 - wxALIGN_CENTER_VERTICAL|wxRIGHT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - MaterialType - 1 - - - protected - 1 - - Resizable - 0 - 1 - - - ; ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - + + 0 + wxEXPAND + 1 + + + bSizer71 + wxHORIZONTAL + none + + 12 + wxALIGN_CENTER_VERTICAL|wxRIGHT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + MaterialType + 1 + + + protected + 1 + + Resizable + 0 + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + - - - 0 - wxALIGN_CENTER_VERTICAL|wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Description: - 0 - - 0 - - - 0 - - 1 - m_staticText57 - 1 - - - protected - 1 - - Resizable - 1 - - - ; ; forward_declare - 0 - - - - - -1 + + 0 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Description: + 0 + + 0 + + + 0 + + 1 + m_staticText57 + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + - - - 6 - wxEXPAND|wxLEFT - 1 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - - 0 - - 1 - MaterialDescription - 1 - - - protected - 1 - - Resizable - 1 - - wxTE_PROCESS_ENTER - ; ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - + + 6 + wxEXPAND|wxLEFT + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + + 1 + MaterialDescription + 1 + + + protected + 1 + + Resizable + 1 + + wxTE_PROCESS_ENTER + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + diff --git a/install/ui/materialeditor.xrc b/install/ui/materialeditor.xrc index 922098db16..b42e4faf87 100644 --- a/install/ui/materialeditor.xrc +++ b/install/ui/materialeditor.xrc @@ -134,73 +134,76 @@ wxVERTICAL - wxBOTTOM|wxEXPAND - 6 - - 0 - 2 - 6 - 6 - 1 - - - - wxALIGN_CENTER_VERTICAL - 0 - - - -1 + wxEXPAND | wxALL + 0 + + + + 0 + 2 + 6 + 6 + 1 + + + + wxALIGN_CENTER_VERTICAL + 0 + + + -1 + - - - - wxEXPAND - 0 - - - + + + wxEXPAND + 0 + + + + - - - - wxALIGN_CENTER_VERTICAL|wxALL - 0 - - - -1 + + + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + + -1 + - - - - wxEXPAND - 0 - - wxHORIZONTAL - - - wxALIGN_CENTER_VERTICAL|wxRIGHT - 12 - - 0 - + + + wxEXPAND + 0 + + wxHORIZONTAL + + + wxALIGN_CENTER_VERTICAL|wxRIGHT + 12 + + 0 + + - - - - wxALIGN_CENTER_VERTICAL|wxALL - 0 - - - -1 + + + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + + -1 + - - - - wxEXPAND|wxLEFT - 6 - - - + + + wxEXPAND|wxLEFT + 6 + + + + diff --git a/radiant/ui/materials/editor/MaterialEditor.cpp b/radiant/ui/materials/editor/MaterialEditor.cpp index f75f3b0a88..4c9dd6c150 100644 --- a/radiant/ui/materials/editor/MaterialEditor.cpp +++ b/radiant/ui/materials/editor/MaterialEditor.cpp @@ -1096,7 +1096,17 @@ void MaterialEditor::revertCurrentMaterial() { if (!_material) return; + if (_material->isModified() && _material->getShaderFileInfo().name.empty()) + { + // This material has been created and not been saved yet, + // discarding it means removing it + GlobalMaterialManager().removeMaterial(_material->getName()); + selectMaterial(MaterialPtr()); + return; + } + _material->revertModifications(); + onMaterialChanged(); } @@ -1147,7 +1157,7 @@ void MaterialEditor::handleMaterialSelectionChange() _materialChanged.disconnect(); // Update the preview if a texture is selected - if (!_treeView->IsDirectorySelected()) + if (_selectedMaterialItem.IsOk() && !_treeView->IsDirectorySelected()) { _material = GlobalMaterialManager().getMaterial(_treeView->GetSelectedFullname()); @@ -1181,11 +1191,18 @@ void MaterialEditor::_onSaveMaterial(wxCommandEvent& ev) { if (!_material) return; - // TODO + saveCurrentMaterial(); } void MaterialEditor::selectMaterial(const MaterialPtr& material) { + if (!material) + { + _treeView->UnselectAll(); + handleMaterialSelectionChange(); + return; + } + auto newItem = _treeView->GetTreeModel()->FindString(material->getName(), _treeView->Columns().fullName); if (newItem.IsOk()) @@ -1460,6 +1477,8 @@ void MaterialEditor::updateMaterialPropertiesFromMaterial() { util::ScopedBoolLock lock(_materialUpdateInProgress); + getControl("MaterialNameAndDescription")->Enable(_material != nullptr); + auto nameEntry = getControl("MaterialName"); nameEntry->Enable(_material != nullptr); nameEntry->SetValue(_material ? _material->getName() : "");