UnixDriveView.cpp 23 KB

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