UnixDirView.cpp 25 KB

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