From 50c89933387ab8ae4a8a291f59ae7f61d3613317 Mon Sep 17 00:00:00 2001 From: codereader Date: Fri, 11 Jun 2021 06:56:00 +0200 Subject: [PATCH] #5634: Usability fixes: don't overwrite the shader clipboard if the material is already matching, otherwise we lose the texdef information of faces and patches. --- radiant/clipboard/ClipboardModule.cpp | 20 +++++++++++++++---- radiantcore/selection/clipboard/Clipboard.cpp | 8 +++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/radiant/clipboard/ClipboardModule.cpp b/radiant/clipboard/ClipboardModule.cpp index b031acef9d..5313159203 100644 --- a/radiant/clipboard/ClipboardModule.cpp +++ b/radiant/clipboard/ClipboardModule.cpp @@ -10,6 +10,19 @@ namespace ui { +namespace +{ + inline std::string getContentHash(const std::string& content) + { + // Inspect the clipboard when the main window regains focus + // and fire the event if the contents changed + math::Hash hash; + hash.addString(content); + + return hash; + } +} + std::string ClipboardModule::getString() { std::string returnValue; @@ -37,6 +50,8 @@ void ClipboardModule::setString(const std::string& str) wxTheClipboard->SetData(new wxTextDataObject(str)); wxTheClipboard->Close(); + _contentHash = getContentHash(str); + // Contents changed signal _sigContentsChanged.emit(); } @@ -77,10 +92,7 @@ void ClipboardModule::onAppActivated(wxActivateEvent& ev) { // Inspect the clipboard when the main window regains focus // and fire the event if the contents changed - math::Hash hash; - hash.addString(getString()); - - std::string newHash = hash; + auto newHash = getContentHash(getString()); if (newHash != _contentHash) { diff --git a/radiantcore/selection/clipboard/Clipboard.cpp b/radiantcore/selection/clipboard/Clipboard.cpp index 11cbfe0192..dfda4ee7fd 100644 --- a/radiantcore/selection/clipboard/Clipboard.cpp +++ b/radiantcore/selection/clipboard/Clipboard.cpp @@ -88,7 +88,13 @@ void paste(const cmd::ArgumentList& args) { UndoableCommand undo("pasteMaterialFromClipboard"); - GlobalShaderClipboard().setSourceShader(clipboardMaterial); + // Activate the material name in the shader clipboard, but don't overwrite + // anything there if the material is already matching to not overwrite Face/Patch information + if (GlobalShaderClipboard().getShaderName() != clipboardMaterial) + { + GlobalShaderClipboard().setSourceShader(clipboardMaterial); + } + algorithm::pasteShaderToSelection(args); return; }