本文整理汇总了C++中Vec::InsertAt方法的典型用法代码示例。如果您正苦于以下问题:C++ Vec::InsertAt方法的具体用法?C++ Vec::InsertAt怎么用?C++ Vec::InsertAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vec
的用法示例。
在下文中一共展示了Vec::InsertAt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AppendFavMenus
// For easy access, we try to show favorites in the menu, similar to a list of
// recently opened files.
// The first menu items are for currently opened file (up to MAX_FAV_MENUS), based
// on the assumption that user is usually interested in navigating current file.
// Then we have a submenu for each file for which there are bookmarks (up to
// MAX_FAV_SUBMENUS), each having up to MAX_FAV_MENUS menu items.
// If not all favorites can be shown, we also enable "Show all favorites" menu which
// will provide a way to see all favorites.
// Note: not sure if that's the best layout. Maybe we should always use submenu and
// put the submenu for current file as the first one (potentially named as "Current file"
// or some such, to make it stand out from other submenus)
static void AppendFavMenus(HMENU m, const WCHAR* currFilePath) {
// To minimize mouse movement when navigating current file via favorites
// menu, put favorites for current file first
DisplayState* currFileFav = nullptr;
if (currFilePath) {
currFileFav = gFavorites.GetFavByFilePath(currFilePath);
}
// sort the files with favorites by base file name of file path
Vec<const WCHAR*> filePathsSorted;
if (HasPermission(Perm_DiskAccess)) {
// only show favorites for other files, if we're allowed to open them
GetSortedFilePaths(filePathsSorted, currFileFav);
}
if (currFileFav && currFileFav->favorites->size() > 0) {
filePathsSorted.InsertAt(0, currFileFav->filePath);
}
if (filePathsSorted.size() == 0) {
return;
}
AppendMenu(m, MF_SEPARATOR, 0, nullptr);
gFavorites.ResetMenuIds();
UINT menuId = IDM_FAV_FIRST;
size_t menusCount = filePathsSorted.size();
if (menusCount > MAX_FAV_MENUS) {
menusCount = MAX_FAV_MENUS;
}
for (size_t i = 0; i < menusCount; i++) {
const WCHAR* filePath = filePathsSorted.at(i);
DisplayState* f = gFavorites.GetFavByFilePath(filePath);
CrashIf(!f);
HMENU sub = m;
bool combined = (f->favorites->size() == 1);
if (!combined) {
sub = CreateMenu();
}
AppendFavMenuItems(sub, f, menuId, combined, f == currFileFav);
if (!combined) {
if (f == currFileFav) {
AppendMenu(m, MF_POPUP | MF_STRING, (UINT_PTR)sub, _TR("Current file"));
} else {
AutoFreeW tmp;
tmp.SetCopy(path::GetBaseName(filePath));
auto fileName = win::menu::ToSafeString(tmp);
AppendMenuW(m, MF_POPUP | MF_STRING, (UINT_PTR)sub, fileName);
}
}
}
}
示例2: AppendFavMenus
// For easy access, we try to show favorites in the menu, similar to a list of
// recently opened files.
// The first menu items are for currently opened file (up to MAX_FAV_MENUS), based
// on the assumption that user is usually interested in navigating current file.
// Then we have a submenu for each file for which there are bookmarks (up to
// MAX_FAV_SUBMENUS), each having up to MAX_FAV_MENUS menu items.
// If not all favorites can be shown, we also enable "Show all favorites" menu which
// will provide a way to see all favorites.
// Note: not sure if that's the best layout. Maybe we should always use submenu and
// put the submenu for current file as the first one (potentially named as "Current file"
// or some such, to make it stand out from other submenus)
static void AppendFavMenus(HMENU m, const WCHAR *currFilePath)
{
// To minimize mouse movement when navigating current file via favorites
// menu, put favorites for current file first
DisplayState *currFileFav = NULL;
if (currFilePath) {
currFileFav = gFavorites.GetFavByFilePath(currFilePath);
}
// sort the files with favorites by base file name of file path
Vec<const WCHAR *> filePathsSorted;
if (HasPermission(Perm_DiskAccess)) {
// only show favorites for other files, if we're allowed to open them
GetSortedFilePaths(filePathsSorted, currFileFav);
}
if (currFileFav)
filePathsSorted.InsertAt(0, currFileFav->filePath);
if (filePathsSorted.Count() == 0)
return;
AppendMenu(m, MF_SEPARATOR, 0, NULL);
gFavorites.ResetMenuIds();
UINT menuId = IDM_FAV_FIRST;
size_t menusCount = filePathsSorted.Count();
if (menusCount > MAX_FAV_MENUS)
menusCount = MAX_FAV_MENUS;
for (size_t i = 0; i < menusCount; i++) {
const WCHAR *filePath = filePathsSorted.At(i);
DisplayState *f = gFavorites.GetFavByFilePath(filePath);
HMENU sub = m;
bool combined = (f->favorites->Count() == 1);
if (!combined)
sub = CreateMenu();
AppendFavMenuItems(sub, f, menuId, combined, f == currFileFav);
if (!combined) {
if (f == currFileFav) {
AppendMenu(m, MF_POPUP | MF_STRING, (UINT_PTR)sub, _TR("Current file"));
} else {
const WCHAR *fileName = path::GetBaseName(filePath);
ScopedMem<WCHAR> s(win::menu::ToSafeString(fileName));
AppendMenu(m, MF_POPUP | MF_STRING, (UINT_PTR)sub, s);
}
}
}
}