UnixDriveView.cpp 22 KB

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