UnixDriveView.cpp 25 KB

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