Skip to content

Commit

Permalink
Fix editor Save As confirmation, prevent opening empty filename
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
Robyt3 committed Sep 21, 2024
1 parent b34edb6 commit a3d0831
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/game/editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5353,20 +5353,25 @@ 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;
else if(m_pfnFileDialogFunc == &CallbackSaveCopyMap)
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);
}
}
}

Expand Down

0 comments on commit a3d0831

Please sign in to comment.