Extract SSelectionPopupContext::Reset to reduce duplicate code

This commit is contained in:
Robert Müller 2022-11-26 13:55:15 +01:00
parent e2fd30f7d3
commit 3ba51c476f
3 changed files with 11 additions and 8 deletions

View file

@ -3872,8 +3872,7 @@ int CEditor::PopupImage(CEditor *pEditor, CUIRect View, void *pContext)
{
char aFilename[IO_MAX_PATH_LENGTH];
str_format(aFilename, sizeof(aFilename), "%s.png", pImg->m_aName);
s_SelectionPopupContext.m_pSelection = nullptr;
s_SelectionPopupContext.m_Entries.clear();
s_SelectionPopupContext.Reset();
pEditor->Storage()->FindFiles(aFilename, "mapres", IStorage::TYPE_ALL, &s_SelectionPopupContext.m_Entries);
if(s_SelectionPopupContext.m_Entries.empty())
{
@ -3897,8 +3896,7 @@ int CEditor::PopupImage(CEditor *pEditor, CUIRect View, void *pContext)
bool WasExternal = pImg->m_External;
ReplaceImage(s_SelectionPopupContext.m_pSelection->c_str(), IStorage::TYPE_ALL, pEditor);
pImg->m_External = WasExternal;
s_SelectionPopupContext.m_pSelection = nullptr;
s_SelectionPopupContext.m_Entries.clear();
s_SelectionPopupContext.Reset();
return 1;
}
@ -3939,8 +3937,7 @@ int CEditor::PopupSound(CEditor *pEditor, CUIRect View, void *pContext)
{
char aFilename[IO_MAX_PATH_LENGTH];
str_format(aFilename, sizeof(aFilename), "%s.opus", pSound->m_aName);
s_SelectionPopupContext.m_pSelection = nullptr;
s_SelectionPopupContext.m_Entries.clear();
s_SelectionPopupContext.Reset();
pEditor->Storage()->FindFiles(aFilename, "mapres", IStorage::TYPE_ALL, &s_SelectionPopupContext.m_Entries);
if(s_SelectionPopupContext.m_Entries.empty())
{
@ -3962,8 +3959,7 @@ int CEditor::PopupSound(CEditor *pEditor, CUIRect View, void *pContext)
if(s_SelectionPopupContext.m_pSelection != nullptr)
{
ReplaceSound(s_SelectionPopupContext.m_pSelection->c_str(), IStorage::TYPE_ALL, pEditor);
s_SelectionPopupContext.m_pSelection = nullptr;
s_SelectionPopupContext.m_Entries.clear();
s_SelectionPopupContext.Reset();
return 1;
}

View file

@ -1148,6 +1148,7 @@ public:
const std::string *m_pSelection;
SSelectionPopupContext();
void Reset();
};
static int PopupSelection(CEditor *pEditor, CUIRect View, void *pContext);
void ShowPopupSelection(float X, float Y, SSelectionPopupContext *pContext);

View file

@ -1903,8 +1903,14 @@ void CEditor::ShowPopupMessage(float X, float Y, SMessagePopupContext *pContext)
}
CEditor::SSelectionPopupContext::SSelectionPopupContext()
{
Reset();
}
void CEditor::SSelectionPopupContext::Reset()
{
m_pSelection = nullptr;
m_Entries.clear();
}
int CEditor::PopupSelection(CEditor *pEditor, CUIRect View, void *pContext)