UnixDriveView.cpp 23 KB

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