[Debugger] Alphabetize script lists (#2174)

This commit is contained in:
shyguyhex 2022-01-20 17:23:21 -06:00 committed by GitHub
parent 93740c612f
commit 9e99ef1855
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 35 deletions

View File

@ -423,8 +423,8 @@ LRESULT CDebugScripts::OnConsoleClear(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /
LRESULT CDebugScripts::OnRefreshList(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
int nIndex = m_ScriptList.GetSelectedIndex();
CPath searchPath(m_ScriptsDir.c_str(), "*");
strlist fileNames;
if (!searchPath.FindFirst(CPath::FIND_ATTRIBUTE_FILES))
{
@ -432,22 +432,27 @@ LRESULT CDebugScripts::OnRefreshList(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*
return FALSE;
}
do
{
if (searchPath.GetExtension() == "js")
{
fileNames.push_back(searchPath.GetNameExtension());
}
} while (searchPath.FindNext());
fileNames.sort([](stdstr a, stdstr b) {
return a.ToLower() < b.ToLower();
});
m_ScriptList.SetRedraw(false);
m_ScriptList.DeleteAllItems();
size_t nItem = 0;
do
int nItem = 0;
for (const stdstr& fileName : fileNames)
{
if (searchPath.GetExtension() != "js")
{
continue;
}
JSInstanceStatus status = m_Debugger->ScriptSystem()->GetStatus(fileName.c_str());
const wchar_t* statusIcon = L"";
stdstr scriptFileName = searchPath.GetNameExtension();
JSInstanceStatus status = m_Debugger->ScriptSystem()->GetStatus(scriptFileName.c_str());
const wchar_t *statusIcon = L"";
switch (status)
{
case JS_STATUS_STARTING:
@ -460,11 +465,11 @@ LRESULT CDebugScripts::OnRefreshList(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*
statusIcon = L"-";
break;
}
m_ScriptList.AddItem(nItem, 0, statusIcon);
m_ScriptList.SetItemText(nItem, 1, scriptFileName.ToUTF16().c_str());
m_ScriptList.SetItemText(nItem, 1, fileName.ToUTF16().c_str());
nItem++;
} while (searchPath.FindNext());
}
m_ScriptList.SetRedraw(true);
m_ScriptList.Invalidate();

View File

@ -132,29 +132,38 @@ LRESULT CScriptsAutorunDlg::OnRefreshScriptList(UINT /*uMsg*/, WPARAM /*wParam*/
return 0;
}
m_ScriptListView.SetRedraw(false);
m_ScriptListView.DeleteAllItems();
size_t nItem = 0;
strlist fileNames;
do
{
stdstr scriptFileName = searchPath.GetNameExtension();
stdstr fileName = searchPath.GetNameExtension();
if (searchPath.GetExtension() == "js" &&
m_ScriptSystem->AutorunList().count(scriptFileName) == 0)
m_ScriptSystem->AutorunList().count(fileName) == 0)
{
m_ScriptListView.AddItem(nItem, 0, scriptFileName.ToUTF16().c_str());
if (scriptFileName == m_InitSelectedScriptName)
{
nSelectedItem = nItem;
m_bScriptListNeedsRefocus = true;
m_InitSelectedScriptName = "";
}
nItem++;
fileNames.push_back(searchPath.GetNameExtension());
}
} while (searchPath.FindNext());
fileNames.sort([](stdstr a, stdstr b) {
return a.ToLower() < b.ToLower();
});
m_ScriptListView.SetRedraw(false);
m_ScriptListView.DeleteAllItems();
int nItem = 0;
for (const stdstr& fileName : fileNames)
{
m_ScriptListView.AddItem(nItem, 0, fileName.ToUTF16().c_str());
if (fileName == m_InitSelectedScriptName)
{
nSelectedItem = nItem;
m_bScriptListNeedsRefocus = true;
m_InitSelectedScriptName = "";
}
nItem++;
}
m_ScriptListView.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
int itemCount = m_ScriptListView.GetItemCount();
@ -178,16 +187,19 @@ LRESULT CScriptsAutorunDlg::OnRefreshAutorunList(UINT /*uMsg*/, WPARAM /*wParam*
{
int nSelectedItem = m_AutorunListView.GetSelectedIndex();
strlist fileNames(m_ScriptSystem->AutorunList().begin(), m_ScriptSystem->AutorunList().end());
fileNames.sort([](stdstr a, stdstr b) {
return a.ToLower() < b.ToLower();
});
m_AutorunListView.SetRedraw(FALSE);
m_AutorunListView.DeleteAllItems();
int nItem = 0;
std::set<std::string>& scripts = m_ScriptSystem->AutorunList();
std::set<std::string>::iterator it;
for (it = scripts.begin(); it != scripts.end(); it++)
for (const stdstr& fileName : fileNames)
{
m_AutorunListView.AddItem(nItem, 0, stdstr(*it).ToUTF16().c_str());
if (*it == m_InitSelectedScriptName)
m_AutorunListView.AddItem(nItem, 0, fileName.ToUTF16().c_str());
if (fileName == m_InitSelectedScriptName)
{
nSelectedItem = nItem;
m_bAutorunListNeedsRefocus = true;