UnixDriveView.cpp 24 KB

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