UnixDriveView.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  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 = 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. assert(!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. USEDPARAM(Node);
  243. USEDPARAM(Force);
  244. USEDPARAM(CanLoad);
  245. #endif
  246. }
  247. //---------------------------------------------------------------------------
  248. TTreeNode * __fastcall TCustomUnixDriveView::LoadPathEasy(TTreeNode * Parent,
  249. UnicodeString Path, TRemoteFile * File)
  250. {
  251. #ifndef DESIGN_ONLY
  252. assert(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. USEDPARAM(Parent);
  272. USEDPARAM(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. assert(!FIgnoreChange);
  332. FIgnoreChange = true;
  333. try
  334. {
  335. Selected = LoadPath(FTerminal->Files->Directory);
  336. assert(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. assert(Node->Data != NULL);
  350. return static_cast<TNodeData*>(Node->Data);
  351. }
  352. //---------------------------------------------------------------------------
  353. TRemoteFileList * __fastcall TCustomUnixDriveView::NodeFileList(const TTreeNode * Node)
  354. {
  355. assert(Node->Data != NULL);
  356. return static_cast<TNodeData*>(Node->Data)->FileList;
  357. }
  358. //---------------------------------------------------------------------------
  359. TRemoteFile * __fastcall TCustomUnixDriveView::NodeFile(const TTreeNode * Node)
  360. {
  361. assert(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. try
  416. {
  417. // During D&D Selected is set to NULL and then back to previous selection,
  418. // prevent actually changing directory in such case
  419. if (Reading || ControlState.Contains(csRecreating) ||
  420. FIgnoreChange || (Node == NULL) || (Node == FPrevSelected))
  421. {
  422. TCustomDriveView::Change(Node);
  423. }
  424. else
  425. {
  426. if (FDirView != NULL)
  427. {
  428. // remember current directory, so it gets selected if we move to parent
  429. // directory
  430. FDirView->ContinueSession(true);
  431. }
  432. // if previous node is child to newly selected one, do not expand it.
  433. // it is either already expanded and it is even being collapsed.
  434. bool Expand = (FPrevSelected == NULL) || !FPrevSelected->HasAsParent(Node);
  435. FDirectoryLoaded = false;
  436. try
  437. {
  438. APPLICATION_EXCEPTION_HACK_BEGIN
  439. {
  440. Terminal->ChangeDirectory(NodePathName(Node));
  441. }
  442. APPLICATION_EXCEPTION_HACK_END;
  443. TCustomDriveView::Change(Node);
  444. }
  445. __finally
  446. {
  447. if (FDirectoryLoaded)
  448. {
  449. FPrevSelected = Selected;
  450. if (Expand)
  451. {
  452. Selected->Expand(false);
  453. }
  454. }
  455. else
  456. {
  457. assert(!FIgnoreChange);
  458. FIgnoreChange = true;
  459. try
  460. {
  461. Selected = FPrevSelected;
  462. }
  463. __finally
  464. {
  465. FIgnoreChange = false;
  466. }
  467. }
  468. }
  469. }
  470. }
  471. __finally
  472. {
  473. CheckPendingDeletes();
  474. }
  475. #else
  476. TCustomDriveView::Change(Node);
  477. #endif
  478. }
  479. //---------------------------------------------------------------------------
  480. void __fastcall TCustomUnixDriveView::CheckPendingDeletes()
  481. {
  482. int Index = 0;
  483. while (Index < FPendingDelete->Count)
  484. {
  485. TTreeNode * Node = static_cast<TTreeNode *>(FPendingDelete->Items[Index]);
  486. // this as well deletes node from FPendingDelete
  487. if (!NodeTryDelete(Node, false))
  488. {
  489. Index++;
  490. }
  491. }
  492. }
  493. //---------------------------------------------------------------------------
  494. void __fastcall TCustomUnixDriveView::PerformDragDropFileOperation(
  495. TTreeNode * Node, int Effect)
  496. {
  497. if (OnDDFileOperation)
  498. {
  499. assert(DragDropFilesEx->FileList->Count > 0);
  500. assert(Node != NULL);
  501. UnicodeString SourceDirectory;
  502. UnicodeString TargetDirectory;
  503. SourceDirectory = ExtractFilePath(DragDropFilesEx->FileList->Items[0]->Name);
  504. TargetDirectory = NodeData(Node)->Directory;
  505. bool DoFileOperation = true;
  506. OnDDFileOperation(this, Effect, SourceDirectory, TargetDirectory,
  507. DoFileOperation);
  508. }
  509. }
  510. //---------------------------------------------------------------------------
  511. void __fastcall TCustomUnixDriveView::DDChooseEffect(int KeyState, int & Effect)
  512. {
  513. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  514. if (Effect != DROPEFFECT_None)
  515. {
  516. if (DropTarget != NULL)
  517. {
  518. if ((KeyState & (MK_CONTROL | MK_SHIFT)) == 0)
  519. {
  520. Effect = DROPEFFECT_Copy;
  521. }
  522. }
  523. else
  524. {
  525. Effect = DROPEFFECT_None;
  526. }
  527. }
  528. TCustomDriveView::DDChooseEffect(KeyState, Effect);
  529. }
  530. //---------------------------------------------------------------------------
  531. void __fastcall TCustomUnixDriveView::UpdateDropTarget()
  532. {
  533. // should never be NULL
  534. if (DropTarget != NULL)
  535. {
  536. UpdatePath(DropTarget, false, true);
  537. }
  538. }
  539. //---------------------------------------------------------------------------
  540. void __fastcall TCustomUnixDriveView::UpdateDropSource()
  541. {
  542. // DragNode may be NULL if its parent directory was reloaded as result
  543. // of D&D operation and thus all child nodes are recreated
  544. if ((DragNode != NULL) && (DragNode->Parent != NULL))
  545. {
  546. UpdatePath(DragNode->Parent, false, true);
  547. }
  548. }
  549. //---------------------------------------------------------------------------
  550. TStrings * __fastcall TCustomUnixDriveView::DragFileList()
  551. {
  552. assert(DragNode != NULL);
  553. TStrings * FileList = new TStringList();
  554. try
  555. {
  556. #ifndef DESIGN_ONLY
  557. FileList->AddObject(ExcludeTrailingBackslash(NodePathName(DragNode)),
  558. NodeFileForce(DragNode));
  559. #endif
  560. }
  561. catch(...)
  562. {
  563. delete FileList;
  564. throw;
  565. }
  566. return FileList;
  567. }
  568. //---------------------------------------------------------------------------
  569. bool __fastcall TCustomUnixDriveView::DragCompleteFileList()
  570. {
  571. return true;
  572. }
  573. //---------------------------------------------------------------------------
  574. TDropEffectSet __fastcall TCustomUnixDriveView::DDSourceEffects()
  575. {
  576. TDropEffectSet Result;
  577. Result << deCopy;
  578. if (DDAllowMove)
  579. {
  580. Result << deMove;
  581. }
  582. return Result;
  583. }
  584. //---------------------------------------------------------------------------
  585. UnicodeString __fastcall TCustomUnixDriveView::NodePathName(TTreeNode * Node)
  586. {
  587. // same as NodePath
  588. return NodeData(Node)->Directory;
  589. }
  590. //---------------------------------------------------------------------------
  591. void __fastcall TCustomUnixDriveView::ClearDragFileList(TFileList * FileList)
  592. {
  593. #ifndef DESIGN_ONLY
  594. if (FDummyDragFile != NULL)
  595. {
  596. SAFE_DESTROY(FDummyDragFile);
  597. }
  598. #endif
  599. TCustomDriveView::ClearDragFileList(FileList);
  600. }
  601. //---------------------------------------------------------------------------
  602. void __fastcall TCustomUnixDriveView::AddToDragFileList(TFileList * FileList,
  603. TTreeNode * Node)
  604. {
  605. UnicodeString FileName = NodePathName(Node);
  606. TRemoteFile * File = NodeFileForce(Node);
  607. if (OnDDDragFileName != NULL)
  608. {
  609. OnDDDragFileName(this, File, FileName);
  610. }
  611. FileList->AddItem(NULL, FileName);
  612. }
  613. //---------------------------------------------------------------------------
  614. UnicodeString __fastcall TCustomUnixDriveView::NodePath(TTreeNode * Node)
  615. {
  616. // same as NodePathName
  617. return NodeData(Node)->Directory;
  618. }
  619. //---------------------------------------------------------------------------
  620. bool __fastcall TCustomUnixDriveView::NodeIsRecycleBin(TTreeNode * /*Node*/)
  621. {
  622. return false;
  623. }
  624. //---------------------------------------------------------------------------
  625. bool __fastcall TCustomUnixDriveView::NodePathExists(TTreeNode * /*Node*/)
  626. {
  627. return true;
  628. }
  629. //---------------------------------------------------------------------------
  630. TColor __fastcall TCustomUnixDriveView::NodeColor(TTreeNode * Node)
  631. {
  632. assert(Node != NULL);
  633. TColor Result = static_cast<TColor>(clDefaultItemColor);
  634. #ifndef DESIGN_ONLY
  635. if (FDimmHiddenDirs && !Node->Selected)
  636. {
  637. if (NodeIsHidden(Node))
  638. {
  639. Result = clGrayText;
  640. }
  641. }
  642. #else
  643. USEDPARAM(Node);
  644. #endif
  645. return Result;
  646. }
  647. //---------------------------------------------------------------------------
  648. Word __fastcall TCustomUnixDriveView::NodeOverlayIndexes(TTreeNode * Node)
  649. {
  650. #ifndef DESIGN_ONLY
  651. Word Result = oiNoOverlay;
  652. // Cannot query root node for file
  653. if (Node->Parent != NULL)
  654. {
  655. TRemoteFile * File = NodeFile(Node);
  656. if ((File != NULL) && (File->IsSymLink))
  657. {
  658. // broken link cannot probably happen anyway
  659. // as broken links are treated as files
  660. Result |= File->BrokenLink ? oiBrokenLink : oiLink;
  661. }
  662. }
  663. return Result;
  664. #else
  665. USEDPARAM(Node);
  666. return 0;
  667. #endif
  668. }
  669. //---------------------------------------------------------------------------
  670. void __fastcall TCustomUnixDriveView::GetImageIndex(TTreeNode * Node)
  671. {
  672. TCustomDriveView::GetImageIndex(Node);
  673. Node->ImageIndex = StdDirIcon;
  674. Node->SelectedIndex = StdDirSelIcon;
  675. }
  676. //---------------------------------------------------------------------------
  677. TTreeNode * __fastcall TCustomUnixDriveView::FindNodeToPath(UnicodeString Path)
  678. {
  679. TTreeNode * Result;
  680. #ifndef DESIGN_ONLY
  681. if (IsUnixRootPath(Path))
  682. {
  683. Result = Items->GetFirstNode();
  684. }
  685. else
  686. {
  687. Result = NULL;
  688. Path = UnixExcludeTrailingBackslash(Path);
  689. TTreeNode * Parent = NULL;
  690. if (!IsUnixRootPath(Path))
  691. {
  692. Parent = FindNodeToPath(UnixExtractFileDir(Path));
  693. }
  694. if ((Parent != NULL) && (Parent->getFirstChild() != NULL))
  695. {
  696. UnicodeString DirName = UnixExtractFileName(Path);
  697. int StartIndex = 0;
  698. int EndIndex = Parent->Count - 1;
  699. while (true)
  700. {
  701. int Index = (StartIndex + EndIndex) / 2;
  702. UnicodeString NodeDir = Parent->Item[Index]->Text;
  703. // lstrcmp is used by AlphaSort()
  704. int C = lstrcmp(DirName.c_str(), NodeDir.c_str());
  705. if (C == 0)
  706. {
  707. Result = Parent->Item[Index];
  708. break;
  709. }
  710. else if (C < 0)
  711. {
  712. if (Index == StartIndex)
  713. {
  714. break;
  715. }
  716. EndIndex = Index - 1;
  717. }
  718. else
  719. {
  720. if (Index == EndIndex)
  721. {
  722. break;
  723. }
  724. StartIndex = Index + 1;
  725. }
  726. }
  727. }
  728. }
  729. #else
  730. Result = NULL;
  731. #endif
  732. return Result;
  733. }
  734. //---------------------------------------------------------------------------
  735. TTreeNode * __fastcall TCustomUnixDriveView::FindPathNode(UnicodeString Path)
  736. {
  737. TTreeNode * Result = NULL;
  738. #ifndef DESIGN_ONLY
  739. if (Items->GetFirstNode() != NULL)
  740. {
  741. do
  742. {
  743. Result = FindNodeToPath(Path);
  744. if (Result == NULL)
  745. {
  746. assert(!IsUnixRootPath(Path));
  747. Path = UnixExtractFileDir(UnixExcludeTrailingBackslash(Path));
  748. }
  749. }
  750. while (Result == NULL);
  751. }
  752. #endif
  753. return Result;
  754. }
  755. //---------------------------------------------------------------------------
  756. void __fastcall TCustomUnixDriveView::ValidateDirectoryEx(TTreeNode * /*Node*/,
  757. TRecursiveScan /*Recurse*/, bool /*NewDirs*/)
  758. {
  759. // nothing
  760. }
  761. //---------------------------------------------------------------------------
  762. void __fastcall TCustomUnixDriveView::RebuildTree()
  763. {
  764. TTreeNode * First = Items->GetFirstNode();
  765. if (First != NULL)
  766. {
  767. UpdatePath(First, true);
  768. }
  769. }
  770. //---------------------------------------------------------------------------
  771. void __fastcall TCustomUnixDriveView::SetShowInaccesibleDirectories(bool value)
  772. {
  773. if (FShowInaccesibleDirectories != value)
  774. {
  775. FShowInaccesibleDirectories = value;
  776. RebuildTree();
  777. }
  778. }
  779. //---------------------------------------------------------------------------
  780. void __fastcall TCustomUnixDriveView::CMShowingChanged(TMessage & Message)
  781. {
  782. TCustomDriveView::Dispatch(&Message);
  783. if (Showing && (Terminal != NULL))
  784. {
  785. LoadDirectory();
  786. }
  787. }
  788. //---------------------------------------------------------------------------
  789. void __fastcall TCustomUnixDriveView::DisplayContextMenu(TTreeNode * /*Node*/,
  790. const TPoint & /*ScreenPos*/)
  791. {
  792. // TODO
  793. }
  794. //---------------------------------------------------------------------------
  795. void __fastcall TCustomUnixDriveView::DisplayPropertiesMenu(TTreeNode * /*Node*/)
  796. {
  797. // TODO
  798. }