123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include <Common.h>
- #include "UnixDirView.h"
- #include "UnixDriveView.h"
- #include <FileCtrl.hpp>
- #ifndef DESIGN_ONLY
- #include <CoreMain.h>
- #include <Terminal.h>
- #include <WinConfiguration.h>
- #include <VCLCommon.h>
- #endif
- #pragma package(smart_init)
- #ifndef DESIGN_ONLY
- #define ITEMFILE ((TRemoteFile *)(Item->Data))
- // noop, previously this tested that the file was in terminal's file listing,
- // but that cannot be safely checked now the terminal is used in multithreaded
- // environment
- #define ASSERT_VALID_ITEM
- #endif
- //---------------------------------------------------------------------------
- static inline void ValidCtrCheck(TUnixDirView *)
- {
- new TUnixDirView(NULL);
- }
- //---------------------------------------------------------------------------
- namespace Unixdirview
- {
- void __fastcall PACKAGE Register()
- {
- TComponentClass classes[1] = {__classid(TUnixDirView)};
- RegisterComponents(L"Scp", classes, 0);
- }
- }
- //---------------------------------------------------------------------------
- #ifndef DESIGN_ONLY
- #define RFILE(N) ((TRemoteFile *)(Item ## N->Data))
- int __stdcall CompareDirectories(TListItem *Item1, TListItem *Item2)
- {
- // Because CompareDirectories is called from each other compare functions
- // it's sufficient to check pointers only here (see below)
- assert(Item1 && RFILE(1) && Item2 && RFILE(2));
- if (RFILE(1)->IsParentDirectory && !RFILE(2)->IsParentDirectory) return -1;
- else
- if (!RFILE(1)->IsParentDirectory && RFILE(2)->IsParentDirectory) return 1;
- else
- if (RFILE(1)->IsDirectory && !RFILE(2)->IsDirectory) return -1;
- else
- if (!RFILE(1)->IsDirectory && RFILE(2)->IsDirectory) return 1;
- else
- return 0;
- }
- //---------------------------------------------------------------------------
- #define DEFINE_COMPARE_FUNC_EX(PROPERTY, NAME, COMPAREFUNCFILE, COMPAREFUNCDIR, FALLBACK) \
- int __stdcall Compare ## NAME(TListItem *Item1, TListItem *Item2, TUnixDirView *DirView) \
- { \
- int Result = CompareDirectories(Item1, Item2); \
- if (!Result) \
- { \
- if (RFILE(1)->IsDirectory) \
- { \
- Result = COMPAREFUNCDIR(RFILE(1)->PROPERTY, RFILE(2)->PROPERTY); \
- } \
- else \
- { \
- Result = COMPAREFUNCFILE(RFILE(1)->PROPERTY, RFILE(2)->PROPERTY); \
- } \
- if (Result == 0) \
- { \
- Result = FALLBACK(RFILE(1)->FileName, RFILE(2)->FileName); \
- } \
- if (!DirView->UnixColProperties->SortAscending) Result = -Result; \
- } \
- return Result; \
- }
- #define DEFINE_COMPARE_FUNC(PROPERTY, COMPAREFUNC) \
- DEFINE_COMPARE_FUNC_EX(PROPERTY, PROPERTY, COMPAREFUNC, COMPAREFUNC, AnsiCompareText)
- #define COMPARE_NUMBER(Num1, Num2) ( Num1 < Num2 ? -1 : ( Num1 > Num2 ? 1 : 0) )
- #define COMPARE_DUMMY(X1, X2) 0
- #define COMPARE_TOKEN(Token1, Token2) Token1.Compare(Token2)
- //---------------------------------------------------------------------------
- DEFINE_COMPARE_FUNC_EX(FileName, ItemFileName, AnsiCompareText, AnsiCompareText, COMPARE_DUMMY);
- DEFINE_COMPARE_FUNC(Size, COMPARE_NUMBER);
- DEFINE_COMPARE_FUNC(Modification, COMPARE_NUMBER);
- DEFINE_COMPARE_FUNC(RightsStr, AnsiCompareText);
- DEFINE_COMPARE_FUNC(Owner, COMPARE_TOKEN);
- DEFINE_COMPARE_FUNC(Group, COMPARE_TOKEN);
- DEFINE_COMPARE_FUNC_EX(Extension, Extension, AnsiCompareText, COMPARE_DUMMY, AnsiCompareText);
- DEFINE_COMPARE_FUNC(LinkTo, AnsiCompareText);
- DEFINE_COMPARE_FUNC(TypeName, AnsiCompareText);
- //---------------------------------------------------------------------------
- #undef DEFINE_COMPARE_FUNC
- #undef COMPARE_NUMBER
- #undef RFILE
- #endif
- //---------------------------------------------------------------------------
- #define HOMEDIRECTORY L""
- //---------------------------------------------------------------------------
- __fastcall TUnixDirView::TUnixDirView(TComponent* Owner)
- : TCustomUnixDirView(Owner)
- {
- #ifndef DESIGN_ONLY
- FTerminal = NULL;
- #endif
- FCaseSensitive = true;
- DDAllowMove = false;
- FShowInaccesibleDirectories = true;
- FFullLoad = false;
- FDriveView = NULL;
- FInvalidNameChars = L"/";
- }
- //---------------------------------------------------------------------------
- __fastcall TUnixDirView::~TUnixDirView()
- {
- #ifndef DESIGN_ONLY
- Terminal = NULL;
- #endif
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::DisplayContextMenu(const TPoint &Where)
- {
- bool Handled = false;
- if (OnContextPopup)
- {
- OnContextPopup(this, ScreenToClient(Where), Handled);
- }
- if (!Handled)
- {
- if (PopupMenu && !PopupMenu->AutoPopup)
- {
- PopupMenu->Popup(Where.x, Where.y);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::DisplayPropertiesMenu()
- {
- if (OnDisplayProperties) OnDisplayProperties(this);
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::ExecuteFile(TListItem * Item)
- {
- #ifndef DESIGN_ONLY
- ASSERT_VALID_ITEM;
- if (ITEMFILE->IsDirectory ||
- !Terminal->ResolvingSymlinks)
- {
- PathChanging(true);
- ChangeDirectory(ITEMFILE->FileName);
- }
- else
- {
- if (ItemFocused != Item) ItemFocused = Item;
- DisplayPropertiesMenu();
- }
- #else
- USEDPARAM(Item);
- #endif
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::ExecuteParentDirectory()
- {
- PathChanging(true);
- #ifndef DESIGN_ONLY
- ChangeDirectory(PARENTDIRECTORY);
- #endif
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::ExecuteHomeDirectory()
- {
- #ifndef DESIGN_ONLY
- // don't select any directory
- PathChanging(false);
- UnicodeString APath = Terminal->SessionData->RemoteDirectory;
- if (WinConfiguration->DefaultDirIsHome && !APath.IsEmpty() &&
- !Terminal->SessionData->UpdateDirectories)
- {
- if (APath[1] != L'/')
- {
- Terminal->BeginTransaction();
- try
- {
- ChangeDirectory(HOMEDIRECTORY);
- ChangeDirectory(APath);
- }
- __finally
- {
- Terminal->EndTransaction();
- }
- }
- else
- {
- ChangeDirectory(APath);
- }
- }
- else
- {
- ChangeDirectory(HOMEDIRECTORY);
- }
- #endif
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::ReloadDirectory()
- {
- #ifndef DESIGN_ONLY
- FLastPath = L"";
- DoAnimation(true);
- Terminal->ReloadDirectory();
- #endif
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::ExecuteRootDirectory()
- {
- #ifndef DESIGN_ONLY
- // We set LastPath to top directory, so it will be selected
- // after entering root directory
- // DISABLED: see PathChanged(): back moves to top directory, not to current
- PathChanging(false);
- ChangeDirectory(ROOTDIRECTORY);
- #endif
- }
- //---------------------------------------------------------------------------
- bool __fastcall TUnixDirView::ItemIsDirectory(TListItem * Item)
- {
- #ifndef DESIGN_ONLY
- ASSERT_VALID_ITEM;
- return ITEMFILE->IsDirectory;
- #else
- USEDPARAM(Item);
- return false;
- #endif
- }
- //---------------------------------------------------------------------------
- bool __fastcall TUnixDirView::ItemIsFile(TListItem * Item)
- {
- #ifndef DESIGN_ONLY
- ASSERT_VALID_ITEM;
- return !(ITEMFILE->IsParentDirectory);
- #else
- USEDPARAM(Item);
- return false;
- #endif
- }
- //---------------------------------------------------------------------------
- bool __fastcall TUnixDirView::ItemIsParentDirectory(TListItem * Item)
- {
- #ifndef DESIGN_ONLY
- ASSERT_VALID_ITEM;
- return ITEMFILE->IsParentDirectory;
- #else
- USEDPARAM(Item);
- return false;
- #endif
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TUnixDirView::ItemFileName(TListItem * Item)
- {
- #ifndef DESIGN_ONLY
- ASSERT_VALID_ITEM;
- return ITEMFILE->FileName;
- #else
- USEDPARAM(Item);
- return UnicodeString();
- #endif
- }
- //---------------------------------------------------------------------------
- __int64 __fastcall TUnixDirView::ItemFileSize(TListItem * Item)
- {
- #ifndef DESIGN_ONLY
- ASSERT_VALID_ITEM;
- return ITEMFILE->IsDirectory ? 0 : ITEMFILE->Size;
- #else
- USEDPARAM(Item);
- return 0;
- #endif
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TUnixDirView::ItemFullFileName(TListItem * Item)
- {
- #ifndef DESIGN_ONLY
- ASSERT_VALID_ITEM;
- return ITEMFILE->FullFileName;
- #else
- USEDPARAM(Item);
- return UnicodeString();
- #endif
- }
- //---------------------------------------------------------------------------
- int __fastcall TUnixDirView::ItemImageIndex(TListItem * Item, bool /*Cache*/)
- {
- #ifndef DESIGN_ONLY
- ASSERT_VALID_ITEM;
- // TCustomDirView::ItemImageIndex is used for icon caching
- // so we don't need it here. But it's implemented anyway.
- return ITEMFILE->IconIndex;
- #else
- USEDPARAM(Item);
- return 0;
- #endif
- }
- //---------------------------------------------------------------------------
- bool __fastcall TUnixDirView::ItemMatchesFilter(TListItem * Item,
- const TFileFilter &Filter)
- {
- #ifndef DESIGN_ONLY
- ASSERT_VALID_ITEM;
- TRemoteFile *File = ITEMFILE;
- int Attr = File->Attr;
- return
- ((Attr & Filter.IncludeAttr) == Filter.IncludeAttr) &&
- ((Attr & Filter.ExcludeAttr) == 0) &&
- ((Filter.FileSizeFrom == 0) || (File->Size >= Filter.FileSizeFrom)) &&
- ((Filter.FileSizeTo == 0) || (File->Size <= Filter.FileSizeTo)) &&
- ((!(int)Filter.ModificationFrom) || (File->Modification >= Filter.ModificationFrom)) &&
- ((!(int)Filter.ModificationTo) || (File->Modification <= Filter.ModificationTo)) &&
- ((Filter.Masks.IsEmpty()) ||
- FileNameMatchesMasks(File->FileName, File->IsDirectory, File->Size, File->Modification, Filter.Masks, false) ||
- (File->IsDirectory && Filter.Directories &&
- FileNameMatchesMasks(File->FileName, false, File->Size, File->Modification, Filter.Masks, false)));
- #else
- USEDPARAM(Item);
- USEDPARAM(Filter);
- return false;
- #endif
- }
- //---------------------------------------------------------------------------
- Word __fastcall TUnixDirView::ItemOverlayIndexes(TListItem * Item)
- {
- #ifndef DESIGN_ONLY
- ASSERT_VALID_ITEM;
- Word Result = TCustomDirView::ItemOverlayIndexes(Item);
- if (ITEMFILE->IsParentDirectory)
- {
- Result |= oiDirUp;
- }
- if (ITEMFILE->IsSymLink)
- {
- Result |= ITEMFILE->BrokenLink ? oiBrokenLink : oiLink;
- }
- return Result;
- #else
- USEDPARAM(Item);
- return 0;
- #endif
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::LoadFiles()
- {
- #ifndef DESIGN_ONLY
- assert(Terminal);
- if (DirOK)
- {
- // it's enough if we reach this point, we don't require that loading files into
- // list succeeded. FDirLoadedAfterChangeDir == false tells only that
- // loding file list from server failed, not loading into listview
- FDirLoadedAfterChangeDir = true;
- FFilesSize = 0;
- FHasParentDir = false;
- int VisibleFiles = 0;
- FHiddenCount = 0;
- FFilteredCount = 0;
- for (int Index = 0; Index < Terminal->Files->Count; Index++)
- {
- TRemoteFile *File = Terminal->Files->Files[Index];
- assert(File);
- if ((!ShowHiddenFiles && File->IsHidden) ||
- (!ShowInaccesibleDirectories && File->IsInaccesibleDirectory))
- {
- FHiddenCount++;
- }
- else if (!Mask.IsEmpty() &&
- !File->IsParentDirectory && !File->IsThisDirectory &&
- !FileNameMatchesMasks(File->FileName, File->IsDirectory, File->Size, File->Modification, Mask, true))
- {
- FFilteredCount++;
- }
- else
- {
- VisibleFiles++;
- if (!File->IsDirectory) FFilesSize += File->Size;
- if (File->IsParentDirectory) FHasParentDir = true;
- TListItem * Item = new TListItem(Items);
- Item->Data = File;
- // Need to add before assigning to .Caption and .OverlayIndex,
- // as the setters these call back to owning view.
- // Assignment is redundant
- Item = Items->AddItem(Item);
- Item->Caption = File->FileName;
- if (FFullLoad)
- {
- // this is out of date
- // (missing columns and does not update then file properties are loaded)
- Item->ImageIndex = File->IconIndex;
- Item->SubItems->Add(!File->IsDirectory ? FormatBytes(File->Size, FormatSizeBytes, FormatSizeBytes) : UnicodeString());
- Item->SubItems->Add(File->UserModificationStr);
- Item->SubItems->Add(File->RightsStr);
- Item->SubItems->Add(File->Owner.DisplayText);
- Item->SubItems->Add(File->Group.DisplayText);
- Item->SubItems->Add(File->Extension);
- }
- }
- }
- if (OwnerData)
- {
- Items->Count = VisibleFiles;
- }
- }
- #endif
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::GetDisplayInfo(TListItem * Item, tagLVITEMW &DispInfo)
- {
- if (!FFullLoad)
- {
- #ifndef DESIGN_ONLY
- TRemoteFile * File = ITEMFILE;
- if (DispInfo.mask & LVIF_TEXT)
- {
- UnicodeString Value;
- switch (DispInfo.iSubItem) {
- case uvName: Value = File->FileName; break;
- case uvSize:
- // expanded from ?: to avoid memory leaks
- if (!File->IsDirectory)
- {
- Value = FormatBytes(File->Size, FormatSizeBytes, FormatSizeBytes);
- }
- break;
- case uvChanged: Value = File->UserModificationStr; break;
- case uvRights: Value = File->RightsStr; break;
- case uvOwner: Value = File->Owner.DisplayText; break;
- case uvGroup: Value = File->Group.DisplayText; break;
- case uvExt: Value = File->Extension; break;
- case uvLinkTarget: Value = File->LinkTo; break;
- case uvType: Value = File->TypeName; break;
- default: assert(false);
- }
- StrPLCopy(DispInfo.pszText, Value, DispInfo.cchTextMax);
- }
- if (DispInfo.iSubItem == 0 && DispInfo.mask & LVIF_IMAGE)
- {
- DispInfo.iImage = File->IconIndex;
- DispInfo.mask |= LVIF_DI_SETITEM;
- }
- #else
- USEDPARAM(Item);
- USEDPARAM(DispInfo);
- #endif
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TUnixDirView::PasteFromClipBoard(UnicodeString TargetPath)
- {
- DragDropFilesEx->FileList->Clear();
- bool Result = false;
- if (CanPasteFromClipBoard() &&
- DragDropFilesEx->GetFromClipboard())
- {
- if (TargetPath.IsEmpty())
- {
- TargetPath = PathName;
- }
- PerformItemDragDropOperation(NULL, DROPEFFECT_COPY);
- if (OnDDExecuted != NULL)
- {
- OnDDExecuted(this, DROPEFFECT_COPY);
- }
- Result = true;
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::PerformItemDragDropOperation(TListItem * Item,
- int Effect)
- {
- #ifndef DESIGN_ONLY
- if (OnDDFileOperation)
- {
- assert(DragDropFilesEx->FileList->Count > 0);
- UnicodeString SourceDirectory;
- UnicodeString TargetDirectory;
- SourceDirectory = ExtractFilePath(DragDropFilesEx->FileList->Items[0]->Name);
- if (Item)
- {
- assert(ITEMFILE->IsDirectory && (Terminal->Files->IndexOf(ITEMFILE) >= 0));
- TargetDirectory = ITEMFILE->FullFileName;
- }
- else
- {
- TargetDirectory = Path;
- }
- bool DoFileOperation = true;
- OnDDFileOperation(this, Effect, SourceDirectory, TargetDirectory,
- DoFileOperation);
- }
- #else
- USEDPARAM(Item);
- USEDPARAM(Effect);
- #endif
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::SetItemImageIndex(TListItem * /* Item */, int /* Index */)
- {
- // TCustomDirView::SetItemImageIndex is used for icon caching
- // so we don't need it here.
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::DDMenuDone(TObject* /* Sender */, HMENU /* AMenu */)
- {
- // TODO: Why I need to duplicate this method? (see TCustomDirView::DDMenuDone)
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::SetDriveView(TCustomUnixDriveView * Value)
- {
- if (Value != FDriveView)
- {
- if (FDriveView != NULL)
- {
- FDriveView->Terminal = NULL;
- }
- FDriveView = Value;
- if (FDriveView != NULL)
- {
- FDriveView->Terminal = Terminal;
- }
- }
- }
- //---------------------------------------------------------------------------
- #ifndef DESIGN_ONLY
- void __fastcall TUnixDirView::SetTerminal(TTerminal *value)
- {
- if (FTerminal != value)
- {
- if (FTerminal)
- {
- assert(FTerminal->OnReadDirectory == DoReadDirectory);
- FTerminal->OnReadDirectory = NULL;
- assert(FTerminal->OnStartReadDirectory == DoStartReadDirectory);
- FTerminal->OnStartReadDirectory = NULL;
- assert(FTerminal->OnChangeDirectory == DoChangeDirectory);
- FTerminal->OnChangeDirectory = NULL;
- if (!value || !value->Files->Loaded)
- {
- ClearItems();
- }
- }
- FTerminal = value;
- PathChanging(false);
- if (FDriveView != NULL)
- {
- FDriveView->Terminal = FTerminal;
- }
- if (FTerminal)
- {
- FTerminal->OnReadDirectory = DoReadDirectory;
- FTerminal->OnStartReadDirectory = DoStartReadDirectory;
- FTerminal->OnChangeDirectory = DoChangeDirectory;
- FTerminal->Files->IncludeParentDirectory = AddParentDir;
- if (FTerminal->Files->Loaded)
- {
- DoChangeDirectory(FTerminal);
- DoStartReadDirectory(FTerminal); // just for style and the assertions
- DoReadDirectoryImpl(FTerminal, false);
- }
- }
- }
- }
- #endif
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::DoStartReadDirectory(TObject * /*Sender*/)
- {
- assert(!FLoading);
- FLoading = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::DoReadDirectory(TObject * Sender, bool ReloadOnly)
- {
- DoReadDirectoryImpl(Sender, ReloadOnly);
- if (FOnRead != NULL)
- {
- FOnRead(this);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::DoReadDirectoryImpl(TObject * /*Sender*/, bool ReloadOnly)
- {
- assert(FLoading);
- FLoading = false;
- #ifndef DESIGN_ONLY
- if (Terminal->Active)
- {
- CancelEdit();
- if (ReloadOnly)
- {
- Reload(false);
- }
- else
- {
- Load();
- PathChanged();
- }
- if ((FDriveView != NULL) && FDriveView->Visible)
- {
- FDriveView->LoadDirectory();
- }
- }
- else
- {
- // Make sure file list is cleared, to remove all references to invalid
- // file objects. LoadFiles check for disconnected terminal, so no reloading
- // actually occures.
- Load();
- }
- #else
- USEDPARAM(ReloadOnly);
- #endif
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::DoChangeDirectory(TObject * /*Sender*/)
- {
- #ifndef DESIGN_ONLY
- // Reload(false);
- #endif
- }
- //---------------------------------------------------------------------------
- bool __fastcall TUnixDirView::GetDirOK()
- {
- #ifndef DESIGN_ONLY
- return (Active && Terminal->Files->Loaded);
- #else
- return false;
- #endif
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TUnixDirView::GetPathName()
- {
- #ifndef DESIGN_ONLY
- if (DirOK) return Terminal->CurrentDirectory;
- else
- #endif
- return L"";
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TUnixDirView::GetPath()
- {
- #ifndef DESIGN_ONLY
- if (DirOK) return UnixIncludeTrailingBackslash(Terminal->CurrentDirectory);
- else
- #endif
- return L"";
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::SetPath(UnicodeString Value)
- {
- #ifndef DESIGN_ONLY
- Value = UnixExcludeTrailingBackslash(Value);
- if (Active && (Terminal->CurrentDirectory != Value))
- {
- PathChanging(true);
- Terminal->CurrentDirectory = Value;
- }
- #endif
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::SortItems()
- {
- #ifndef DESIGN_ONLY
- assert(Terminal);
- if (HandleAllocated())
- {
- PFNLVCOMPARE SortProc;
- switch (SortColumn) {
- case uvName: SortProc = (PFNLVCOMPARE)CompareItemFileName; break;
- case uvSize: SortProc = (PFNLVCOMPARE)CompareSize; break;
- case uvChanged: SortProc = (PFNLVCOMPARE)CompareModification; break;
- case uvRights: SortProc = (PFNLVCOMPARE)CompareRightsStr; break;
- case uvOwner: SortProc = (PFNLVCOMPARE)CompareOwner; break;
- case uvGroup: SortProc = (PFNLVCOMPARE)CompareGroup; break;
- case uvExt: SortProc = (PFNLVCOMPARE)CompareExtension; break;
- case uvLinkTarget: SortProc = (PFNLVCOMPARE)CompareLinkTo; break;
- case uvType: SortProc = (PFNLVCOMPARE)CompareTypeName; break;
- default: assert(false);
- }
- CustomSortItems(SortProc);
- }
- #endif
- }
- //---------------------------------------------------------------------------
- bool __fastcall TUnixDirView::GetActive()
- {
- #ifndef DESIGN_ONLY
- return ((Terminal != NULL) && Terminal->Active);
- #else
- return false;
- #endif
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::DDDragDetect(int grfKeyState,
- const TPoint &DetectStart, const TPoint &Point, TDragDetectStatus DragStatus)
- {
- if ((DragStatus == ddsDrag) && (!Loading) && (MarkedCount > 0))
- {
- TCustomUnixDirView::DDDragDetect(grfKeyState, DetectStart, Point, DragStatus);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::SetAddParentDir(bool Value)
- {
- if (Value != AddParentDir)
- {
- #ifndef DESIGN_ONLY
- if (Terminal) Terminal->Files->IncludeParentDirectory = Value;
- #endif
- TCustomUnixDirView::SetAddParentDir(Value);
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TUnixDirView::TargetHasDropHandler(TListItem * /* Item */, int /* Effect */)
- {
- return false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::DDChooseEffect(int grfKeyState, int &dwEffect)
- {
- if ((grfKeyState & (MK_CONTROL | MK_SHIFT)) == 0)
- {
- dwEffect = DROPEFFECT_Copy;
- }
- TCustomDirView::DDChooseEffect(grfKeyState, dwEffect);
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::SetDDAllowMove(bool value)
- {
- if (DDAllowMove != value)
- {
- assert(DragDropFilesEx);
- FDDAllowMove = value;
- DragDropFilesEx->SourceEffects = DragSourceEffects;
- }
- }
- //---------------------------------------------------------------------------
- TDropEffectSet __fastcall TUnixDirView::GetDragSourceEffects()
- {
- TDropEffectSet Result;
- Result << deCopy;
- if (DDAllowMove) Result << deMove;
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::ChangeDirectory(UnicodeString Path)
- {
- UnicodeString LastFile = L"";
- if (ItemFocused) LastFile = ItemFileName(ItemFocused);
- ClearItems();
- DoAnimation(true);
- #ifndef DESIGN_ONLY
- try
- {
- FDirLoadedAfterChangeDir = false;
- APPLICATION_EXCEPTION_HACK_BEGIN
- {
- if (Path == HOMEDIRECTORY)
- {
- Terminal->HomeDirectory();
- }
- else
- // this works even with LockInHome
- if (Path == ROOTDIRECTORY)
- {
- Terminal->CurrentDirectory = ROOTDIRECTORY;
- }
- else
- {
- Terminal->ChangeDirectory(Path);
- }
- }
- APPLICATION_EXCEPTION_HACK_END;
- }
- __finally
- {
- // changing directory failed, so we load again old directory
- if (!FDirLoadedAfterChangeDir)
- {
- FSelectFile = LastFile;
- Reload(false);
- };
- }
- #endif
- }
- //---------------------------------------------------------------------------
- bool __fastcall TUnixDirView::CanEdit(TListItem* Item)
- {
- #ifndef DESIGN_ONLY
- assert(Terminal);
- return TCustomUnixDirView::CanEdit(Item) && Terminal->IsCapable[fcRename];
- #else
- USEDPARAM(Item);
- return false;
- #endif
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::InternalEdit(const tagLVITEMW & HItem)
- {
- #ifndef DESIGN_ONLY
- TListItem *Item = GetItemFromHItem(HItem);
- ASSERT_VALID_ITEM;
- LoadEnabled = true;
- if (ITEMFILE->FileName != HItem.pszText)
- {
- FSelectFile = HItem.pszText;
- Terminal->RenameFile(ITEMFILE, HItem.pszText, true);
- }
- #else
- USEDPARAM(HItem);
- #endif
- }
- //---------------------------------------------------------------------------
- int __fastcall TUnixDirView::SecondaryColumnHeader(int Index, bool & AliasOnly)
- {
- AliasOnly = false;
- return ((Index == uvName) ? uvExt : -1);
- }
- //---------------------------------------------------------------------------
- int __fastcall TUnixDirView::HiddenCount()
- {
- return FHiddenCount;
- }
- //---------------------------------------------------------------------------
- int __fastcall TUnixDirView::FilteredCount()
- {
- return FFilteredCount;
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::CreateDirectory(UnicodeString DirName)
- {
- CreateDirectoryEx(DirName, NULL);
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::CreateDirectoryEx(UnicodeString DirName, const TRemoteProperties * Properties)
- {
- #ifndef DESIGN_ONLY
- assert(Terminal);
- // if file would be created in current directory, select it after reload
- if (UnixExtractFileName(DirName) == DirName)
- {
- FSelectFile = DirName;
- }
- Terminal->CreateDirectory(DirName, Properties);
- #else
- USEDPARAM(Properties);
- #endif
- }
- //---------------------------------------------------------------------------
- bool __fastcall TUnixDirView::GetIsRoot()
- {
- #ifndef DESIGN_ONLY
- return (PathName == ROOTDIRECTORY);
- #else
- return false;
- #endif
- }
- //---------------------------------------------------------------------------
- TColor __fastcall TUnixDirView::ItemColor(TListItem * Item)
- {
- assert(Item);
- #ifndef DESIGN_ONLY
- if (DimmHiddenFiles && !Item->Selected && ITEMFILE->IsHidden)
- {
- return clGrayText;
- }
- else
- #else
- USEDPARAM(Item);
- #endif
- {
- return (TColor)clDefaultItemColor;
- }
- }
- //---------------------------------------------------------------------------
- TDateTime __fastcall TUnixDirView::ItemFileTime(TListItem * Item,
- TDateTimePrecision & Precision)
- {
- assert(Item);
- #ifndef DESIGN_ONLY
- switch (ITEMFILE->ModificationFmt)
- {
- case mfNone:
- Precision = tpNone;
- break;
- case mfMDHM:
- Precision = tpMinute;
- break;
- case mfMDY:
- Precision = tpDay;
- break;
- case mfFull:
- default:
- Precision = tpSecond;
- break;
- }
- return ITEMFILE->Modification;
- #else
- USEDPARAM(Item);
- Precision = tpSecond;
- return Now();
- #endif
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::SetShowInaccesibleDirectories(bool value)
- {
- if (FShowInaccesibleDirectories != value)
- {
- FShowInaccesibleDirectories = value;
- if (DirOK) Reload(false);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TUnixDirView::AddToDragFileList(TFileList * FileList,
- TListItem * Item)
- {
- UnicodeString FileName = ItemFullFileName(Item);
- #ifndef DESIGN_ONLY
- if (OnDDDragFileName != NULL)
- {
- OnDDDragFileName(this, ITEMFILE, FileName);
- }
- #endif
- FileList->AddItem(NULL, FileName);
- }
|