UnixDriveView.cpp 25 KB

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