UnixDriveView.cpp 21 KB

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