UnixDriveView.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include "UnixDriveView.h"
  6. #ifndef DESIGN_ONLY
  7. #include <Terminal.h>
  8. #include <RemoteFiles.h>
  9. #include <VCLCommon.h>
  10. #endif
  11. #pragma package(smart_init)
  12. //---------------------------------------------------------------------------
  13. static inline void ValidCtrCheck(TUnixDriveView *)
  14. {
  15. new TUnixDriveView(NULL);
  16. }
  17. //---------------------------------------------------------------------------
  18. namespace Unixdriveview
  19. {
  20. void __fastcall PACKAGE Register()
  21. {
  22. TComponentClass classes[1] = {__classid(TUnixDriveView)};
  23. RegisterComponents(L"Scp", classes, 0);
  24. }
  25. }
  26. //---------------------------------------------------------------------------
  27. __fastcall TUnixDriveView::TUnixDriveView(TComponent * Owner) :
  28. TCustomUnixDriveView(Owner)
  29. {
  30. }
  31. //---------------------------------------------------------------------------
  32. struct TNodeData
  33. {
  34. TRemoteFileList * FileList;
  35. TRemoteFile * File;
  36. UnicodeString Directory;
  37. };
  38. //---------------------------------------------------------------------------
  39. __fastcall TCustomUnixDriveView::TCustomUnixDriveView(TComponent* Owner) :
  40. TCustomDriveView(Owner)
  41. {
  42. FTerminal = NULL;
  43. FRootName = Customunixdirview_SUnixDefaultRootName;
  44. FIgnoreChange = false;
  45. FPrevSelected = NULL;
  46. FShowInaccesibleDirectories = true;
  47. FDummyDragFile = NULL;
  48. FPendingDelete = new TList();
  49. FDragDropFilesEx->PreferCopy = true;
  50. }
  51. //---------------------------------------------------------------------------
  52. __fastcall TCustomUnixDriveView::~TCustomUnixDriveView()
  53. {
  54. Terminal = NULL;
  55. if (FDummyDragFile != NULL)
  56. {
  57. #ifndef DESIGN_ONLY
  58. SAFE_DESTROY(FDummyDragFile);
  59. #endif
  60. }
  61. SAFE_DESTROY(FPendingDelete);
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TCustomUnixDriveView::CreateWnd()
  65. {
  66. TCustomDriveView::CreateWnd();
  67. FDragDropFilesEx->TargetEffects = TDropEffectSet() << deCopy << deMove;
  68. }
  69. //---------------------------------------------------------------------------
  70. void __fastcall TCustomUnixDriveView::SetTerminal(TTerminal * value)
  71. {
  72. if (FTerminal != value)
  73. {
  74. FTerminal = value;
  75. Items->Clear();
  76. #ifndef DESIGN_ONLY
  77. // If terminal is not active initially, we will never load fixed paths, when it become active.
  78. // But actually terminal is not active here, only when we are replacing an abandoned terminal
  79. // with a dummy one (which will never become active)
  80. if ((FTerminal != NULL) && FTerminal->Active)
  81. {
  82. TStrings * FixedPaths = FTerminal->FixedPaths;
  83. if (FixedPaths != NULL)
  84. {
  85. for (int i = 0; i < FixedPaths->Count; i++)
  86. {
  87. LoadPath(FixedPaths->Strings[i]);
  88. }
  89. }
  90. }
  91. #endif
  92. }
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TCustomUnixDriveView::SetDirView(TUnixDirView * Value)
  96. {
  97. if (FDirView != Value)
  98. {
  99. if (FDirView != NULL)
  100. {
  101. FDirView->DriveView = NULL;
  102. }
  103. FDirView = Value;
  104. if (FDirView != NULL)
  105. {
  106. FDirView->DriveView = this;
  107. }
  108. }
  109. }
  110. //---------------------------------------------------------------------------
  111. TCustomDirView * __fastcall TCustomUnixDriveView::GetCustomDirView()
  112. {
  113. return FDirView;
  114. }
  115. //---------------------------------------------------------------------------
  116. void __fastcall TCustomUnixDriveView::SetCustomDirView(TCustomDirView * Value)
  117. {
  118. SetDirView(dynamic_cast<TUnixDirView *>(Value));
  119. }
  120. //---------------------------------------------------------------------------
  121. bool __fastcall TCustomUnixDriveView::IsRootNameStored()
  122. {
  123. return (FRootName != Customunixdirview_SUnixDefaultRootName);
  124. }
  125. //---------------------------------------------------------------------------
  126. bool __fastcall TCustomUnixDriveView::NodeIsHidden(const TTreeNode * Node)
  127. {
  128. #ifndef DESIGN_ONLY
  129. TNodeData * Data = NodeData(Node);
  130. TRemoteFile * File = Data->File;
  131. return
  132. ((File != NULL) && File->IsHidden) ||
  133. ((File == NULL) && IsUnixHiddenFile(UnixExtractFileName(Data->Directory)));
  134. #else
  135. return false;
  136. #endif
  137. }
  138. //---------------------------------------------------------------------------
  139. bool __fastcall TCustomUnixDriveView::NodeTryDelete(TTreeNode * Node, bool RememberIfFails)
  140. {
  141. bool Result =
  142. (Selected == NULL) ||
  143. ((Selected != Node) && !Selected->HasAsParent(Node));
  144. if (Result)
  145. {
  146. Node->Delete();
  147. }
  148. else
  149. {
  150. if (RememberIfFails)
  151. {
  152. int I = FPendingDelete->IndexOf(Node);
  153. if (I < 0)
  154. {
  155. FPendingDelete->Add(Node);
  156. }
  157. }
  158. }
  159. return Result;
  160. }
  161. //---------------------------------------------------------------------------
  162. void __fastcall TCustomUnixDriveView::UpdatePath(TTreeNode * Node, bool Force,
  163. bool CanLoad)
  164. {
  165. #ifndef DESIGN_ONLY
  166. TNodeData * Data = NodeData(Node);
  167. UnicodeString Path = Data->Directory;
  168. TDateTime Timestamp = (Data->FileList != NULL) ? Data->FileList->Timestamp : TDateTime();
  169. TRemoteFileList * FileList = FTerminal->DirectoryFileList(Path, Timestamp, CanLoad);
  170. if ((FileList != NULL) ||
  171. ((Data->FileList != NULL) && Force))
  172. {
  173. TStringList * ChildrenDirs = new TStringList();
  174. TRemoteFileList * OldFileList = NULL;
  175. try
  176. {
  177. if (FileList != NULL)
  178. {
  179. OldFileList = Data->FileList;
  180. Data->FileList = FileList;
  181. }
  182. ChildrenDirs->Duplicates = Types::dupAccept;
  183. ChildrenDirs->CaseSensitive = true;
  184. TTreeNode * ChildNode = Node->getFirstChild();
  185. while (ChildNode != NULL)
  186. {
  187. TNodeData * ChildData = NodeData(ChildNode);
  188. ChildData->File = NULL;
  189. ChildrenDirs->AddObject(UnixExtractFileName(ChildData->Directory),
  190. ChildNode);
  191. ChildNode = Node->GetNextChild(ChildNode);
  192. }
  193. // sort only after adding all items.
  194. // should be faster then keeping the list sorted since beginning
  195. ChildrenDirs->Sorted = true;
  196. for (int i = 0; i < Data->FileList->Count; i++)
  197. {
  198. TRemoteFile * File = Data->FileList->Files[i];
  199. if (File->IsDirectory && IsRealFile(File->FileName) &&
  200. (ShowHiddenDirs || !File->IsHidden) &&
  201. (ShowInaccesibleDirectories || !File->IsInaccesibleDirectory))
  202. {
  203. int ChildIndex = ChildrenDirs->IndexOf(File->FileName);
  204. if (ChildIndex >= 0)
  205. {
  206. TTreeNode * ChildNode =
  207. dynamic_cast<TTreeNode *>(ChildrenDirs->Objects[ChildIndex]);
  208. TNodeData * ChildData = NodeData(ChildNode);
  209. ChildData->File = File;
  210. UpdatePath(ChildNode, Force);
  211. }
  212. else
  213. {
  214. UnicodeString ChildPath = UnixIncludeTrailingBackslash(Path) + File->FileName;
  215. DebugAssert(!IsUnixRootPath(ChildPath));
  216. LoadPathEasy(Node, ChildPath, File);
  217. }
  218. }
  219. }
  220. for (int i = 0; i < ChildrenDirs->Count; i++)
  221. {
  222. TTreeNode * ChildNode = dynamic_cast<TTreeNode *>(ChildrenDirs->Objects[i]);
  223. TNodeData * ChildData = NodeData(ChildNode);
  224. if (ChildData->File == NULL)
  225. {
  226. NodeTryDelete(ChildNode, true);
  227. }
  228. }
  229. Node->AlphaSort(false);
  230. }
  231. __finally
  232. {
  233. delete ChildrenDirs;
  234. // Relese only files only now, once they are no longer references in the tree
  235. delete OldFileList; // if not NULL
  236. }
  237. }
  238. else if (Force)
  239. {
  240. TTreeNode * ChildNode = Node->GetLastChild();
  241. while (ChildNode != NULL)
  242. {
  243. TTreeNode * PrevChildNode = Node->GetPrevChild(ChildNode);
  244. TRemoteFile * File = NodeFile(ChildNode);
  245. if (((ShowHiddenDirs || !NodeIsHidden(ChildNode)) &&
  246. (ShowInaccesibleDirectories || (File == NULL) || !File->IsInaccesibleDirectory)) ||
  247. !NodeTryDelete(ChildNode, true))
  248. {
  249. UpdatePath(ChildNode, true);
  250. }
  251. ChildNode = PrevChildNode;
  252. }
  253. }
  254. #else
  255. DebugUsedParam(Node);
  256. DebugUsedParam(Force);
  257. DebugUsedParam(CanLoad);
  258. #endif
  259. }
  260. //---------------------------------------------------------------------------
  261. TTreeNode * __fastcall TCustomUnixDriveView::LoadPathEasy(TTreeNode * Parent,
  262. UnicodeString Path, TRemoteFile * File)
  263. {
  264. #ifndef DESIGN_ONLY
  265. DebugAssert(Path == UnixExcludeTrailingBackslash(Path));
  266. UnicodeString DirName;
  267. if (IsUnixRootPath(Path))
  268. {
  269. DirName = RootName;
  270. }
  271. else
  272. {
  273. DirName = UnixExtractFileName(Path);
  274. }
  275. TTreeNode * Node = Items->AddChild(Parent, DirName);
  276. TNodeData * Data = new TNodeData();
  277. Node->Data = Data;
  278. Data->Directory = Path;
  279. Data->File = File;
  280. Data->FileList = NULL;
  281. UpdatePath(Node, true);
  282. return Node;
  283. #else
  284. DebugUsedParam(Parent);
  285. DebugUsedParam(File);
  286. return NULL;
  287. #endif
  288. }
  289. //---------------------------------------------------------------------------
  290. TTreeNode * __fastcall TCustomUnixDriveView::LoadPath(UnicodeString Path)
  291. {
  292. #ifndef DESIGN_ONLY
  293. if (Path.IsEmpty())
  294. {
  295. Path = ROOTDIRECTORY;
  296. }
  297. TTreeNode * Node = FindNodeToPath(Path);
  298. if (Node == NULL)
  299. {
  300. Path = UnixExcludeTrailingBackslash(Path);
  301. TTreeNode * Parent = NULL;
  302. TRemoteFile * File = NULL;
  303. if (!IsUnixRootPath(Path))
  304. {
  305. Parent = LoadPath(UnixExtractFileDir(Path));
  306. }
  307. Node = FindNodeToPath(Path);
  308. if (Node == NULL)
  309. {
  310. // node still does not exist, this should happen only when
  311. // if the parent directory is not in cache
  312. if (Parent != NULL)
  313. {
  314. TRemoteFileList * ParentFileList = NodeFileList(Parent);
  315. if (ParentFileList != NULL)
  316. {
  317. File = ParentFileList->FindFile(UnixExtractFileName(Path));
  318. }
  319. }
  320. Node = LoadPathEasy(Parent, Path, File);
  321. if (Parent != NULL)
  322. {
  323. Parent->AlphaSort(false);
  324. }
  325. }
  326. else
  327. {
  328. UpdatePath(Node, false);
  329. }
  330. }
  331. else
  332. {
  333. UpdatePath(Node, false);
  334. }
  335. return Node;
  336. #else
  337. return NULL;
  338. #endif
  339. }
  340. //---------------------------------------------------------------------------
  341. void __fastcall TCustomUnixDriveView::LoadDirectory()
  342. {
  343. #ifndef DESIGN_ONLY
  344. DebugAssert(!FIgnoreChange);
  345. FIgnoreChange = true;
  346. try
  347. {
  348. Selected = LoadPath(FTerminal->Files->Directory);
  349. DebugAssert(Selected != NULL);
  350. FPrevSelected = Selected;
  351. }
  352. __finally
  353. {
  354. FIgnoreChange = false;
  355. FDirectoryLoaded = true;
  356. }
  357. #endif
  358. }
  359. //---------------------------------------------------------------------------
  360. TNodeData * __fastcall TCustomUnixDriveView::NodeData(const TTreeNode * Node)
  361. {
  362. DebugAssert(Node->Data != NULL);
  363. return static_cast<TNodeData*>(Node->Data);
  364. }
  365. //---------------------------------------------------------------------------
  366. TRemoteFileList * __fastcall TCustomUnixDriveView::NodeFileList(const TTreeNode * Node)
  367. {
  368. DebugAssert(Node->Data != NULL);
  369. return static_cast<TNodeData*>(Node->Data)->FileList;
  370. }
  371. //---------------------------------------------------------------------------
  372. TRemoteFile * __fastcall TCustomUnixDriveView::NodeFile(const TTreeNode * Node)
  373. {
  374. DebugAssert(Node->Data != NULL);
  375. return static_cast<TNodeData*>(Node->Data)->File;
  376. }
  377. //---------------------------------------------------------------------------
  378. TRemoteFile * __fastcall TCustomUnixDriveView::NodeFileForce(TTreeNode * Node)
  379. {
  380. TRemoteFile * File = NodeFile(Node);
  381. if (File == NULL)
  382. {
  383. #ifndef DESIGN_ONLY
  384. SAFE_DESTROY(FDummyDragFile);
  385. FDummyDragFile = new TRemoteDirectoryFile();
  386. FDummyDragFile->FileName = Node->Text;
  387. FDummyDragFile->FullFileName = NodePathName(Node);
  388. File = FDummyDragFile;
  389. #endif
  390. }
  391. return File;
  392. }
  393. //---------------------------------------------------------------------------
  394. void __fastcall TCustomUnixDriveView::Delete(TTreeNode * Node)
  395. {
  396. if (Node == FPrevSelected)
  397. {
  398. FPrevSelected = NULL;
  399. }
  400. // optimization check
  401. if (FPendingDelete->Count > 0)
  402. {
  403. int I = FPendingDelete->IndexOf(Node);
  404. if (I >= 0)
  405. {
  406. FPendingDelete->Delete(I);
  407. }
  408. }
  409. TNodeData * Data = NULL;
  410. if (Node != NULL)
  411. {
  412. Data = NodeData(Node);
  413. }
  414. TCustomDriveView::Delete(Node);
  415. // delete file list at last, when we are sure that no child nodes exist
  416. if (Data != NULL)
  417. {
  418. #ifndef DESIGN_ONLY
  419. delete Data->FileList;
  420. #endif
  421. delete Data;
  422. }
  423. }
  424. //---------------------------------------------------------------------------
  425. void __fastcall TCustomUnixDriveView::Change(TTreeNode * Node)
  426. {
  427. #ifndef DESIGN_ONLY
  428. bool Expand = false;
  429. try
  430. {
  431. // During D&D Selected is set to NULL and then back to previous selection,
  432. // prevent actually changing directory in such case
  433. if (Reading || ControlState.Contains(csRecreating) ||
  434. (Node == NULL) || (Node == FPrevSelected))
  435. {
  436. TCustomDriveView::Change(Node);
  437. }
  438. else
  439. {
  440. // if previous node is child to newly selected one, do not expand it.
  441. // it is either already expanded and it is even being collapsed.
  442. Expand = (FPrevSelected == NULL) || !FPrevSelected->HasAsParent(Node);
  443. if (FIgnoreChange)
  444. {
  445. TCustomDriveView::Change(Node);
  446. }
  447. else
  448. {
  449. if (FDirView != NULL)
  450. {
  451. // remember current directory, so it gets selected if we move to parent
  452. // directory
  453. FDirView->ContinueSession(true);
  454. }
  455. FDirectoryLoaded = false;
  456. StartBusy();
  457. try
  458. {
  459. Terminal->ChangeDirectory(NodePathName(Node));
  460. TCustomDriveView::Change(Node);
  461. }
  462. __finally
  463. {
  464. EndBusy();
  465. if (!FDirectoryLoaded)
  466. {
  467. DebugAssert(!FIgnoreChange);
  468. Expand = false;
  469. FIgnoreChange = true;
  470. try
  471. {
  472. Selected = FPrevSelected;
  473. }
  474. __finally
  475. {
  476. FIgnoreChange = false;
  477. }
  478. }
  479. }
  480. }
  481. }
  482. }
  483. __finally
  484. {
  485. FPrevSelected = Selected;
  486. if (Expand)
  487. {
  488. Selected->Expand(false);
  489. }
  490. CheckPendingDeletes();
  491. }
  492. #else
  493. TCustomDriveView::Change(Node);
  494. #endif
  495. }
  496. //---------------------------------------------------------------------------
  497. void __fastcall TCustomUnixDriveView::CheckPendingDeletes()
  498. {
  499. int Index = 0;
  500. while (Index < FPendingDelete->Count)
  501. {
  502. TTreeNode * Node = static_cast<TTreeNode *>(FPendingDelete->Items[Index]);
  503. // this as well deletes node from FPendingDelete
  504. if (!NodeTryDelete(Node, false))
  505. {
  506. Index++;
  507. }
  508. }
  509. }
  510. //---------------------------------------------------------------------------
  511. void __fastcall TCustomUnixDriveView::PerformDragDropFileOperation(
  512. TTreeNode * Node, int Effect)
  513. {
  514. if (OnDDFileOperation)
  515. {
  516. // see a comment in TUnixDirView::PerformItemDragDropOperation
  517. if (DragDropFilesEx->FileList->Count > 0)
  518. {
  519. DebugAssert(Node != NULL);
  520. UnicodeString SourceDirectory;
  521. UnicodeString TargetDirectory;
  522. SourceDirectory = ExtractFilePath(DragDropFilesEx->FileList->Items[0]->Name);
  523. TargetDirectory = NodeData(Node)->Directory;
  524. bool DoFileOperation = true;
  525. OnDDFileOperation(
  526. this, Effect, SourceDirectory, TargetDirectory, false, DoFileOperation);
  527. }
  528. }
  529. }
  530. //---------------------------------------------------------------------------
  531. void __fastcall TCustomUnixDriveView::DDChooseEffect(int KeyState, int & Effect)
  532. {
  533. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  534. if (Effect != DROPEFFECT_None)
  535. {
  536. if (DropTarget != NULL)
  537. {
  538. if ((KeyState & (MK_CONTROL | MK_SHIFT)) == 0)
  539. {
  540. Effect = DROPEFFECT_Copy;
  541. }
  542. }
  543. else
  544. {
  545. Effect = DROPEFFECT_None;
  546. }
  547. }
  548. TCustomDriveView::DDChooseEffect(KeyState, Effect);
  549. }
  550. //---------------------------------------------------------------------------
  551. void __fastcall TCustomUnixDriveView::UpdateDropTarget()
  552. {
  553. // should never be NULL
  554. if (DropTarget != NULL)
  555. {
  556. UpdatePath(DropTarget, false, true);
  557. }
  558. }
  559. //---------------------------------------------------------------------------
  560. void __fastcall TCustomUnixDriveView::UpdateDropSource()
  561. {
  562. // DragNode may be NULL if its parent directory was reloaded as result
  563. // of D&D operation and thus all child nodes are recreated
  564. if ((DragNode != NULL) && (DragNode->Parent != NULL))
  565. {
  566. UpdatePath(DragNode->Parent, false, true);
  567. }
  568. }
  569. //---------------------------------------------------------------------------
  570. TStrings * __fastcall TCustomUnixDriveView::DragFileList()
  571. {
  572. DebugAssert(DragNode != NULL);
  573. TStrings * FileList = new TStringList();
  574. try
  575. {
  576. #ifndef DESIGN_ONLY
  577. FileList->AddObject(ExcludeTrailingBackslash(NodePathName(DragNode)),
  578. NodeFileForce(DragNode));
  579. #endif
  580. }
  581. catch(...)
  582. {
  583. delete FileList;
  584. throw;
  585. }
  586. return FileList;
  587. }
  588. //---------------------------------------------------------------------------
  589. bool __fastcall TCustomUnixDriveView::DragCompleteFileList()
  590. {
  591. return true;
  592. }
  593. //---------------------------------------------------------------------------
  594. TDropEffectSet __fastcall TCustomUnixDriveView::DDSourceEffects()
  595. {
  596. return TDropEffectSet() << deCopy << deMove;
  597. }
  598. //---------------------------------------------------------------------------
  599. UnicodeString __fastcall TCustomUnixDriveView::NodePathName(TTreeNode * Node)
  600. {
  601. // same as NodePath
  602. return NodeData(Node)->Directory;
  603. }
  604. //---------------------------------------------------------------------------
  605. void __fastcall TCustomUnixDriveView::ClearDragFileList(TFileList * FileList)
  606. {
  607. #ifndef DESIGN_ONLY
  608. if (FDummyDragFile != NULL)
  609. {
  610. SAFE_DESTROY(FDummyDragFile);
  611. }
  612. #endif
  613. TCustomDriveView::ClearDragFileList(FileList);
  614. }
  615. //---------------------------------------------------------------------------
  616. void __fastcall TCustomUnixDriveView::AddToDragFileList(TFileList * FileList,
  617. TTreeNode * Node)
  618. {
  619. UnicodeString FileName = NodePathName(Node);
  620. TRemoteFile * File = NodeFileForce(Node);
  621. if (OnDDDragFileName != NULL)
  622. {
  623. OnDDDragFileName(this, File, FileName);
  624. }
  625. FileList->AddItem(NULL, FileName);
  626. }
  627. //---------------------------------------------------------------------------
  628. UnicodeString __fastcall TCustomUnixDriveView::NodePath(TTreeNode * Node)
  629. {
  630. // same as NodePathName
  631. return NodeData(Node)->Directory;
  632. }
  633. //---------------------------------------------------------------------------
  634. bool __fastcall TCustomUnixDriveView::NodeIsRecycleBin(TTreeNode * /*Node*/)
  635. {
  636. return false;
  637. }
  638. //---------------------------------------------------------------------------
  639. bool __fastcall TCustomUnixDriveView::NodePathExists(TTreeNode * /*Node*/)
  640. {
  641. return true;
  642. }
  643. //---------------------------------------------------------------------------
  644. TColor __fastcall TCustomUnixDriveView::NodeColor(TTreeNode * Node)
  645. {
  646. DebugAssert(Node != NULL);
  647. TColor Result = static_cast<TColor>(clDefaultItemColor);
  648. #ifndef DESIGN_ONLY
  649. if (FDimmHiddenDirs && !Node->Selected)
  650. {
  651. if (NodeIsHidden(Node))
  652. {
  653. Result = clGrayText;
  654. }
  655. }
  656. #else
  657. DebugUsedParam(Node);
  658. #endif
  659. return Result;
  660. }
  661. //---------------------------------------------------------------------------
  662. Word __fastcall TCustomUnixDriveView::NodeOverlayIndexes(TTreeNode * Node)
  663. {
  664. #ifndef DESIGN_ONLY
  665. Word Result = oiNoOverlay;
  666. // Cannot query root node for file
  667. if (Node->Parent != NULL)
  668. {
  669. TRemoteFile * File = NodeFile(Node);
  670. if (File != NULL)
  671. {
  672. if (File->IsSymLink)
  673. {
  674. // broken link cannot probably happen anyway
  675. // as broken links are treated as files
  676. Result |= File->BrokenLink ? oiBrokenLink : oiLink;
  677. }
  678. if (File->IsEncrypted)
  679. {
  680. Result |= oiEncrypted;
  681. }
  682. }
  683. }
  684. return Result;
  685. #else
  686. DebugUsedParam(Node);
  687. return 0;
  688. #endif
  689. }
  690. //---------------------------------------------------------------------------
  691. void __fastcall TCustomUnixDriveView::GetImageIndex(TTreeNode * Node)
  692. {
  693. TCustomDriveView::GetImageIndex(Node);
  694. Node->ImageIndex = StdDirIcon;
  695. Node->SelectedIndex = StdDirSelIcon;
  696. }
  697. //---------------------------------------------------------------------------
  698. TTreeNode * __fastcall TCustomUnixDriveView::FindNodeToPath(UnicodeString Path)
  699. {
  700. TTreeNode * Result;
  701. #ifndef DESIGN_ONLY
  702. if (IsUnixRootPath(Path))
  703. {
  704. Result = Items->GetFirstNode();
  705. }
  706. else
  707. {
  708. Result = NULL;
  709. Path = UnixExcludeTrailingBackslash(Path);
  710. TTreeNode * Parent = NULL;
  711. if (!IsUnixRootPath(Path))
  712. {
  713. Parent = FindNodeToPath(UnixExtractFileDir(Path));
  714. }
  715. if ((Parent != NULL) && (Parent->getFirstChild() != NULL))
  716. {
  717. UnicodeString DirName = UnixExtractFileName(Path);
  718. int StartIndex = 0;
  719. int EndIndex = Parent->Count - 1;
  720. while (true)
  721. {
  722. int Index = (StartIndex + EndIndex) / 2;
  723. UnicodeString NodeDir = Parent->Item[Index]->Text;
  724. // lstrcmp is used by AlphaSort()
  725. int C = lstrcmp(DirName.c_str(), NodeDir.c_str());
  726. if (C == 0)
  727. {
  728. Result = Parent->Item[Index];
  729. break;
  730. }
  731. else if (C < 0)
  732. {
  733. if (Index == StartIndex)
  734. {
  735. break;
  736. }
  737. EndIndex = Index - 1;
  738. }
  739. else
  740. {
  741. if (Index == EndIndex)
  742. {
  743. break;
  744. }
  745. StartIndex = Index + 1;
  746. }
  747. }
  748. }
  749. }
  750. #else
  751. Result = NULL;
  752. #endif
  753. return Result;
  754. }
  755. //---------------------------------------------------------------------------
  756. TTreeNode * __fastcall TCustomUnixDriveView::FindPathNode(UnicodeString Path)
  757. {
  758. TTreeNode * Result = NULL;
  759. #ifndef DESIGN_ONLY
  760. if (Items->GetFirstNode() != NULL)
  761. {
  762. do
  763. {
  764. Result = FindNodeToPath(Path);
  765. if (Result == NULL)
  766. {
  767. DebugAssert(!IsUnixRootPath(Path));
  768. Path = UnixExtractFileDir(UnixExcludeTrailingBackslash(Path));
  769. }
  770. }
  771. while (Result == NULL);
  772. }
  773. #endif
  774. return Result;
  775. }
  776. //---------------------------------------------------------------------------
  777. void __fastcall TCustomUnixDriveView::ValidateDirectoryEx(TTreeNode * /*Node*/,
  778. TRecursiveScan /*Recurse*/, bool /*NewDirs*/)
  779. {
  780. // nothing
  781. }
  782. //---------------------------------------------------------------------------
  783. void __fastcall TCustomUnixDriveView::RebuildTree()
  784. {
  785. TTreeNode * First = Items->GetFirstNode();
  786. if (First != NULL)
  787. {
  788. UpdatePath(First, true);
  789. }
  790. }
  791. //---------------------------------------------------------------------------
  792. void __fastcall TCustomUnixDriveView::SetShowInaccesibleDirectories(bool value)
  793. {
  794. if (FShowInaccesibleDirectories != value)
  795. {
  796. FShowInaccesibleDirectories = value;
  797. RebuildTree();
  798. }
  799. }
  800. //---------------------------------------------------------------------------
  801. void __fastcall TCustomUnixDriveView::CMShowingChanged(TMessage & Message)
  802. {
  803. TCustomDriveView::Dispatch(&Message);
  804. if (Showing && (Terminal != NULL))
  805. {
  806. LoadDirectory();
  807. }
  808. }
  809. //---------------------------------------------------------------------------
  810. void __fastcall TCustomUnixDriveView::DisplayContextMenu(TTreeNode * /*Node*/,
  811. const TPoint & /*ScreenPos*/)
  812. {
  813. // TODO
  814. }
  815. //---------------------------------------------------------------------------
  816. void __fastcall TCustomUnixDriveView::DisplayPropertiesMenu(TTreeNode * /*Node*/)
  817. {
  818. // TODO
  819. }