📄 panelitems.cpp
字号:
NCOM::CPropVariant propVariant;
_folder->GetProperty(i, kpidAttrib, &propVariant);
UInt32 attributes = 0;
if (propVariant.vt == VT_UI4)
attributes = propVariant.ulVal;
else
{
if (IsItemFolder(i))
attributes |= FILE_ATTRIBUTE_DIRECTORY;
}
bool defined = false;
if (folderGetSystemIconIndex)
{
folderGetSystemIconIndex->GetSystemIconIndex(i, &item.iImage);
defined = (item.iImage > 0);
}
if (!defined)
{
if (_currentFolderPrefix.IsEmpty())
{
int iconIndexTemp;
GetRealIconIndex(itemName + WCHAR_PATH_SEPARATOR, attributes, iconIndexTemp);
item.iImage = iconIndexTemp;
}
else
{
item.iImage = _extToIconMap.GetIconIndex(attributes, itemName);
}
}
if (item.iImage < 0)
item.iImage = 0;
if(_listView.InsertItem(&item) == -1)
return; // error
}
// OutputDebugStringA("End2\n");
if(_listView.GetItemCount() > 0 && cursorIndex >= 0)
SetFocusedSelectedItem(cursorIndex, selectFocused);
_listView.SortItems(CompareItems, (LPARAM)this);
if (cursorIndex < 0 && _listView.GetItemCount() > 0)
{
if (focusedPos >= _listView.GetItemCount())
focusedPos = _listView.GetItemCount() - 1;
SetFocusedSelectedItem(focusedPos, showDots);
}
// m_RedrawEnabled = true;
_listView.EnsureVisible(_listView.GetFocusedItem(), false);
_listView.SetRedraw(true);
_listView.InvalidateRect(NULL, true);
// OutputDebugStringA("End1\n");
/*
_listView.UpdateWindow();
*/
}
void CPanel::GetSelectedItemsIndices(CRecordVector<UInt32> &indices) const
{
indices.Clear();
/*
int itemIndex = -1;
while ((itemIndex = _listView.GetNextItem(itemIndex, LVNI_SELECTED)) != -1)
{
LPARAM param;
if (_listView.GetItemParam(itemIndex, param))
indices.Add(param);
}
*/
for (int i = 0; i < _selectedStatusVector.Size(); i++)
if (_selectedStatusVector[i])
indices.Add(i);
HeapSort(&indices.Front(), indices.Size());
}
void CPanel::GetOperatedItemIndices(CRecordVector<UInt32> &indices) const
{
GetSelectedItemsIndices(indices);
if (!indices.IsEmpty())
return;
if (_listView.GetSelectedCount() == 0)
return;
int focusedItem = _listView.GetFocusedItem();
if (focusedItem >= 0)
{
if(_listView.GetItemState(focusedItem, LVIS_SELECTED) == LVIS_SELECTED)
{
int realIndex = GetRealItemIndex(focusedItem);
if (realIndex != kParentIndex)
indices.Add(realIndex);
}
}
}
void CPanel::GetAllItemIndices(CRecordVector<UInt32> &indices) const
{
indices.Clear();
UInt32 numItems;
if (_folder->GetNumberOfItems(&numItems) == S_OK)
for (UInt32 i = 0; i < numItems; i++)
indices.Add(i);
}
void CPanel::GetOperatedIndicesSmart(CRecordVector<UInt32> &indices) const
{
GetOperatedItemIndices(indices);
if (indices.IsEmpty() || (indices.Size() == 1 && indices[0] == (UInt32)(Int32)-1))
GetAllItemIndices(indices);
}
/*
void CPanel::GetOperatedListViewIndices(CRecordVector<UInt32> &indices) const
{
indices.Clear();
int numItems = _listView.GetItemCount();
for (int i = 0; i < numItems; i++)
{
int realIndex = GetRealItemIndex(i);
if (realIndex >= 0)
if (_selectedStatusVector[realIndex])
indices.Add(i);
}
if (indices.IsEmpty())
{
int focusedItem = _listView.GetFocusedItem();
if (focusedItem >= 0)
indices.Add(focusedItem);
}
}
*/
void CPanel::EditItem()
{
int focusedItem = _listView.GetFocusedItem();
if (focusedItem < 0)
return;
int realIndex = GetRealItemIndex(focusedItem);
if (realIndex == kParentIndex)
return;
if (!IsItemFolder(realIndex))
EditItem(realIndex);
}
void CPanel::OpenFocusedItemAsInternal()
{
int focusedItem = _listView.GetFocusedItem();
if (focusedItem < 0)
return;
int realIndex = GetRealItemIndex(focusedItem);
if (IsItemFolder(realIndex))
OpenFolder(realIndex);
else
OpenItem(realIndex, true, false);
}
void CPanel::OpenSelectedItems(bool tryInternal)
{
CRecordVector<UInt32> indices;
GetOperatedItemIndices(indices);
if (indices.Size() > 20)
{
MessageBoxErrorLang(IDS_TOO_MANY_ITEMS, 0x02000606);
return;
}
int focusedItem = _listView.GetFocusedItem();
if (focusedItem >= 0)
{
int realIndex = GetRealItemIndex(focusedItem);
if (realIndex == kParentIndex && (tryInternal || indices.Size() == 0) &&
_listView.GetItemState(focusedItem, LVIS_SELECTED) == LVIS_SELECTED)
indices.Insert(0, realIndex);
}
bool dirIsStarted = false;
for(int i = 0; i < indices.Size(); i++)
{
UInt32 index = indices[i];
// CFileInfo &aFile = m_Files[index];
if (IsItemFolder(index))
{
if (!dirIsStarted)
{
if (tryInternal)
{
OpenFolder(index);
dirIsStarted = true;
break;
}
else
OpenFolderExternal(index);
}
}
else
OpenItem(index, (tryInternal && indices.Size() == 1), true);
}
}
UString CPanel::GetItemName(int itemIndex) const
{
if (itemIndex == kParentIndex)
return L"..";
NCOM::CPropVariant propVariant;
if (_folder->GetProperty(itemIndex, kpidName, &propVariant) != S_OK)
throw 2723400;
if (propVariant.vt != VT_BSTR)
throw 2723401;
return (propVariant.bstrVal);
}
UString CPanel::GetItemPrefix(int itemIndex) const
{
if (itemIndex == kParentIndex)
return UString();
NCOM::CPropVariant propVariant;
if (_folder->GetProperty(itemIndex, kpidPrefix, &propVariant) != S_OK)
throw 2723400;
UString prefix;
if (propVariant.vt == VT_BSTR)
prefix = propVariant.bstrVal;
return prefix;
}
UString CPanel::GetItemRelPath(int itemIndex) const
{
return GetItemPrefix(itemIndex) + GetItemName(itemIndex);
}
bool CPanel::IsItemFolder(int itemIndex) const
{
if (itemIndex == kParentIndex)
return true;
NCOM::CPropVariant propVariant;
if (_folder->GetProperty(itemIndex, kpidIsDir, &propVariant) != S_OK)
throw 2723400;
if (propVariant.vt == VT_BOOL)
return VARIANT_BOOLToBool(propVariant.boolVal);
if (propVariant.vt == VT_EMPTY)
return false;
return false;
}
UINT64 CPanel::GetItemSize(int itemIndex) const
{
if (itemIndex == kParentIndex)
return 0;
NCOM::CPropVariant propVariant;
if (_folder->GetProperty(itemIndex, kpidSize, &propVariant) != S_OK)
throw 2723400;
if (propVariant.vt == VT_EMPTY)
return 0;
return ConvertPropVariantToUInt64(propVariant);
}
void CPanel::ReadListViewInfo()
{
_typeIDString = GetFolderTypeID();
if (!_typeIDString.IsEmpty())
::ReadListViewInfo(_typeIDString, _listViewInfo);
}
void CPanel::SaveListViewInfo()
{
int i;
for(i = 0; i < _visibleProperties.Size(); i++)
{
CItemProperty &property = _visibleProperties[i];
LVCOLUMN winColumnInfo;
winColumnInfo.mask = LVCF_ORDER | LVCF_WIDTH;
if (!_listView.GetColumn(i, &winColumnInfo))
throw 1;
property.Order = winColumnInfo.iOrder;
property.Width = winColumnInfo.cx;
}
CListViewInfo viewInfo;
// PROPID sortPropID = _properties[_sortIndex].ID;
PROPID sortPropID = _sortID;
_visibleProperties.Sort();
for(i = 0; i < _visibleProperties.Size(); i++)
{
const CItemProperty &property = _visibleProperties[i];
CColumnInfo columnInfo;
columnInfo.IsVisible = property.IsVisible;
columnInfo.PropID = property.ID;
columnInfo.Width = property.Width;
viewInfo.Columns.Add(columnInfo);
}
for(i = 0; i < _properties.Size(); i++)
{
const CItemProperty &property = _properties[i];
if (!property.IsVisible)
{
CColumnInfo columnInfo;
columnInfo.IsVisible = property.IsVisible;
columnInfo.PropID = property.ID;
columnInfo.Width = property.Width;
viewInfo.Columns.Add(columnInfo);
}
}
// viewInfo.SortIndex = viewInfo.FindColumnWithID(sortPropID);
viewInfo.SortID = sortPropID;
viewInfo.Ascending = _ascending;
if (!_listViewInfo.IsEqual(viewInfo))
{
::SaveListViewInfo(_typeIDString, viewInfo);
_listViewInfo = viewInfo;
}
}
bool CPanel::OnRightClick(LPNMITEMACTIVATE itemActiveate, LRESULT &result)
{
if(itemActiveate->hdr.hwndFrom == HWND(_listView))
return false;
POINT point;
::GetCursorPos(&point);
CMenu menu;
CMenuDestroyer menuDestroyer(menu);
menu.CreatePopup();
const int kCommandStart = 100;
for(int i = 0; i < _properties.Size(); i++)
{
const CItemProperty &property = _properties[i];
UINT flags = MF_STRING;
if (property.IsVisible)
flags |= MF_CHECKED;
if (i == 0)
flags |= MF_GRAYED;
menu.AppendItem(flags, kCommandStart + i, GetSystemString(property.Name));
}
int menuResult = menu.Track(TPM_LEFTALIGN | TPM_RETURNCMD | TPM_NONOTIFY,
point.x, point.y, _listView);
if (menuResult >= kCommandStart && menuResult <= kCommandStart + _properties.Size())
{
int index = menuResult - kCommandStart;
CItemProperty &property = _properties[index];
property.IsVisible = !property.IsVisible;
if (property.IsVisible)
{
int prevVisibleSize = _visibleProperties.Size();
property.Order = prevVisibleSize;
_visibleProperties.Add(property);
InsertColumn(prevVisibleSize);
}
else
{
int visibleIndex = _visibleProperties.FindItemWithID(property.ID);
_visibleProperties.Delete(visibleIndex);
/*
if (_sortIndex == index)
{
_sortIndex = 0;
_ascending = true;
}
*/
if (_sortID == property.ID)
{
_sortID = kpidName;
_ascending = true;
}
_listView.DeleteColumn(visibleIndex);
}
}
result = TRUE;
return true;
}
void CPanel::OnReload()
{
RefreshListCtrlSaveFocused();
OnRefreshStatusBar();
}
void CPanel::OnTimer()
{
if (!_processTimer)
return;
CMyComPtr<IFolderWasChanged> folderWasChanged;
if (_folder.QueryInterface(IID_IFolderWasChanged, &folderWasChanged) != S_OK)
return;
INT32 wasChanged;
if (folderWasChanged->WasChanged(&wasChanged) != S_OK)
return;
if (wasChanged == 0)
return;
OnReload();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -