Merge pull request #9006 from Robyt3/Editor-File-Dialog-Fixes

Fix editor `Save As` confirmation, prevent opening empty filename
This commit is contained in:
Zwelf 2024-11-08 18:49:15 +00:00 committed by GitHub
commit 022f101c4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5466,7 +5466,8 @@ void CEditor::RenderFileDialog()
str_format(m_aFileSaveName, sizeof(m_aFileSaveName), "%s/%s", m_pFileDialogPath, m_FileDialogFileNameInput.GetString()); str_format(m_aFileSaveName, sizeof(m_aFileSaveName), "%s/%s", m_pFileDialogPath, m_FileDialogFileNameInput.GetString());
if(!str_endswith(m_aFileSaveName, FILETYPE_EXTENSIONS[m_FileDialogFileType])) if(!str_endswith(m_aFileSaveName, FILETYPE_EXTENSIONS[m_FileDialogFileType]))
str_append(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) if(m_pfnFileDialogFunc == &CallbackSaveMap)
m_PopupEventType = POPEVENT_SAVE; m_PopupEventType = POPEVENT_SAVE;
@ -5474,14 +5475,18 @@ void CEditor::RenderFileDialog()
m_PopupEventType = POPEVENT_SAVE_COPY; m_PopupEventType = POPEVENT_SAVE_COPY;
else if(m_pfnFileDialogFunc == &CallbackSaveImage) else if(m_pfnFileDialogFunc == &CallbackSaveImage)
m_PopupEventType = POPEVENT_SAVE_IMG; m_PopupEventType = POPEVENT_SAVE_IMG;
else else if(m_pfnFileDialogFunc == &CallbackSaveSound)
m_PopupEventType = POPEVENT_SAVE_SOUND; m_PopupEventType = POPEVENT_SAVE_SOUND;
else
dbg_assert(false, "m_pfnFileDialogFunc unhandled for saving");
m_PopupEventActivated = true; m_PopupEventActivated = true;
} }
else if(m_pfnFileDialogFunc) else if(m_pfnFileDialogFunc && (SaveAction || m_FilesSelectedIndex >= 0))
{
m_pfnFileDialogFunc(m_aFileSaveName, StorageType, m_pFileDialogUser); m_pfnFileDialogFunc(m_aFileSaveName, StorageType, m_pFileDialogUser);
} }
} }
}
ButtonBar.VSplitRight(ButtonSpacing, &ButtonBar, nullptr); ButtonBar.VSplitRight(ButtonSpacing, &ButtonBar, nullptr);
ButtonBar.VSplitRight(50.0f, &ButtonBar, &Button); ButtonBar.VSplitRight(50.0f, &ButtonBar, &Button);