From 402c6aa985aee7eaac0d717ddeb574af2efba9f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 21 Sep 2024 18:17:09 +0200 Subject: [PATCH] Fix editor `Save As` confirmation, prevent opening empty filename The confirmation popup was not shown for the Save As dialog anymore, due to the label being changed to `Save As` for the respective quick action. This check based on string comparison is rather brittle and can be replaced with comparison of the storage type with `IStorage::TYPE_SAVE`. When the file dialog is used to open files, prevent opening files with an empty filename if enter is pressed while no file is selected (i.e. when the filter excludes all entries). --- src/game/editor/editor.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 04e1383f1..78ff54262 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -5466,7 +5466,8 @@ void CEditor::RenderFileDialog() str_format(m_aFileSaveName, sizeof(m_aFileSaveName), "%s/%s", m_pFileDialogPath, m_FileDialogFileNameInput.GetString()); if(!str_endswith(m_aFileSaveName, FILETYPE_EXTENSIONS[m_FileDialogFileType])) str_append(m_aFileSaveName, FILETYPE_EXTENSIONS[m_FileDialogFileType]); - if(!str_comp(m_pFileDialogButtonText, "Save") && Storage()->FileExists(m_aFileSaveName, StorageType)) + const bool SaveAction = m_FileDialogStorageType == IStorage::TYPE_SAVE; + if(SaveAction && Storage()->FileExists(m_aFileSaveName, StorageType)) { if(m_pfnFileDialogFunc == &CallbackSaveMap) m_PopupEventType = POPEVENT_SAVE; @@ -5474,12 +5475,16 @@ void CEditor::RenderFileDialog() m_PopupEventType = POPEVENT_SAVE_COPY; else if(m_pfnFileDialogFunc == &CallbackSaveImage) m_PopupEventType = POPEVENT_SAVE_IMG; - else + else if(m_pfnFileDialogFunc == &CallbackSaveSound) m_PopupEventType = POPEVENT_SAVE_SOUND; + else + dbg_assert(false, "m_pfnFileDialogFunc unhandled for saving"); m_PopupEventActivated = true; } - else if(m_pfnFileDialogFunc) + else if(m_pfnFileDialogFunc && (SaveAction || m_FilesSelectedIndex >= 0)) + { m_pfnFileDialogFunc(m_aFileSaveName, StorageType, m_pFileDialogUser); + } } }