1
0
mirror of https://github.com/winscp/winscp.git synced 2026-10-24 02:28:55 +03:00
Files
winscp/source/components/DirView.cpp
Martin Prikryl 674c6958ec Fixing local thumbnail bug introduced in c562d3d
Source commit: 31a0e0f30397a79acfac9cc9e20d62c792928716
2025-12-27 11:11:32 +01:00

121 lines
3.5 KiB
C++

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <Common.h>
#include "DirView.h"
#include "IEDriveInfo.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
__fastcall TDirView::TDirView(TComponent * AOwner) :
TDirViewInt(AOwner)
{
DriveInfoRequire();
}
//---------------------------------------------------------------------------
void __fastcall TDirView::IconUpdateClear()
{
FIconUpdateQueue = TIconUpdateQueue();
FIconUpdateQueueDeferred = TIconUpdateQueue();
FIconUpdateSet.clear();
}
//---------------------------------------------------------------------------
void __fastcall TDirView::IconUpdateEnqueue(TListItem * ListItem)
{
if (FIconUpdateSet.find(ListItem->Index) == FIconUpdateSet.end())
{
FIconUpdateSet.insert(ListItem->Index);
TIconUpdateSchedule Schedule { .Index = ListItem->Index };
FIconUpdateQueue.push(Schedule);
DebugAssert(FIconUpdateSet.size() == FIconUpdateQueue.size() + FIconUpdateQueueDeferred.size());
}
StartIconUpdateThread();
}
//---------------------------------------------------------------------------
int __fastcall TDirView::IconUpdatePeek()
{
int Result;
if (!FIconUpdateQueue.empty())
{
Result = FIconUpdateQueue.front().Index;
}
else if (!FIconUpdateQueueDeferred.empty())
{
Result = FIconUpdateQueueDeferred.front().Index;
}
else
{
Result = -1;
}
return Result;
}
//---------------------------------------------------------------------------
bool __fastcall TDirView::IconUpdateDeprioritize(Dirviewint::TFileRec * ItemData, int Index)
{
bool Result = !FIconUpdateQueue.empty();
if (Result)
{
DebugAssert(!ThumbnailNeeded(ItemData));
if (ItemData->IconEmpty)
{
TIconUpdateSchedule Schedule = FIconUpdateQueue.front();
FIconUpdateQueue.pop();
FIconUpdateQueueDeferred.push(Schedule);
}
else
{
IconUpdateDequeue(Index);
}
}
return Result;
}
//---------------------------------------------------------------------------
void __fastcall TDirView::IconUpdateDequeue(int Index)
{
if (!FIconUpdateQueue.empty())
{
FIconUpdateQueue.pop();
}
else
{
FIconUpdateQueueDeferred.pop();
}
FIconUpdateSet.erase(Index);
DebugAssert(FIconUpdateSet.size() == FIconUpdateQueue.size() + FIconUpdateQueueDeferred.size());
}
//---------------------------------------------------------------------------
void __fastcall TDirView::PathChanged()
{
TDirViewInt::PathChanged();
// make sure to use PathName as Path maybe just X: what
// ExpandFileName resolves to current working directory
// on the drive, not to root path
UnicodeString Expanded = ExpandFileName(PathName);
FLastPaths[DriveInfo->GetDriveKey(Expanded)] = Expanded;
}
//---------------------------------------------------------------------------
bool __fastcall TDirView::TryGetLastPath(UnicodeString Drive, UnicodeString & Path)
{
auto I = FLastPaths.find(Drive);
bool Result = (I != FLastPaths.end());
if (Result)
{
Path = I->second;
#ifndef DESIGN_ONLY
if (!DirectoryExists(ApiPath(Path)))
{
if (DriveInfo->IsRealDrive(Drive))
{
Path = FORMAT(L"%s:", (Drive));
}
else
{
Path = Drive;
}
}
#endif
}
return Result;
}