GME
13
|
00001 #include "stdafx.h" 00002 #include "GMEStd.h" 00003 #include "DynMenu.h" 00004 00006 00007 CDynMenu::CDynMenu(int iden, TCHAR* nm) : id(iden), name(nm) 00008 { 00009 menu.CreatePopupMenu(); 00010 minID = maxID = -1; 00011 } 00012 00013 CDynMenu::~CDynMenu() 00014 { 00015 } 00016 00017 void CDynMenu::AddItem(int id, CString&& roleName, CString&& displayName, CString&& helpMsg) 00018 { 00019 if(minID < 0) 00020 minID = id; 00021 maxID = id; 00022 std::unique_ptr<CDynMenuItem> item(new CDynMenuItem(id, std::move(roleName), std::move(displayName), std::move(helpMsg))); 00023 items.push_back(std::move(item)); 00024 } 00025 00026 void CDynMenu::Sort() 00027 { 00028 std::sort(items.begin(), items.end(), 00029 [](const std::unique_ptr<CDynMenuItem>& a, const std::unique_ptr<CDynMenuItem>& b) 00030 { return a->GetLabel() < b->GetLabel(); } 00031 ); 00032 for (auto it = items.begin(); it != items.end(); it++) 00033 { 00034 menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, (**it).id, (**it).displayName); 00035 } 00036 } 00037 00038 CDynMenuItem* CDynMenu::FindItem(int id) 00039 { 00040 for (auto it = items.begin(); it != items.end(); it++) { 00041 CDynMenuItem* item = it->get(); 00042 if(item->id == id) 00043 return item; 00044 } 00045 return 0; 00046 }