UnixDirView.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include "UnixDirView.h"
  6. #include "UnixDriveView.h"
  7. #include <FileCtrl.hpp>
  8. #ifndef DESIGN_ONLY
  9. #include <CoreMain.h>
  10. #include <Terminal.h>
  11. #include <WinConfiguration.h>
  12. #include <VCLCommon.h>
  13. #endif
  14. #pragma package(smart_init)
  15. #ifndef DESIGN_ONLY
  16. #define ITEMFILE ((TRemoteFile *)(Item->Data))
  17. // noop, previously this tested that the file was in terminal's file listing,
  18. // but that cannot be safely checked now the terminal is used in multithreaded
  19. // environment
  20. #define ASSERT_VALID_ITEM
  21. #endif
  22. //---------------------------------------------------------------------------
  23. static inline void ValidCtrCheck(TUnixDirView *)
  24. {
  25. new TUnixDirView(NULL);
  26. }
  27. //---------------------------------------------------------------------------
  28. namespace Unixdirview
  29. {
  30. void __fastcall PACKAGE Register()
  31. {
  32. TComponentClass classes[1] = {__classid(TUnixDirView)};
  33. RegisterComponents(L"Scp", classes, 0);
  34. }
  35. }
  36. //---------------------------------------------------------------------------
  37. #define HOMEDIRECTORY L""
  38. //---------------------------------------------------------------------------
  39. __fastcall TUnixDirView::TUnixDirView(TComponent* Owner)
  40. : TCustomUnixDirView(Owner)
  41. {
  42. #ifndef DESIGN_ONLY
  43. FTerminal = NULL;
  44. #endif
  45. FCaseSensitive = true;
  46. DDAllowMove = false;
  47. FShowInaccesibleDirectories = true;
  48. FFullLoad = false;
  49. FDriveView = NULL;
  50. FInvalidNameChars = L"/";
  51. }
  52. //---------------------------------------------------------------------------
  53. __fastcall TUnixDirView::~TUnixDirView()
  54. {
  55. #ifndef DESIGN_ONLY
  56. Terminal = NULL;
  57. #endif
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TUnixDirView::DisplayContextMenu(const TPoint &Where)
  61. {
  62. bool Handled = false;
  63. if (OnContextPopup)
  64. {
  65. OnContextPopup(this, ScreenToClient(Where), Handled);
  66. }
  67. if (!Handled)
  68. {
  69. if (PopupMenu && !PopupMenu->AutoPopup)
  70. {
  71. PopupMenu->Popup(Where.x, Where.y);
  72. }
  73. }
  74. }
  75. //---------------------------------------------------------------------------
  76. void __fastcall TUnixDirView::DisplayPropertiesMenu()
  77. {
  78. if (OnDisplayProperties) OnDisplayProperties(this);
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TUnixDirView::ExecuteFile(TListItem * Item)
  82. {
  83. #ifndef DESIGN_ONLY
  84. ASSERT_VALID_ITEM;
  85. if (ITEMFILE->IsDirectory ||
  86. !Terminal->ResolvingSymlinks)
  87. {
  88. PathChanging(true);
  89. ChangeDirectory(ITEMFILE->FileName);
  90. }
  91. else
  92. {
  93. if (ItemFocused != Item) ItemFocused = Item;
  94. DisplayPropertiesMenu();
  95. }
  96. #else
  97. DebugUsedParam(Item);
  98. #endif
  99. }
  100. //---------------------------------------------------------------------------
  101. void __fastcall TUnixDirView::ExecuteParentDirectory()
  102. {
  103. PathChanging(true);
  104. #ifndef DESIGN_ONLY
  105. ChangeDirectory(PARENTDIRECTORY);
  106. #endif
  107. }
  108. //---------------------------------------------------------------------------
  109. void __fastcall TUnixDirView::ExecuteHomeDirectory()
  110. {
  111. #ifndef DESIGN_ONLY
  112. // don't select any directory
  113. PathChanging(false);
  114. UnicodeString APath = Terminal->SessionData->RemoteDirectory;
  115. if (WinConfiguration->DefaultDirIsHome && !APath.IsEmpty() &&
  116. !Terminal->SessionData->UpdateDirectories)
  117. {
  118. if (APath[1] != L'/')
  119. {
  120. Terminal->BeginTransaction();
  121. try
  122. {
  123. ChangeDirectory(HOMEDIRECTORY);
  124. ChangeDirectory(APath);
  125. }
  126. __finally
  127. {
  128. Terminal->EndTransaction();
  129. }
  130. }
  131. else
  132. {
  133. ChangeDirectory(APath);
  134. }
  135. }
  136. else
  137. {
  138. ChangeDirectory(HOMEDIRECTORY);
  139. }
  140. #endif
  141. }
  142. //---------------------------------------------------------------------------
  143. void __fastcall TUnixDirView::ReloadDirectory()
  144. {
  145. #ifndef DESIGN_ONLY
  146. FLastPath = L"";
  147. DoAnimation(true);
  148. Terminal->ReloadDirectory();
  149. #endif
  150. }
  151. //---------------------------------------------------------------------------
  152. void __fastcall TUnixDirView::ExecuteRootDirectory()
  153. {
  154. #ifndef DESIGN_ONLY
  155. // We set LastPath to top directory, so it will be selected
  156. // after entering root directory
  157. // DISABLED: see PathChanged(): back moves to top directory, not to current
  158. PathChanging(false);
  159. ChangeDirectory(ROOTDIRECTORY);
  160. #endif
  161. }
  162. //---------------------------------------------------------------------------
  163. bool __fastcall TUnixDirView::ItemIsDirectory(TListItem * Item)
  164. {
  165. #ifndef DESIGN_ONLY
  166. ASSERT_VALID_ITEM;
  167. return ITEMFILE->IsDirectory;
  168. #else
  169. DebugUsedParam(Item);
  170. return false;
  171. #endif
  172. }
  173. //---------------------------------------------------------------------------
  174. bool __fastcall TUnixDirView::ItemIsFile(TListItem * Item)
  175. {
  176. #ifndef DESIGN_ONLY
  177. ASSERT_VALID_ITEM;
  178. return !(ITEMFILE->IsParentDirectory);
  179. #else
  180. DebugUsedParam(Item);
  181. return false;
  182. #endif
  183. }
  184. //---------------------------------------------------------------------------
  185. bool __fastcall TUnixDirView::ItemIsParentDirectory(TListItem * Item)
  186. {
  187. #ifndef DESIGN_ONLY
  188. ASSERT_VALID_ITEM;
  189. return ITEMFILE->IsParentDirectory;
  190. #else
  191. DebugUsedParam(Item);
  192. return false;
  193. #endif
  194. }
  195. //---------------------------------------------------------------------------
  196. UnicodeString __fastcall TUnixDirView::ItemFileName(TListItem * Item)
  197. {
  198. #ifndef DESIGN_ONLY
  199. ASSERT_VALID_ITEM;
  200. return ITEMFILE->FileName;
  201. #else
  202. DebugUsedParam(Item);
  203. return UnicodeString();
  204. #endif
  205. }
  206. //---------------------------------------------------------------------------
  207. __int64 __fastcall TUnixDirView::ItemFileSize(TListItem * Item)
  208. {
  209. #ifndef DESIGN_ONLY
  210. ASSERT_VALID_ITEM;
  211. return ITEMFILE->Size;
  212. #else
  213. DebugUsedParam(Item);
  214. return 0;
  215. #endif
  216. }
  217. //---------------------------------------------------------------------------
  218. UnicodeString __fastcall TUnixDirView::ItemFullFileName(TListItem * Item)
  219. {
  220. #ifndef DESIGN_ONLY
  221. ASSERT_VALID_ITEM;
  222. return ITEMFILE->FullFileName;
  223. #else
  224. DebugUsedParam(Item);
  225. return UnicodeString();
  226. #endif
  227. }
  228. //---------------------------------------------------------------------------
  229. int __fastcall TUnixDirView::ItemImageIndex(TListItem * Item, bool /*Cache*/)
  230. {
  231. #ifndef DESIGN_ONLY
  232. ASSERT_VALID_ITEM;
  233. // TCustomDirView::ItemImageIndex is used for icon caching
  234. // so we don't need it here. But it's implemented anyway.
  235. return ITEMFILE->IconIndex;
  236. #else
  237. DebugUsedParam(Item);
  238. return 0;
  239. #endif
  240. }
  241. //---------------------------------------------------------------------------
  242. bool __fastcall TUnixDirView::ItemMatchesFilter(TListItem * Item,
  243. const TFileFilter &Filter)
  244. {
  245. #ifndef DESIGN_ONLY
  246. ASSERT_VALID_ITEM;
  247. TRemoteFile *File = ITEMFILE;
  248. return
  249. ((Filter.Masks.IsEmpty()) ||
  250. FileNameMatchesMasks(File->FileName, File->IsDirectory, File->Size, File->Modification, Filter.Masks, false) ||
  251. (File->IsDirectory && Filter.Directories &&
  252. FileNameMatchesMasks(File->FileName, false, File->Size, File->Modification, Filter.Masks, false)));
  253. #else
  254. DebugUsedParam(Item);
  255. DebugUsedParam(Filter);
  256. return false;
  257. #endif
  258. }
  259. //---------------------------------------------------------------------------
  260. Word __fastcall TUnixDirView::ItemOverlayIndexes(TListItem * Item)
  261. {
  262. #ifndef DESIGN_ONLY
  263. ASSERT_VALID_ITEM;
  264. Word Result = TCustomDirView::ItemOverlayIndexes(Item);
  265. if (ITEMFILE->IsParentDirectory)
  266. {
  267. Result |= oiDirUp;
  268. }
  269. if (ITEMFILE->IsSymLink)
  270. {
  271. Result |= ITEMFILE->BrokenLink ? oiBrokenLink : oiLink;
  272. }
  273. return Result;
  274. #else
  275. DebugUsedParam(Item);
  276. return 0;
  277. #endif
  278. }
  279. //---------------------------------------------------------------------------
  280. void __fastcall TUnixDirView::LoadFiles()
  281. {
  282. #ifndef DESIGN_ONLY
  283. DebugAssert(Terminal);
  284. if (DirOK)
  285. {
  286. // it's enough if we reach this point, we don't require that loading files into
  287. // list succeeded. FDirLoadedAfterChangeDir == false tells only that
  288. // loding file list from server failed, not loading into listview
  289. FDirLoadedAfterChangeDir = true;
  290. FFilesSize = 0;
  291. FHasParentDir = false;
  292. int VisibleFiles = 0;
  293. FHiddenCount = 0;
  294. FFilteredCount = 0;
  295. for (int Index = 0; Index < Terminal->Files->Count; Index++)
  296. {
  297. TRemoteFile *File = Terminal->Files->Files[Index];
  298. DebugAssert(File);
  299. if ((!ShowHiddenFiles && File->IsHidden) ||
  300. (!ShowInaccesibleDirectories && File->IsInaccesibleDirectory))
  301. {
  302. FHiddenCount++;
  303. }
  304. else if (!Mask.IsEmpty() &&
  305. !File->IsParentDirectory && !File->IsThisDirectory &&
  306. !FileNameMatchesMasks(File->FileName, File->IsDirectory, File->Size, File->Modification, Mask, true))
  307. {
  308. FFilteredCount++;
  309. }
  310. else
  311. {
  312. VisibleFiles++;
  313. FFilesSize += File->Size;
  314. if (File->IsParentDirectory) FHasParentDir = true;
  315. TListItem * Item = new TListItem(Items);
  316. Item->Data = File;
  317. // Need to add before assigning to .Caption and .OverlayIndex,
  318. // as the setters these call back to owning view.
  319. // Assignment is redundant
  320. Item = Items->AddItem(Item);
  321. Item->Caption = File->FileName;
  322. if (FFullLoad)
  323. {
  324. // this is out of date
  325. // (missing columns and does not update then file properties are loaded)
  326. Item->ImageIndex = File->IconIndex;
  327. Item->SubItems->Add(!File->IsDirectory ? FormatPanelBytes(File->Size, FormatSizeBytes) : UnicodeString());
  328. Item->SubItems->Add(File->UserModificationStr);
  329. Item->SubItems->Add(File->RightsStr);
  330. Item->SubItems->Add(File->Owner.DisplayText);
  331. Item->SubItems->Add(File->Group.DisplayText);
  332. Item->SubItems->Add(File->Extension);
  333. }
  334. }
  335. }
  336. if (OwnerData)
  337. {
  338. Items->Count = VisibleFiles;
  339. }
  340. }
  341. #endif
  342. }
  343. //---------------------------------------------------------------------------
  344. void __fastcall TUnixDirView::GetDisplayInfo(TListItem * Item, tagLVITEMW &DispInfo)
  345. {
  346. if (!FFullLoad)
  347. {
  348. #ifndef DESIGN_ONLY
  349. TRemoteFile * File = ITEMFILE;
  350. if (DispInfo.mask & LVIF_TEXT)
  351. {
  352. UnicodeString Value;
  353. switch (DispInfo.iSubItem) {
  354. case uvName: Value = File->FileName; break;
  355. case uvSize:
  356. // expanded from ?: to avoid memory leaks
  357. if (!File->IsDirectory)
  358. {
  359. Value = FormatPanelBytes(File->Size, FormatSizeBytes);
  360. }
  361. break;
  362. case uvChanged: Value = File->UserModificationStr; break;
  363. case uvRights: Value = File->RightsStr; break;
  364. case uvOwner: Value = File->Owner.DisplayText; break;
  365. case uvGroup: Value = File->Group.DisplayText; break;
  366. case uvExt: Value = File->Extension; break;
  367. case uvLinkTarget: Value = File->LinkTo; break;
  368. case uvType: Value = File->TypeName; break;
  369. default: DebugFail();
  370. }
  371. StrPLCopy(DispInfo.pszText, Value, DispInfo.cchTextMax);
  372. }
  373. if (DispInfo.iSubItem == 0 && DispInfo.mask & LVIF_IMAGE)
  374. {
  375. DispInfo.iImage = File->IconIndex;
  376. DispInfo.mask |= LVIF_DI_SETITEM;
  377. }
  378. #else
  379. DebugUsedParam(Item);
  380. DebugUsedParam(DispInfo);
  381. #endif
  382. }
  383. }
  384. //---------------------------------------------------------------------------
  385. bool __fastcall TUnixDirView::PasteFromClipBoard(UnicodeString TargetPath)
  386. {
  387. DragDropFilesEx->FileList->Clear();
  388. bool Result = false;
  389. if (CanPasteFromClipBoard() &&
  390. DragDropFilesEx->GetFromClipboard())
  391. {
  392. if (TargetPath.IsEmpty())
  393. {
  394. TargetPath = PathName;
  395. }
  396. PerformItemDragDropOperation(NULL, DROPEFFECT_COPY);
  397. if (OnDDExecuted != NULL)
  398. {
  399. OnDDExecuted(this, DROPEFFECT_COPY);
  400. }
  401. Result = true;
  402. }
  403. return Result;
  404. }
  405. //---------------------------------------------------------------------------
  406. void __fastcall TUnixDirView::PerformItemDragDropOperation(TListItem * Item,
  407. int Effect)
  408. {
  409. #ifndef DESIGN_ONLY
  410. if (OnDDFileOperation)
  411. {
  412. // Could be empty if the source application does not provide any files;
  413. // or if the IDataObject fails GetData, like Visual Studio Code 0.8.0.
  414. if (DragDropFilesEx->FileList->Count > 0)
  415. {
  416. UnicodeString SourceDirectory;
  417. UnicodeString TargetDirectory;
  418. SourceDirectory = ExtractFilePath(DragDropFilesEx->FileList->Items[0]->Name);
  419. if (Item)
  420. {
  421. DebugAssert(ITEMFILE->IsDirectory && (Terminal->Files->IndexOf(ITEMFILE) >= 0));
  422. TargetDirectory = ITEMFILE->FullFileName;
  423. }
  424. else
  425. {
  426. TargetDirectory = Path;
  427. }
  428. bool DoFileOperation = true;
  429. OnDDFileOperation(this, Effect, SourceDirectory, TargetDirectory,
  430. DoFileOperation);
  431. }
  432. }
  433. #else
  434. DebugUsedParam(Item);
  435. DebugUsedParam(Effect);
  436. #endif
  437. }
  438. //---------------------------------------------------------------------------
  439. void __fastcall TUnixDirView::SetItemImageIndex(TListItem * /* Item */, int /* Index */)
  440. {
  441. // TCustomDirView::SetItemImageIndex is used for icon caching
  442. // so we don't need it here.
  443. }
  444. //---------------------------------------------------------------------------
  445. void __fastcall TUnixDirView::DDMenuDone(TObject* /* Sender */, HMENU /* AMenu */)
  446. {
  447. // TODO: Why I need to duplicate this method? (see TCustomDirView::DDMenuDone)
  448. }
  449. //---------------------------------------------------------------------------
  450. void __fastcall TUnixDirView::SetDriveView(TCustomUnixDriveView * Value)
  451. {
  452. if (Value != FDriveView)
  453. {
  454. if (FDriveView != NULL)
  455. {
  456. FDriveView->Terminal = NULL;
  457. }
  458. FDriveView = Value;
  459. if (FDriveView != NULL)
  460. {
  461. FDriveView->Terminal = Terminal;
  462. }
  463. }
  464. }
  465. //---------------------------------------------------------------------------
  466. #ifndef DESIGN_ONLY
  467. void __fastcall TUnixDirView::SetTerminal(TTerminal *value)
  468. {
  469. if (FTerminal != value)
  470. {
  471. if (FTerminal)
  472. {
  473. DebugAssert(FTerminal->OnReadDirectory == DoReadDirectory);
  474. FTerminal->OnReadDirectory = NULL;
  475. DebugAssert(FTerminal->OnStartReadDirectory == DoStartReadDirectory);
  476. FTerminal->OnStartReadDirectory = NULL;
  477. DebugAssert(FTerminal->OnChangeDirectory == DoChangeDirectory);
  478. FTerminal->OnChangeDirectory = NULL;
  479. if (!value || !value->Files->Loaded)
  480. {
  481. ClearItems();
  482. }
  483. }
  484. FTerminal = value;
  485. PathChanging(false);
  486. if (FDriveView != NULL)
  487. {
  488. FDriveView->Terminal = FTerminal;
  489. }
  490. if (FTerminal)
  491. {
  492. FTerminal->OnReadDirectory = DoReadDirectory;
  493. FTerminal->OnStartReadDirectory = DoStartReadDirectory;
  494. FTerminal->OnChangeDirectory = DoChangeDirectory;
  495. FTerminal->Files->IncludeParentDirectory = AddParentDir;
  496. if (FTerminal->Files->Loaded)
  497. {
  498. DoChangeDirectory(FTerminal);
  499. DoStartReadDirectory(FTerminal); // just for style and the assertions
  500. DoReadDirectoryImpl(FTerminal, false);
  501. }
  502. }
  503. UpdatePathLabel();
  504. }
  505. }
  506. #endif
  507. //---------------------------------------------------------------------------
  508. void __fastcall TUnixDirView::DoStartReadDirectory(TObject * /*Sender*/)
  509. {
  510. DebugAssert(!FLoading);
  511. FLoading = true;
  512. }
  513. //---------------------------------------------------------------------------
  514. void __fastcall TUnixDirView::DoReadDirectory(TObject * Sender, bool ReloadOnly)
  515. {
  516. DoReadDirectoryImpl(Sender, ReloadOnly);
  517. if (FOnRead != NULL)
  518. {
  519. FOnRead(this);
  520. }
  521. }
  522. //---------------------------------------------------------------------------
  523. void __fastcall TUnixDirView::DoReadDirectoryImpl(TObject * /*Sender*/, bool ReloadOnly)
  524. {
  525. DebugAssert(FLoading);
  526. FLoading = false;
  527. #ifndef DESIGN_ONLY
  528. if (Terminal->Active)
  529. {
  530. CancelEdit();
  531. if (ReloadOnly)
  532. {
  533. Reload(false);
  534. }
  535. else
  536. {
  537. Load(true);
  538. PathChanged();
  539. }
  540. if ((FDriveView != NULL) && FDriveView->Visible)
  541. {
  542. FDriveView->LoadDirectory();
  543. }
  544. }
  545. else
  546. {
  547. // Make sure file list is cleared, to remove all references to invalid
  548. // file objects. LoadFiles check for disconnected terminal, so no reloading
  549. // actually occures.
  550. Load(true);
  551. }
  552. #else
  553. DebugUsedParam(ReloadOnly);
  554. #endif
  555. }
  556. //---------------------------------------------------------------------------
  557. void __fastcall TUnixDirView::DoChangeDirectory(TObject * /*Sender*/)
  558. {
  559. #ifndef DESIGN_ONLY
  560. // Reload(false);
  561. #endif
  562. }
  563. //---------------------------------------------------------------------------
  564. bool __fastcall TUnixDirView::GetDirOK()
  565. {
  566. #ifndef DESIGN_ONLY
  567. return (Active && Terminal->Files->Loaded);
  568. #else
  569. return false;
  570. #endif
  571. }
  572. //---------------------------------------------------------------------------
  573. UnicodeString __fastcall TUnixDirView::GetPathName()
  574. {
  575. #ifndef DESIGN_ONLY
  576. if (DirOK) return Terminal->CurrentDirectory;
  577. else
  578. #endif
  579. return L"";
  580. }
  581. //---------------------------------------------------------------------------
  582. UnicodeString __fastcall TUnixDirView::GetPath()
  583. {
  584. #ifndef DESIGN_ONLY
  585. if (DirOK) return UnixIncludeTrailingBackslash(Terminal->CurrentDirectory);
  586. else
  587. #endif
  588. return L"";
  589. }
  590. //---------------------------------------------------------------------------
  591. void __fastcall TUnixDirView::SetPath(UnicodeString Value)
  592. {
  593. #ifndef DESIGN_ONLY
  594. Value = UnixExcludeTrailingBackslash(Value);
  595. if (Active && (Terminal->CurrentDirectory != Value))
  596. {
  597. PathChanging(true);
  598. Terminal->CurrentDirectory = Value;
  599. }
  600. #endif
  601. }
  602. //---------------------------------------------------------------------------
  603. #ifndef DESIGN_ONLY
  604. #define COMPARE_NUMBER(Num1, Num2) ( Num1 < Num2 ? -1 : ( Num1 > Num2 ? 1 : 0) )
  605. //---------------------------------------------------------------------------
  606. int __stdcall CompareFile(TListItem * Item1, TListItem * Item2, TUnixDirView * DirView)
  607. {
  608. DebugAssert((Item1 != NULL) && (Item2 != NULL));
  609. TRemoteFile * File1 = DebugNotNull((TRemoteFile *)(Item1->Data));
  610. TRemoteFile * File2 = DebugNotNull((TRemoteFile *)(Item2->Data));
  611. int Result;
  612. if (File1->IsParentDirectory && !File2->IsParentDirectory)
  613. {
  614. Result = -1;
  615. }
  616. else if (!File1->IsParentDirectory && File2->IsParentDirectory)
  617. {
  618. Result = 1;
  619. }
  620. else if (File1->IsDirectory && !File2->IsDirectory)
  621. {
  622. Result = -1;
  623. }
  624. else if (!File1->IsDirectory && File2->IsDirectory)
  625. {
  626. Result = 1;
  627. }
  628. else
  629. {
  630. Result = 0;
  631. switch (DirView->SortColumn)
  632. {
  633. case uvName:
  634. // fallback
  635. break;
  636. case uvSize:
  637. Result = COMPARE_NUMBER(File1->Size, File2->Size);
  638. break;
  639. case uvChanged:
  640. Result = COMPARE_NUMBER(File1->Modification, File2->Modification);
  641. break;
  642. case uvRights:
  643. Result = AnsiCompareText(File1->RightsStr, File2->RightsStr);
  644. break;
  645. case uvOwner:
  646. Result = File1->Owner.Compare(File2->Owner);
  647. break;
  648. case uvGroup:
  649. Result = File1->Group.Compare(File2->Group);
  650. break;
  651. case uvExt:
  652. // Duplicated in uvType branch
  653. if (!File1->IsDirectory)
  654. {
  655. Result = CompareLogicalText(File1->Extension, File2->Extension);
  656. }
  657. else
  658. {
  659. // fallback
  660. }
  661. break;
  662. case uvLinkTarget:
  663. Result = CompareLogicalText(File1->LinkTo, File2->LinkTo);
  664. break;
  665. case uvType:
  666. Result = CompareLogicalText(File1->TypeName, File2->TypeName);
  667. // fallback to uvExt
  668. if ((Result == 0) && !File1->IsDirectory)
  669. {
  670. Result = CompareLogicalText(File1->Extension, File2->Extension);
  671. }
  672. break;
  673. default:
  674. DebugFail();
  675. }
  676. if (Result == 0)
  677. {
  678. Result = CompareLogicalText(File1->FileName, File2->FileName);
  679. }
  680. if (!DirView->UnixColProperties->SortAscending)
  681. {
  682. Result = -Result;
  683. }
  684. }
  685. return Result;
  686. }
  687. //---------------------------------------------------------------------------
  688. #undef COMPARE_NUMBER
  689. #endif
  690. //---------------------------------------------------------------------------
  691. void __fastcall TUnixDirView::SortItems()
  692. {
  693. #ifndef DESIGN_ONLY
  694. DebugAssert(Terminal);
  695. if (HandleAllocated())
  696. {
  697. CustomSortItems(CompareFile);
  698. }
  699. #endif
  700. }
  701. //---------------------------------------------------------------------------
  702. bool __fastcall TUnixDirView::GetActive()
  703. {
  704. #ifndef DESIGN_ONLY
  705. return ((Terminal != NULL) && Terminal->Active);
  706. #else
  707. return false;
  708. #endif
  709. }
  710. //---------------------------------------------------------------------------
  711. void __fastcall TUnixDirView::DDDragDetect(int grfKeyState,
  712. const TPoint &DetectStart, const TPoint &Point, TDragDetectStatus DragStatus)
  713. {
  714. if ((DragStatus == ddsDrag) && (!Loading) && (MarkedCount > 0))
  715. {
  716. TCustomUnixDirView::DDDragDetect(grfKeyState, DetectStart, Point, DragStatus);
  717. }
  718. }
  719. //---------------------------------------------------------------------------
  720. void __fastcall TUnixDirView::SetAddParentDir(bool Value)
  721. {
  722. if (Value != AddParentDir)
  723. {
  724. #ifndef DESIGN_ONLY
  725. if (Terminal) Terminal->Files->IncludeParentDirectory = Value;
  726. #endif
  727. TCustomUnixDirView::SetAddParentDir(Value);
  728. }
  729. }
  730. //---------------------------------------------------------------------------
  731. bool __fastcall TUnixDirView::TargetHasDropHandler(TListItem * /* Item */, int /* Effect */)
  732. {
  733. return false;
  734. }
  735. //---------------------------------------------------------------------------
  736. void __fastcall TUnixDirView::DDChooseEffect(int grfKeyState, int &dwEffect)
  737. {
  738. if ((grfKeyState & (MK_CONTROL | MK_SHIFT)) == 0)
  739. {
  740. dwEffect = DROPEFFECT_Copy;
  741. }
  742. TCustomDirView::DDChooseEffect(grfKeyState, dwEffect);
  743. }
  744. //---------------------------------------------------------------------------
  745. void __fastcall TUnixDirView::SetDDAllowMove(bool value)
  746. {
  747. if (DDAllowMove != value)
  748. {
  749. DebugAssert(DragDropFilesEx);
  750. FDDAllowMove = value;
  751. DragDropFilesEx->SourceEffects = DragSourceEffects;
  752. }
  753. }
  754. //---------------------------------------------------------------------------
  755. TDropEffectSet __fastcall TUnixDirView::GetDragSourceEffects()
  756. {
  757. TDropEffectSet Result;
  758. Result << deCopy;
  759. if (DDAllowMove) Result << deMove;
  760. return Result;
  761. }
  762. //---------------------------------------------------------------------------
  763. void __fastcall TUnixDirView::ChangeDirectory(UnicodeString Path)
  764. {
  765. UnicodeString LastFile = L"";
  766. if (ItemFocused) LastFile = ItemFileName(ItemFocused);
  767. ClearItems();
  768. DoAnimation(true);
  769. #ifndef DESIGN_ONLY
  770. try
  771. {
  772. FDirLoadedAfterChangeDir = false;
  773. if (Path == HOMEDIRECTORY)
  774. {
  775. Terminal->HomeDirectory();
  776. }
  777. else
  778. // this works even with LockInHome
  779. if (Path == ROOTDIRECTORY)
  780. {
  781. Terminal->CurrentDirectory = ROOTDIRECTORY;
  782. }
  783. else
  784. {
  785. Terminal->ChangeDirectory(Path);
  786. }
  787. }
  788. __finally
  789. {
  790. // changing directory failed, so we load again old directory
  791. if (!FDirLoadedAfterChangeDir)
  792. {
  793. FSelectFile = LastFile;
  794. Reload(false);
  795. };
  796. }
  797. #endif
  798. }
  799. //---------------------------------------------------------------------------
  800. bool __fastcall TUnixDirView::CanEdit(TListItem* Item)
  801. {
  802. #ifndef DESIGN_ONLY
  803. DebugAssert(Terminal);
  804. return TCustomUnixDirView::CanEdit(Item) && Terminal->IsCapable[fcRename];
  805. #else
  806. DebugUsedParam(Item);
  807. return false;
  808. #endif
  809. }
  810. //---------------------------------------------------------------------------
  811. void __fastcall TUnixDirView::InternalEdit(const tagLVITEMW & HItem)
  812. {
  813. #ifndef DESIGN_ONLY
  814. TListItem *Item = GetItemFromHItem(HItem);
  815. ASSERT_VALID_ITEM;
  816. LoadEnabled = true;
  817. if (ITEMFILE->FileName != HItem.pszText)
  818. {
  819. FSelectFile = HItem.pszText;
  820. Terminal->RenameFile(ITEMFILE, HItem.pszText, true);
  821. }
  822. #else
  823. DebugUsedParam(HItem);
  824. #endif
  825. }
  826. //---------------------------------------------------------------------------
  827. int __fastcall TUnixDirView::HiddenCount()
  828. {
  829. return FHiddenCount;
  830. }
  831. //---------------------------------------------------------------------------
  832. int __fastcall TUnixDirView::FilteredCount()
  833. {
  834. return FFilteredCount;
  835. }
  836. //---------------------------------------------------------------------------
  837. void __fastcall TUnixDirView::CreateDirectory(UnicodeString DirName)
  838. {
  839. CreateDirectoryEx(DirName, NULL);
  840. }
  841. //---------------------------------------------------------------------------
  842. void __fastcall TUnixDirView::CreateDirectoryEx(UnicodeString DirName, const TRemoteProperties * Properties)
  843. {
  844. #ifndef DESIGN_ONLY
  845. DebugAssert(Terminal);
  846. // if file would be created in current directory, select it after reload
  847. if (UnixExtractFileName(DirName) == DirName)
  848. {
  849. FSelectFile = DirName;
  850. }
  851. Terminal->CreateDirectory(DirName, Properties);
  852. #else
  853. DebugUsedParam(Properties);
  854. #endif
  855. }
  856. //---------------------------------------------------------------------------
  857. bool __fastcall TUnixDirView::GetIsRoot()
  858. {
  859. #ifndef DESIGN_ONLY
  860. return (PathName == ROOTDIRECTORY);
  861. #else
  862. return false;
  863. #endif
  864. }
  865. //---------------------------------------------------------------------------
  866. TColor __fastcall TUnixDirView::ItemColor(TListItem * Item)
  867. {
  868. DebugAssert(Item);
  869. #ifndef DESIGN_ONLY
  870. if (DimmHiddenFiles && !Item->Selected && ITEMFILE->IsHidden)
  871. {
  872. return clGrayText;
  873. }
  874. else
  875. #else
  876. DebugUsedParam(Item);
  877. #endif
  878. {
  879. return (TColor)clDefaultItemColor;
  880. }
  881. }
  882. //---------------------------------------------------------------------------
  883. TDateTime __fastcall TUnixDirView::ItemFileTime(TListItem * Item,
  884. TDateTimePrecision & Precision)
  885. {
  886. DebugAssert(Item);
  887. #ifndef DESIGN_ONLY
  888. switch (ITEMFILE->ModificationFmt)
  889. {
  890. case mfNone:
  891. Precision = tpNone;
  892. break;
  893. case mfMDHM:
  894. Precision = tpMinute;
  895. break;
  896. case mfMDY:
  897. Precision = tpDay;
  898. break;
  899. case mfFull:
  900. default:
  901. Precision = tpSecond;
  902. break;
  903. }
  904. return ITEMFILE->Modification;
  905. #else
  906. DebugUsedParam(Item);
  907. Precision = tpSecond;
  908. return Now();
  909. #endif
  910. }
  911. //---------------------------------------------------------------------------
  912. void __fastcall TUnixDirView::SetShowInaccesibleDirectories(bool value)
  913. {
  914. if (FShowInaccesibleDirectories != value)
  915. {
  916. FShowInaccesibleDirectories = value;
  917. if (DirOK) Reload(false);
  918. }
  919. }
  920. //---------------------------------------------------------------------------
  921. void __fastcall TUnixDirView::AddToDragFileList(TFileList * FileList,
  922. TListItem * Item)
  923. {
  924. UnicodeString FileName = ItemFullFileName(Item);
  925. #ifndef DESIGN_ONLY
  926. if (OnDDDragFileName != NULL)
  927. {
  928. OnDDDragFileName(this, ITEMFILE, FileName);
  929. }
  930. #endif
  931. FileList->AddItem(NULL, FileName);
  932. }
  933. //---------------------------------------------------------------------------
  934. void __fastcall TUnixDirView::UpdatePathLabelCaption()
  935. {
  936. if (Terminal != NULL)
  937. {
  938. TCustomDirView::UpdatePathLabelCaption();
  939. }
  940. else
  941. {
  942. PathLabel->Caption = UnicodeString();
  943. PathLabel->Mask = UnicodeString();
  944. }
  945. }