Skip to content

Commit

Permalink
Select matching entry in editor file dialog when saving file
Browse files Browse the repository at this point in the history
Also scroll to the entry with the matching filename when opening the editor file dialog for saving instead of only when the filename input is changed.
  • Loading branch information
Robyt3 committed Dec 29, 2024
1 parent f8b3515 commit 58cf997
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions src/game/editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5158,6 +5158,10 @@ void CEditor::RenderFileDialog()
Ui()->DoLabel(&PathBox, aBuf, 10.0f, TEXTALIGN_ML);
}

// filebox
static CListBox s_ListBox;
s_ListBox.SetActive(!Ui()->IsPopupOpen());

const auto &&UpdateFileNameInput = [this]() {
if(m_FilesSelectedIndex >= 0 && !m_vpFilteredFileList[m_FilesSelectedIndex]->m_IsDir)
{
Expand All @@ -5168,10 +5172,22 @@ void CEditor::RenderFileDialog()
else
m_FileDialogFileNameInput.Clear();
};

// filebox
static CListBox s_ListBox;
s_ListBox.SetActive(!Ui()->IsPopupOpen());
const auto &&UpdateSelectedIndex = [&]() {
m_FilesSelectedIndex = -1;
m_aFilesSelectedName[0] = '\0';
// find first valid entry, if it exists
for(size_t i = 0; i < m_vpFilteredFileList.size(); i++)
{
if(str_comp_nocase(m_vpFilteredFileList[i]->m_aName, m_FileDialogFileNameInput.GetString()) == 0)
{
m_FilesSelectedIndex = i;
str_copy(m_aFilesSelectedName, m_vpFilteredFileList[i]->m_aName);
break;
}
}
if(m_FilesSelectedIndex >= 0)
s_ListBox.ScrollToSelected();
};

if(m_FileDialogSaveAction)
{
Expand All @@ -5187,24 +5203,17 @@ void CEditor::RenderFileDialog()
--i;
}
}
m_FilesSelectedIndex = -1;
m_aFilesSelectedName[0] = '\0';
// find first valid entry, if it exists
for(size_t i = 0; i < m_vpFilteredFileList.size(); i++)
{
if(str_comp_nocase(m_vpFilteredFileList[i]->m_aName, m_FileDialogFileNameInput.GetString()) == 0)
{
m_FilesSelectedIndex = i;
str_copy(m_aFilesSelectedName, m_vpFilteredFileList[i]->m_aName);
break;
}
}
if(m_FilesSelectedIndex >= 0)
s_ListBox.ScrollToSelected();
UpdateSelectedIndex();
}

if(m_FileDialogOpening)
{
Ui()->SetActiveItem(&m_FileDialogFileNameInput);
if(!m_FileDialogFileNameInput.IsEmpty())
{
UpdateSelectedIndex();
}
}
}
else
{
Expand Down

0 comments on commit 58cf997

Please sign in to comment.