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