<commit_before>#include "..\Inc\CRMenuManager.h"

MenuManager* MenuManager::ins = nullptr;
int MenuManager::mainMenu = -1;
int MenuManager::importModelMenu = -1;
vector<string> MenuManager::modelList;

MenuManager::MenuManager()
{
}

void MenuManager::InitMenu()
{
	mainMenu = glutCreateMenu(OnMainMenu);
	importModelMenu = glutCreateMenu(OnImportModelMenu);

	glutSetMenu(mainMenu);
	glutAddSubMenu("Import new model", importModelMenu);
	glutAddMenuEntry("Save current scene", 0);

	glutSetMenu(importModelMenu);
	glutAddMenuEntry("Update model list", 0);

	UpdateModelList();

	glutSetMenu(mainMenu);

	glutAttachMenu(GLUT_RIGHT_BUTTON);
}

void MenuManager::OnMainMenu(int value)
{
	switch (value)
	{
	case 0:
	{
		SceneManager::Instance()->SaveScene(ConfigManager::Instance()->GetScenePath());
	}
	break;
	default:
		break;
	}
}

void MenuManager::OnImportModelMenu(int value)
{
	switch (value)
	{
	case 0:
	{
		UpdateModelList();
	}
	break;
	default:
	{
		Object* newObj = new Object();
		SceneManager::Instance()->GetRootNode()->AddChild(newObj);

		string fileName = modelList[value - 1];
		int pos = fileName.find(".fbx");
		if (pos >= 0)
			fileName.erase(pos);

		FbxImportManager::Instance()->ImportFbxModel((char *)fileName.c_str(), newObj);
	}
	break;
	}
}

void MenuManager::UpdateModelList()
{
	glutSetMenu(importModelMenu);

	modelList.clear();
	int itemCount = glutGet(GLUT_MENU_NUM_ITEMS);
	for (int i = 1; i <= itemCount; i++)
		glutRemoveMenuItem(i);
	
	string path = "Resources\\Models";
	for (const auto & entry : directory_iterator(path))
	{
		if (strstr(entry.path().string().c_str(), ".fbx"))
		{
			modelList.emplace_back(entry.path().filename().string());
			string path = modelList[modelList.size() - 1];
			glutAddMenuEntry((const char*)path.c_str(), modelList.size());
		}
	}
}

MenuManager::~MenuManager()
{
}

MenuManager * MenuManager::Instance()
{
	if (ins == nullptr)
		ins = new MenuManager();

	return ins;
}<commit_msg>fix bug when updating model list in menu<commit_after>#include "..\Inc\CRMenuManager.h"

MenuManager* MenuManager::ins = nullptr;
int MenuManager::mainMenu = -1;
int MenuManager::importModelMenu = -1;
vector<string> MenuManager::modelList;

MenuManager::MenuManager()
{
}

void MenuManager::InitMenu()
{
	mainMenu = glutCreateMenu(OnMainMenu);
	importModelMenu = glutCreateMenu(OnImportModelMenu);

	glutSetMenu(mainMenu);
	glutAddSubMenu("Import new model", importModelMenu);
	glutAddMenuEntry("Save current scene", 0);

	glutSetMenu(importModelMenu);
	glutAddMenuEntry("Update model list", 0);

	UpdateModelList();

	glutSetMenu(mainMenu);

	glutAttachMenu(GLUT_RIGHT_BUTTON);
}

void MenuManager::OnMainMenu(int value)
{
	switch (value)
	{
	case 0:
	{
		SceneManager::Instance()->SaveScene(ConfigManager::Instance()->GetScenePath());
	}
	break;
	default:
		break;
	}
}

void MenuManager::OnImportModelMenu(int value)
{
	switch (value)
	{
	case 0:
	{
		UpdateModelList();
	}
	break;
	default:
	{
		Object* newObj = new Object();
		SceneManager::Instance()->GetRootNode()->AddChild(newObj);

		string fileName = modelList[value - 1];
		int pos = fileName.find(".fbx");
		if (pos >= 0)
			fileName.erase(pos);

		FbxImportManager::Instance()->ImportFbxModel((char *)fileName.c_str(), newObj);
	}
	break;
	}
}

void MenuManager::UpdateModelList()
{
	glutSetMenu(importModelMenu);

	modelList.clear();
	int itemCount = glutGet(GLUT_MENU_NUM_ITEMS);
	for (int i = 2; i <= itemCount; i++)
		glutRemoveMenuItem(2);

	itemCount = glutGet(GLUT_MENU_NUM_ITEMS);
	
	string path = "Resources\\Models";
	for (const auto & entry : directory_iterator(path))
	{
		if (strstr(entry.path().string().c_str(), ".fbx"))
		{
			modelList.emplace_back(entry.path().filename().string());
			string path = modelList[modelList.size() - 1];
			glutAddMenuEntry((const char*)path.c_str(), modelList.size());
		}
	}

	itemCount = glutGet(GLUT_MENU_NUM_ITEMS);
}

MenuManager::~MenuManager()
{
}

MenuManager * MenuManager::Instance()
{
	if (ins == nullptr)
		ins = new MenuManager();

	return ins;
}
{'fraction_non_alphanumeric': 0.1568627450980392, 'fraction_numerical': 0.0052122114668652275, 'mean_word_length': 5.5, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '908932', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1400, 'n_words': 257}