UnixDriveView.cpp 24 KB

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