UnixDriveView.cpp 25 KB

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