UnixDirView.cpp 28 KB

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