Compress-Deflate7
view release on metacpan or search on metacpan
7zip/CPP/7zip/UI/FileManager/BrowseDialog.cpp view on Meta::CPAN
const CFileInfoW &f2 = _files[(int)lParam2];
bool isDir1 = f1.IsDir();
bool isDir2 = f2.IsDir();
if (isDir1 && !isDir2) return -1;
if (isDir2 && !isDir1) return 1;
int result = 0;
switch(_sortIndex)
{
case 0: result = f1.Name.CompareNoCase(f2.Name); break;
case 1: result = CompareFileTime(&f1.MTime, &f2.MTime); break;
case 2: result = MyCompare(f1.Size, f2.Size); break;
}
return _ascending ? result: (-result);
}
static int CALLBACK CompareItems2(LPARAM lParam1, LPARAM lParam2, LPARAM lpData)
{
if (lpData == NULL)
return 0;
return ((CBrowseDialog*)lpData)->CompareItems(lParam1, lParam2);
}
static HRESULT GetNormalizedError()
{
HRESULT errorCode = GetLastError();
return (errorCode == 0) ? 1 : errorCode;
}
HRESULT CBrowseDialog::Reload(const UString &pathPrefix, const UString &selectedName)
{
CEnumeratorW enumerator(pathPrefix + L'*');
CObjectVector<CFileInfoW> files;
for (;;)
{
bool found;
CFileInfoW fi;
if (!enumerator.Next(fi, found))
return GetNormalizedError();
if (!found)
break;
files.Add(fi);
}
Path = pathPrefix;
_files = files;
SetItemText(IDC_BROWSE_PATH, Path);
_list.SetRedraw(false);
_list.DeleteAllItems();
if (!Path.IsEmpty() && Path.Back() != WCHAR_PATH_SEPARATOR)
Path += WCHAR_PATH_SEPARATOR;
LVITEMW item;
int index = 0;
int cursorIndex = -1;
#ifndef _SFX
if (_showDots)
{
UString itemName = L"..";
item.iItem = index;
if (selectedName.IsEmpty())
cursorIndex = item.iItem;
item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
int subItem = 0;
item.iSubItem = subItem++;
item.lParam = kParentIndex;
item.pszText = (wchar_t *)(const wchar_t *)itemName;
item.iImage = _extToIconMap.GetIconIndex(FILE_ATTRIBUTE_DIRECTORY, Path);
if (item.iImage < 0)
item.iImage = 0;
_list.InsertItem(&item);
_list.SetSubItem(index, subItem++, L"");
_list.SetSubItem(index, subItem++, L"");
index++;
}
#endif
for (int i = 0; i < _files.Size(); i++)
{
const CFileInfoW &fi = _files[i];
item.iItem = index;
if (fi.Name.CompareNoCase(selectedName) == 0)
cursorIndex = item.iItem;
item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
int subItem = 0;
item.iSubItem = subItem++;
item.lParam = i;
item.pszText = (wchar_t *)(const wchar_t *)fi.Name;
item.iImage = _extToIconMap.GetIconIndex(fi.Attrib, Path + fi.Name);
if (item.iImage < 0)
item.iImage = 0;
_list.InsertItem(&item);
{
FILETIME ft;
UString s;
if (FileTimeToLocalFileTime(&fi.MTime, &ft))
s = ConvertFileTimeToString(ft, false, false);
_list.SetSubItem(index, subItem++, s);
}
{
UString s;
if (!fi.IsDir())
s = ConvertSizeToStringShort(fi.Size);
_list.SetSubItem(index, subItem++, s);
}
index++;
}
if (_list.GetItemCount() > 0 && cursorIndex >= 0)
_list.SetItemState_FocusedSelected(cursorIndex);
_list.SortItems(CompareItems2, (LPARAM)this);
if (_list.GetItemCount() > 0 && cursorIndex < 0)
_list.SetItemState(0, LVIS_FOCUSED, LVIS_FOCUSED);
_list.EnsureVisible(_list.GetFocusedItem(), false);
_list.SetRedraw(true);
return S_OK;
}
HRESULT CBrowseDialog::Reload()
{
UString selectedCur;
int index = _list.GetNextSelectedItem(-1);
if (index >= 0)
{
int fileIndex = GetRealItemIndex(index);
if (fileIndex != kParentIndex)
selectedCur = _files[fileIndex].Name;
}
return Reload(Path, selectedCur);
}
void CBrowseDialog::OpenParentFolder()
{
UString parent, selected;
if (GetParentPath(Path, parent, selected))
Reload(parent, selected);
}
extern UString HResultToMessage(HRESULT errorCode);
bool CBrowseDialog::OnNotify(UINT /* controlID */, LPNMHDR header)
{
if (header->hwndFrom != _list)
return false;
switch(header->code)
{
case LVN_ITEMACTIVATE:
if (g_LVN_ITEMACTIVATE_Support)
{
OnItemEnter();
return true;
}
break;
case NM_DBLCLK:
case NM_RETURN: // probabably it's unused
if (!g_LVN_ITEMACTIVATE_Support)
{
OnItemEnter();
return true;
}
break;
case LVN_COLUMNCLICK:
{
int index = LPNMLISTVIEW(header)->iSubItem;
if (index == _sortIndex)
_ascending = !_ascending;
else
{
_ascending = (index == 0);
_sortIndex = index;
}
Reload();
( run in 1.234 second using v1.01-cache-2.11-cpan-39bf76dae61 )