UnixDriveView.cpp 23 KB

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