📄 favoritesmenu.h
字号:
#pragma once
#include "ExplorerMenu.h"
#include <map>
// for debug
#ifdef _DEBUG
const bool _Mtl_FavoritesMenu_traceOn = true;
#define fvmTRACE if (_Mtl_FavoritesMenu_traceOn) ATLTRACE
#else
#define fvmTRACE
#endif
#define EMS_ORDER_FAVORITES 0x00010000L
#define EMS_USER_DEFINED_FOLDER 0x00040000L
template <class T>
class CFavoritesMenu : public CExplorerMenuImpl<T>
{
public:
typedef CExplorerMenuImpl<T> baseClass;
typedef CFavoritesMenu<T> thisClass;
// Ctor/Dtor
CFavoritesMenu(int nInsertPointMenuItemID, const CString& strNoEntries = _T("(empty)"),
int nMinID = 0x7000, int nMaxID = 0x7FFF,
const CString& strAdditional = _T("Open This Directory"),int nMaxMenuItemTextLength = 55)
: CExplorerMenuImpl<T>(nInsertPointMenuItemID, strNoEntries, nMinID, nMaxID, strAdditional, nMaxMenuItemTextLength)
{
}
// Overrides
void OnMenuItemInitialUpdate(const CString& strDirPath, CSimpleArray<CMenuItemInfo>& infos)
{
fvmTRACE(_T("CFavoritesMenu::OnMenuItemInitialUpdate\n"));
if (_check_flag(EMS_ORDER_FAVORITES, GetStyle()) && !_check_flag(EMS_USER_DEFINED_FOLDER, GetStyle())) {
fvmTRACE(_T(" try to order favorites\n"));
CFavoritesOrder order;
MtlGetFavoritesOrder(order, strDirPath);
std::sort(_begin(infos), _end(infos), _FavoritesMenuItemCompare(order, this));
}
else{
fvmTRACE(_T(" default order\n"));
baseClass::OnMenuItemInitialUpdate(strDirPath, infos);
}
}
struct _FavoritesMenuItemCompare : public std::binary_function<const CMenuItemInfo&, const CMenuItemInfo&, bool>
{
CSimpleMapInt<CString>& _order;
baseClass* _pBase;
_FavoritesMenuItemCompare(CSimpleMapInt<CString>& order, baseClass* pBase) : _order(order), _pBase(pBase)
{
}
bool operator()(const CMenuItemInfo& x, const CMenuItemInfo& y)
{
CString strPathA = _pBase->_GetFilePath(x);
CString strPathB = _pBase->_GetFilePath(y);
CString strA = MtlGetFileName(strPathA);
CString strB = MtlGetFileName(strPathB);
// ATLTRACE(_T("strA(%s), strB(%s)\n"), strA, strB);
const int enough = 10000;
bool bDirA = MtlIsDirectoryPath(strPathA);
bool bDirB = MtlIsDirectoryPath(strPathB);
int itA = _order.Lookup(strA);
int itB = _order.Lookup(strB);
if (itA == -1 || itA == FAVORITESORDER_NOTFOUND)// fixed by fub, thanks.
itA = enough;
if (itB == -1 || itB == FAVORITESORDER_NOTFOUND)
itB = enough;
if (itA == enough && itB == enough) {
if (bDirA == bDirB) {
return strA < strB;
}
else {
if (bDirA)
return true;
else
return false;
}
}
else
return itA < itB;
}
CString _GetFileName(const CMenuItemInfo& mii)
{
CString str = _pBase->m_mapID.Lookup(mii.wID);
if (str.IsEmpty()) {// popup menu = folder
str = mii.dwTypeData;
}
else {
str = MtlGetDisplayTextFromPath(str);
}
return str;
}
FILETIME _GetFileTime(const CString& strPath_)
{
CString strPath(strPath_);
MtlRemoveTrailingBackSlash(strPath);
WIN32_FIND_DATA data;
HANDLE h = ::FindFirstFile(strPath, &data);
ATLASSERT(h != INVALID_HANDLE_VALUE);
::FindClose(h);
return data.ftCreationTime;
}
};
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -