UnixDriveView.cpp 23 KB

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