1
0

UnixDirView.cpp 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include "UnixDirView.h"
  6. #include "UnixDriveView.h"
  7. #include <FileCtrl.hpp>
  8. #ifndef DESIGN_ONLY
  9. #include <CoreMain.h>
  10. #include <Terminal.h>
  11. #include <WinConfiguration.h>
  12. #include <VCLCommon.h>
  13. #endif
  14. #pragma package(smart_init)
  15. #ifndef DESIGN_ONLY
  16. #define ITEMFILE ((TRemoteFile *)(Item->Data))
  17. // noop, previously this tested that the file was in terminal's file listing,
  18. // but that cannot be safely checked now the terminal is used in multithreaded
  19. // environment
  20. #define ASSERT_VALID_ITEM
  21. #endif
  22. //---------------------------------------------------------------------------
  23. static inline void ValidCtrCheck(TUnixDirView *)
  24. {
  25. new TUnixDirView(NULL);
  26. }
  27. //---------------------------------------------------------------------------
  28. namespace Unixdirview
  29. {
  30. void __fastcall PACKAGE Register()
  31. {
  32. TComponentClass classes[1] = {__classid(TUnixDirView)};
  33. RegisterComponents(L"Scp", classes, 0);
  34. }
  35. }
  36. //---------------------------------------------------------------------------
  37. #define HOMEDIRECTORY L""
  38. //---------------------------------------------------------------------------
  39. __fastcall TUnixDirView::TUnixDirView(TComponent* Owner)
  40. : TCustomUnixDirView(Owner)
  41. {
  42. #ifndef DESIGN_ONLY
  43. FTerminal = NULL;
  44. #endif
  45. FCaseSensitive = true;
  46. FShowInaccesibleDirectories = true;
  47. FFullLoad = false;
  48. FDriveView = NULL;
  49. FInvalidNameChars = L"/";
  50. DragDropFilesEx->PreferCopy = true;
  51. }
  52. //---------------------------------------------------------------------------
  53. __fastcall TUnixDirView::~TUnixDirView()
  54. {
  55. #ifndef DESIGN_ONLY
  56. Terminal = NULL;
  57. #endif
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TUnixDirView::DisplayContextMenu(const TPoint &Where)
  61. {
  62. bool Handled = false;
  63. if (OnContextPopup)
  64. {
  65. OnContextPopup(this, ScreenToClient(Where), Handled);
  66. }
  67. if (!Handled)
  68. {
  69. if (PopupMenu && !PopupMenu->AutoPopup)
  70. {
  71. PopupMenu->Popup(Where.x, Where.y);
  72. }
  73. }
  74. }
  75. //---------------------------------------------------------------------------
  76. void __fastcall TUnixDirView::DisplayPropertiesMenu()
  77. {
  78. if (OnDisplayProperties) OnDisplayProperties(this);
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TUnixDirView::ExecuteFile(TListItem * Item)
  82. {
  83. #ifndef DESIGN_ONLY
  84. ASSERT_VALID_ITEM;
  85. if (ITEMFILE->IsDirectory ||
  86. (!Terminal->ResolvingSymlinks && !Terminal->IsEncryptingFiles()))
  87. {
  88. PathChanging(true);
  89. ChangeDirectory(ITEMFILE->FileName);
  90. }
  91. else
  92. {
  93. if (ItemFocused != Item) ItemFocused = Item;
  94. DisplayPropertiesMenu();
  95. }
  96. #else
  97. DebugUsedParam(Item);
  98. #endif
  99. }
  100. //---------------------------------------------------------------------------
  101. void __fastcall TUnixDirView::ExecuteParentDirectory()
  102. {
  103. PathChanging(true);
  104. #ifndef DESIGN_ONLY
  105. ChangeDirectory(PARENTDIRECTORY);
  106. #endif
  107. }
  108. //---------------------------------------------------------------------------
  109. void __fastcall TUnixDirView::ExecuteHomeDirectory()
  110. {
  111. #ifndef DESIGN_ONLY
  112. // don't select any directory
  113. PathChanging(false);
  114. UnicodeString APath = Terminal->SessionData->RemoteDirectory;
  115. if (WinConfiguration->DefaultDirIsHome && !APath.IsEmpty() &&
  116. !Terminal->SessionData->UpdateDirectories)
  117. {
  118. if (APath[1] != L'/')
  119. {
  120. Terminal->BeginTransaction();
  121. try
  122. {
  123. ChangeDirectory(HOMEDIRECTORY);
  124. ChangeDirectory(APath);
  125. }
  126. __finally
  127. {
  128. Terminal->EndTransaction();
  129. }
  130. }
  131. else
  132. {
  133. ChangeDirectory(APath);
  134. }
  135. }
  136. else
  137. {
  138. ChangeDirectory(HOMEDIRECTORY);
  139. }
  140. #endif
  141. }
  142. //---------------------------------------------------------------------------
  143. void __fastcall TUnixDirView::ReloadDirectory()
  144. {
  145. #ifndef DESIGN_ONLY
  146. FLastPath = L"";
  147. Terminal->ReloadDirectory();
  148. #endif
  149. }
  150. //---------------------------------------------------------------------------
  151. void __fastcall TUnixDirView::ExecuteRootDirectory()
  152. {
  153. #ifndef DESIGN_ONLY
  154. // We set LastPath to top directory, so it will be selected
  155. // after entering root directory
  156. // DISABLED: see PathChanged(): back moves to top directory, not to current
  157. PathChanging(false);
  158. ChangeDirectory(ROOTDIRECTORY);
  159. #endif
  160. }
  161. //---------------------------------------------------------------------------
  162. bool __fastcall TUnixDirView::ItemIsDirectory(TListItem * Item)
  163. {
  164. #ifndef DESIGN_ONLY
  165. ASSERT_VALID_ITEM;
  166. return ITEMFILE->IsDirectory;
  167. #else
  168. DebugUsedParam(Item);
  169. return false;
  170. #endif
  171. }
  172. //---------------------------------------------------------------------------
  173. bool __fastcall TUnixDirView::ItemIsFile(TListItem * Item)
  174. {
  175. #ifndef DESIGN_ONLY
  176. ASSERT_VALID_ITEM;
  177. return !(ITEMFILE->IsParentDirectory);
  178. #else
  179. DebugUsedParam(Item);
  180. return false;
  181. #endif
  182. }
  183. //---------------------------------------------------------------------------
  184. bool __fastcall TUnixDirView::ItemIsParentDirectory(TListItem * Item)
  185. {
  186. #ifndef DESIGN_ONLY
  187. ASSERT_VALID_ITEM;
  188. return ITEMFILE->IsParentDirectory;
  189. #else
  190. DebugUsedParam(Item);
  191. return false;
  192. #endif
  193. }
  194. //---------------------------------------------------------------------------
  195. UnicodeString __fastcall TUnixDirView::ItemFileName(TListItem * Item)
  196. {
  197. #ifndef DESIGN_ONLY
  198. ASSERT_VALID_ITEM;
  199. return ITEMFILE->FileName;
  200. #else
  201. DebugUsedParam(Item);
  202. return UnicodeString();
  203. #endif
  204. }
  205. //---------------------------------------------------------------------------
  206. __int64 __fastcall TUnixDirView::ItemFileSize(TListItem * Item)
  207. {
  208. #ifndef DESIGN_ONLY
  209. ASSERT_VALID_ITEM;
  210. return ITEMFILE->Size;
  211. #else
  212. DebugUsedParam(Item);
  213. return 0;
  214. #endif
  215. }
  216. //---------------------------------------------------------------------------
  217. UnicodeString __fastcall TUnixDirView::ItemFullFileName(TListItem * Item)
  218. {
  219. #ifndef DESIGN_ONLY
  220. ASSERT_VALID_ITEM;
  221. return ITEMFILE->FullFileName;
  222. #else
  223. DebugUsedParam(Item);
  224. return UnicodeString();
  225. #endif
  226. }
  227. //---------------------------------------------------------------------------
  228. int __fastcall TUnixDirView::ItemImageIndex(TListItem * Item, bool /*Cache*/)
  229. {
  230. #ifndef DESIGN_ONLY
  231. ASSERT_VALID_ITEM;
  232. // TCustomDirView::ItemImageIndex is used for icon caching
  233. // so we don't need it here. But it's implemented anyway.
  234. return ITEMFILE->IconIndex;
  235. #else
  236. DebugUsedParam(Item);
  237. return 0;
  238. #endif
  239. }
  240. //---------------------------------------------------------------------------
  241. bool __fastcall TUnixDirView::ItemMatchesFilter(TListItem * Item,
  242. const TFileFilter &Filter)
  243. {
  244. #ifndef DESIGN_ONLY
  245. ASSERT_VALID_ITEM;
  246. TRemoteFile *File = ITEMFILE;
  247. return
  248. ((Filter.Masks.IsEmpty()) ||
  249. FileNameMatchesMasks(File->FileName, File->IsDirectory, File->Size, File->Modification, Filter.Masks, false) ||
  250. (File->IsDirectory && Filter.Directories &&
  251. FileNameMatchesMasks(File->FileName, false, File->Size, File->Modification, Filter.Masks, false)));
  252. #else
  253. DebugUsedParam(Item);
  254. DebugUsedParam(Filter);
  255. return false;
  256. #endif
  257. }
  258. //---------------------------------------------------------------------------
  259. Word __fastcall TUnixDirView::ItemOverlayIndexes(TListItem * Item)
  260. {
  261. #ifndef DESIGN_ONLY
  262. ASSERT_VALID_ITEM;
  263. Word Result = TCustomDirView::ItemOverlayIndexes(Item);
  264. if (ITEMFILE->IsParentDirectory)
  265. {
  266. Result |= oiDirUp;
  267. }
  268. if (ITEMFILE->IsSymLink)
  269. {
  270. Result |= ITEMFILE->BrokenLink ? oiBrokenLink : oiLink;
  271. }
  272. if (ITEMFILE->IsEncrypted)
  273. {
  274. Result |= oiEncrypted;
  275. }
  276. return Result;
  277. #else
  278. DebugUsedParam(Item);
  279. return 0;
  280. #endif
  281. }
  282. //---------------------------------------------------------------------------
  283. void __fastcall TUnixDirView::LoadFiles()
  284. {
  285. #ifndef DESIGN_ONLY
  286. DebugAssert(Terminal);
  287. if (DirOK)
  288. {
  289. // it's enough if we reach this point, we don't require that loading files into
  290. // list succeeded. FDirLoadedAfterChangeDir == false tells only that
  291. // loding file list from server failed, not loading into listview
  292. FDirLoadedAfterChangeDir = true;
  293. FFilesSize = 0;
  294. FHasParentDir = false;
  295. int VisibleFiles = 0;
  296. FHiddenCount = 0;
  297. FFilteredCount = 0;
  298. for (int Index = 0; Index < Terminal->Files->Count; Index++)
  299. {
  300. TRemoteFile *File = Terminal->Files->Files[Index];
  301. DebugAssert(File);
  302. if ((!ShowHiddenFiles && File->IsHidden) ||
  303. (!ShowInaccesibleDirectories && File->IsInaccesibleDirectory))
  304. {
  305. FHiddenCount++;
  306. }
  307. else if (!Mask.IsEmpty() &&
  308. IsRealFile(File->FileName) &&
  309. !FileNameMatchesMasks(File->FileName, File->IsDirectory, File->Size, File->Modification, Mask, true))
  310. {
  311. FFilteredCount++;
  312. }
  313. else
  314. {
  315. VisibleFiles++;
  316. FFilesSize += File->Size;
  317. if (File->IsParentDirectory) FHasParentDir = true;
  318. TListItem * Item = new TListItem(Items);
  319. Item->Data = File;
  320. // Need to add before assigning to .Caption and .OverlayIndex,
  321. // as the setters these call back to owning view.
  322. // Assignment is redundant
  323. Item = Items->AddItem(Item);
  324. Item->Caption = File->FileName;
  325. if (FFullLoad)
  326. {
  327. // this is out of date
  328. // (missing columns and does not update then file properties are loaded)
  329. Item->ImageIndex = File->IconIndex;
  330. Item->SubItems->Add(!File->IsDirectory ? FormatPanelBytes(File->Size, FormatSizeBytes) : UnicodeString());
  331. Item->SubItems->Add(File->UserModificationStr);
  332. Item->SubItems->Add(File->RightsStr);
  333. Item->SubItems->Add(File->Owner.DisplayText);
  334. Item->SubItems->Add(File->Group.DisplayText);
  335. Item->SubItems->Add(File->Extension);
  336. }
  337. }
  338. }
  339. if (OwnerData)
  340. {
  341. Items->Count = VisibleFiles;
  342. }
  343. }
  344. #endif
  345. }
  346. //---------------------------------------------------------------------------
  347. void __fastcall TUnixDirView::GetDisplayInfo(TListItem * Item, tagLVITEMW &DispInfo)
  348. {
  349. if (!FFullLoad)
  350. {
  351. #ifndef DESIGN_ONLY
  352. TRemoteFile * File = ITEMFILE;
  353. if (DispInfo.mask & LVIF_TEXT)
  354. {
  355. UnicodeString Value;
  356. switch (DispInfo.iSubItem) {
  357. case uvName: Value = File->FileName; break;
  358. case uvSize:
  359. // expanded from ?: to avoid memory leaks
  360. if (!File->IsDirectory)
  361. {
  362. Value = FormatPanelBytes(File->Size, FormatSizeBytes);
  363. }
  364. break;
  365. case uvChanged: Value = File->UserModificationStr; break;
  366. case uvRights: Value = File->RightsStr; break;
  367. case uvOwner: Value = File->Owner.DisplayText; break;
  368. case uvGroup: Value = File->Group.DisplayText; break;
  369. case uvExt: Value = File->Extension; break;
  370. case uvLinkTarget: Value = File->LinkTo; break;
  371. case uvType: Value = File->TypeName; break;
  372. default: DebugFail();
  373. }
  374. StrPLCopy(DispInfo.pszText, Value, DispInfo.cchTextMax);
  375. }
  376. if (DispInfo.iSubItem == 0 && DispInfo.mask & LVIF_IMAGE)
  377. {
  378. DispInfo.iImage = File->IconIndex;
  379. DispInfo.mask |= LVIF_DI_SETITEM;
  380. }
  381. #else
  382. DebugUsedParam(Item);
  383. DebugUsedParam(DispInfo);
  384. #endif
  385. }
  386. }
  387. //---------------------------------------------------------------------------
  388. bool __fastcall TUnixDirView::PasteFromClipBoard(UnicodeString TargetPath)
  389. {
  390. DragDropFilesEx->FileList->Clear();
  391. bool Result = false;
  392. if (CanPasteFromClipBoard() &&
  393. DragDropFilesEx->GetFromClipboard())
  394. {
  395. if (TargetPath.IsEmpty())
  396. {
  397. TargetPath = PathName;
  398. }
  399. PerformItemDragDropOperation(NULL, DROPEFFECT_COPY);
  400. if (OnDDExecuted != NULL)
  401. {
  402. OnDDExecuted(this, DROPEFFECT_COPY);
  403. }
  404. Result = true;
  405. }
  406. return Result;
  407. }
  408. //---------------------------------------------------------------------------
  409. void __fastcall TUnixDirView::PerformItemDragDropOperation(TListItem * Item,
  410. int Effect)
  411. {
  412. #ifndef DESIGN_ONLY
  413. if (OnDDFileOperation)
  414. {
  415. // Could be empty if the source application does not provide any files;
  416. // or if the IDataObject fails GetData, like Visual Studio Code 0.8.0.
  417. if (DragDropFilesEx->FileList->Count > 0)
  418. {
  419. UnicodeString SourceDirectory;
  420. UnicodeString TargetDirectory;
  421. SourceDirectory = ExtractFilePath(DragDropFilesEx->FileList->Items[0]->Name);
  422. if (Item)
  423. {
  424. DebugAssert(ITEMFILE->IsDirectory && (Terminal->Files->IndexOf(ITEMFILE) >= 0));
  425. TargetDirectory = ITEMFILE->FullFileName;
  426. }
  427. else
  428. {
  429. TargetDirectory = Path;
  430. }
  431. bool DoFileOperation = true;
  432. OnDDFileOperation(this, Effect, SourceDirectory, TargetDirectory,
  433. DoFileOperation);
  434. }
  435. }
  436. #else
  437. DebugUsedParam(Item);
  438. DebugUsedParam(Effect);
  439. #endif
  440. }
  441. //---------------------------------------------------------------------------
  442. void __fastcall TUnixDirView::SetItemImageIndex(TListItem * /* Item */, int /* Index */)
  443. {
  444. // TCustomDirView::SetItemImageIndex is used for icon caching
  445. // so we don't need it here.
  446. }
  447. //---------------------------------------------------------------------------
  448. void __fastcall TUnixDirView::DDMenuDone(TObject* /* Sender */, HMENU /* AMenu */)
  449. {
  450. // TODO: Why I need to duplicate this method? (see TCustomDirView::DDMenuDone)
  451. }
  452. //---------------------------------------------------------------------------
  453. void __fastcall TUnixDirView::SetDriveView(TCustomUnixDriveView * Value)
  454. {
  455. if (Value != FDriveView)
  456. {
  457. if (FDriveView != NULL)
  458. {
  459. FDriveView->Terminal = NULL;
  460. }
  461. FDriveView = Value;
  462. if (FDriveView != NULL)
  463. {
  464. FDriveView->Terminal = Terminal;
  465. }
  466. }
  467. }
  468. //---------------------------------------------------------------------------
  469. #ifndef DESIGN_ONLY
  470. void __fastcall TUnixDirView::DoSetTerminal(TTerminal * value, bool Replace)
  471. {
  472. if (FTerminal != value)
  473. {
  474. if (FTerminal)
  475. {
  476. DebugAssert((FTerminal->OnReadDirectory == DoReadDirectory) || Replace);
  477. if (FTerminal->OnReadDirectory == DoReadDirectory)
  478. {
  479. FTerminal->OnReadDirectory = NULL;
  480. }
  481. DebugAssert((FTerminal->OnStartReadDirectory == DoStartReadDirectory) || Replace);
  482. if (FTerminal->OnStartReadDirectory == DoStartReadDirectory)
  483. {
  484. FTerminal->OnStartReadDirectory = NULL;
  485. }
  486. DebugAssert((FTerminal->OnChangeDirectory == DoChangeDirectory) || Replace);
  487. if (FTerminal->OnChangeDirectory == DoChangeDirectory)
  488. {
  489. FTerminal->OnChangeDirectory = NULL;
  490. }
  491. if (!value || !value->Files->Loaded)
  492. {
  493. ClearItems();
  494. }
  495. }
  496. FTerminal = value;
  497. PathChanging(false);
  498. if (FDriveView != NULL)
  499. {
  500. FDriveView->Terminal = FTerminal;
  501. }
  502. if (FTerminal)
  503. {
  504. FTerminal->OnReadDirectory = DoReadDirectory;
  505. FTerminal->OnStartReadDirectory = DoStartReadDirectory;
  506. FTerminal->OnChangeDirectory = DoChangeDirectory;
  507. FTerminal->Files->IncludeParentDirectory = AddParentDir;
  508. if (FTerminal->Files->Loaded)
  509. {
  510. DoChangeDirectory(FTerminal);
  511. DoStartReadDirectory(FTerminal); // just for style and the assertions
  512. DoReadDirectoryImpl(FTerminal, false);
  513. }
  514. }
  515. UpdatePathLabel();
  516. }
  517. }
  518. //---------------------------------------------------------------------------
  519. void __fastcall TUnixDirView::SetTerminal(TTerminal * value)
  520. {
  521. DoSetTerminal(value, false);
  522. }
  523. //---------------------------------------------------------------------------
  524. void __fastcall TUnixDirView::ReplaceTerminal(TTerminal * value)
  525. {
  526. DoSetTerminal(value, true);
  527. }
  528. #endif
  529. //---------------------------------------------------------------------------
  530. void __fastcall TUnixDirView::DoStartReadDirectory(TObject * /*Sender*/)
  531. {
  532. DebugAssert(!FLoading);
  533. FLoading = true;
  534. }
  535. //---------------------------------------------------------------------------
  536. void __fastcall TUnixDirView::DoReadDirectory(TObject * Sender, bool ReloadOnly)
  537. {
  538. DoReadDirectoryImpl(Sender, ReloadOnly);
  539. if (FOnRead != NULL)
  540. {
  541. FOnRead(this);
  542. }
  543. }
  544. //---------------------------------------------------------------------------
  545. void __fastcall TUnixDirView::DoReadDirectoryImpl(TObject * /*Sender*/, bool ReloadOnly)
  546. {
  547. DebugAssert(FLoading);
  548. FLoading = false;
  549. #ifndef DESIGN_ONLY
  550. if (Terminal->Active)
  551. {
  552. CancelEdit();
  553. if (ReloadOnly)
  554. {
  555. Reload(false);
  556. }
  557. else
  558. {
  559. Load(true);
  560. PathChanged();
  561. }
  562. if ((FDriveView != NULL) && FDriveView->Visible)
  563. {
  564. FDriveView->LoadDirectory();
  565. }
  566. }
  567. else
  568. {
  569. // Make sure file list is cleared, to remove all references to invalid
  570. // file objects. LoadFiles check for disconnected terminal, so no reloading
  571. // actually occures.
  572. Load(true);
  573. }
  574. #else
  575. DebugUsedParam(ReloadOnly);
  576. #endif
  577. }
  578. //---------------------------------------------------------------------------
  579. void __fastcall TUnixDirView::DoChangeDirectory(TObject * /*Sender*/)
  580. {
  581. #ifndef DESIGN_ONLY
  582. // Reload(false);
  583. #endif
  584. }
  585. //---------------------------------------------------------------------------
  586. bool __fastcall TUnixDirView::GetDirOK()
  587. {
  588. #ifndef DESIGN_ONLY
  589. return (Active && Terminal->Files->Loaded);
  590. #else
  591. return false;
  592. #endif
  593. }
  594. //---------------------------------------------------------------------------
  595. UnicodeString __fastcall TUnixDirView::GetPathName()
  596. {
  597. #ifndef DESIGN_ONLY
  598. if (DirOK) return Terminal->CurrentDirectory;
  599. else
  600. #endif
  601. return L"";
  602. }
  603. //---------------------------------------------------------------------------
  604. UnicodeString __fastcall TUnixDirView::GetPath()
  605. {
  606. #ifndef DESIGN_ONLY
  607. if (DirOK) return UnixIncludeTrailingBackslash(Terminal->CurrentDirectory);
  608. else
  609. #endif
  610. return L"";
  611. }
  612. //---------------------------------------------------------------------------
  613. void __fastcall TUnixDirView::SetPath(UnicodeString Value)
  614. {
  615. #ifndef DESIGN_ONLY
  616. Value = UnixExcludeTrailingBackslash(Value);
  617. if (Active && (Terminal->CurrentDirectory != Value))
  618. {
  619. PathChanging(true);
  620. Terminal->CurrentDirectory = Value;
  621. }
  622. #endif
  623. }
  624. //---------------------------------------------------------------------------
  625. #ifndef DESIGN_ONLY
  626. #define COMPARE_NUMBER(Num1, Num2) ( Num1 < Num2 ? -1 : ( Num1 > Num2 ? 1 : 0) )
  627. //---------------------------------------------------------------------------
  628. int __stdcall CompareFile(TListItem * Item1, TListItem * Item2, TUnixDirView * DirView)
  629. {
  630. DebugAssert((Item1 != NULL) && (Item2 != NULL));
  631. TRemoteFile * File1 = DebugNotNull((TRemoteFile *)(Item1->Data));
  632. TRemoteFile * File2 = DebugNotNull((TRemoteFile *)(Item2->Data));
  633. int Result;
  634. if (File1->IsParentDirectory && !File2->IsParentDirectory)
  635. {
  636. Result = -1;
  637. }
  638. else if (!File1->IsParentDirectory && File2->IsParentDirectory)
  639. {
  640. Result = 1;
  641. }
  642. else if (File1->IsDirectory && !File2->IsDirectory)
  643. {
  644. Result = -1;
  645. }
  646. else if (!File1->IsDirectory && File2->IsDirectory)
  647. {
  648. Result = 1;
  649. }
  650. else
  651. {
  652. Result = 0;
  653. switch (DirView->SortColumn)
  654. {
  655. case uvName:
  656. // fallback
  657. break;
  658. case uvSize:
  659. Result = COMPARE_NUMBER(File1->Size, File2->Size);
  660. break;
  661. case uvChanged:
  662. Result = COMPARE_NUMBER(File1->Modification, File2->Modification);
  663. break;
  664. case uvRights:
  665. Result = AnsiCompareText(File1->RightsStr, File2->RightsStr);
  666. break;
  667. case uvOwner:
  668. Result = File1->Owner.Compare(File2->Owner);
  669. break;
  670. case uvGroup:
  671. Result = File1->Group.Compare(File2->Group);
  672. break;
  673. case uvExt:
  674. // Duplicated in uvType branch
  675. if (!File1->IsDirectory)
  676. {
  677. Result = CompareLogicalText(File1->Extension, File2->Extension, DirView->NaturalOrderNumericalSorting);
  678. }
  679. else
  680. {
  681. // fallback
  682. }
  683. break;
  684. case uvLinkTarget:
  685. Result = CompareLogicalText(File1->LinkTo, File2->LinkTo, DirView->NaturalOrderNumericalSorting);
  686. break;
  687. case uvType:
  688. Result = CompareLogicalText(File1->TypeName, File2->TypeName, DirView->NaturalOrderNumericalSorting);
  689. // fallback to uvExt
  690. if ((Result == 0) && !File1->IsDirectory)
  691. {
  692. Result = CompareLogicalText(File1->Extension, File2->Extension, DirView->NaturalOrderNumericalSorting);
  693. }
  694. break;
  695. default:
  696. DebugFail();
  697. }
  698. if (Result == 0)
  699. {
  700. Result = CompareLogicalText(File1->FileName, File2->FileName, DirView->NaturalOrderNumericalSorting);
  701. }
  702. if (!DirView->UnixColProperties->SortAscending)
  703. {
  704. Result = -Result;
  705. }
  706. }
  707. return Result;
  708. }
  709. //---------------------------------------------------------------------------
  710. #undef COMPARE_NUMBER
  711. #endif
  712. //---------------------------------------------------------------------------
  713. void __fastcall TUnixDirView::SortItems()
  714. {
  715. #ifndef DESIGN_ONLY
  716. if (HandleAllocated())
  717. {
  718. CustomSortItems(CompareFile);
  719. }
  720. #endif
  721. }
  722. //---------------------------------------------------------------------------
  723. bool __fastcall TUnixDirView::GetActive()
  724. {
  725. #ifndef DESIGN_ONLY
  726. return ((Terminal != NULL) && Terminal->Active);
  727. #else
  728. return false;
  729. #endif
  730. }
  731. //---------------------------------------------------------------------------
  732. void __fastcall TUnixDirView::DDDragDetect(int grfKeyState,
  733. const TPoint &DetectStart, const TPoint &Point, TDragDetectStatus DragStatus)
  734. {
  735. if ((DragStatus == ddsDrag) && (!Loading) && (MarkedCount > 0))
  736. {
  737. TCustomUnixDirView::DDDragDetect(grfKeyState, DetectStart, Point, DragStatus);
  738. }
  739. }
  740. //---------------------------------------------------------------------------
  741. void __fastcall TUnixDirView::SetAddParentDir(bool Value)
  742. {
  743. if (Value != AddParentDir)
  744. {
  745. #ifndef DESIGN_ONLY
  746. if (Terminal) Terminal->Files->IncludeParentDirectory = Value;
  747. #endif
  748. TCustomUnixDirView::SetAddParentDir(Value);
  749. }
  750. }
  751. //---------------------------------------------------------------------------
  752. bool __fastcall TUnixDirView::TargetHasDropHandler(TListItem * /* Item */, int /* Effect */)
  753. {
  754. return false;
  755. }
  756. //---------------------------------------------------------------------------
  757. void __fastcall TUnixDirView::DDChooseEffect(int grfKeyState, int &dwEffect)
  758. {
  759. if ((grfKeyState & (MK_CONTROL | MK_SHIFT)) == 0)
  760. {
  761. dwEffect = DROPEFFECT_Copy;
  762. }
  763. TCustomDirView::DDChooseEffect(grfKeyState, dwEffect);
  764. }
  765. //---------------------------------------------------------------------------
  766. TDropEffectSet __fastcall TUnixDirView::GetDragSourceEffects()
  767. {
  768. return TDropEffectSet() << deCopy << deMove;
  769. }
  770. //---------------------------------------------------------------------------
  771. void __fastcall TUnixDirView::ChangeDirectory(UnicodeString Path)
  772. {
  773. UnicodeString LastFile = L"";
  774. if (ItemFocused) LastFile = ItemFileName(ItemFocused);
  775. ClearItems();
  776. #ifndef DESIGN_ONLY
  777. try
  778. {
  779. FDirLoadedAfterChangeDir = false;
  780. if (Path == HOMEDIRECTORY)
  781. {
  782. Terminal->HomeDirectory();
  783. }
  784. else
  785. // this works even with LockInHome
  786. if (Path == ROOTDIRECTORY)
  787. {
  788. Terminal->CurrentDirectory = ROOTDIRECTORY;
  789. }
  790. else
  791. {
  792. Terminal->ChangeDirectory(Path);
  793. }
  794. }
  795. __finally
  796. {
  797. // changing directory failed, so we load again old directory
  798. if (!FDirLoadedAfterChangeDir)
  799. {
  800. FSelectFile = LastFile;
  801. Reload(false);
  802. };
  803. }
  804. #endif
  805. }
  806. //---------------------------------------------------------------------------
  807. bool __fastcall TUnixDirView::CanEdit(TListItem* Item)
  808. {
  809. #ifndef DESIGN_ONLY
  810. DebugAssert(Terminal);
  811. return TCustomUnixDirView::CanEdit(Item) && Terminal->IsCapable[fcRename];
  812. #else
  813. DebugUsedParam(Item);
  814. return false;
  815. #endif
  816. }
  817. //---------------------------------------------------------------------------
  818. void __fastcall TUnixDirView::InternalEdit(const tagLVITEMW & HItem)
  819. {
  820. #ifndef DESIGN_ONLY
  821. TListItem *Item = GetItemFromHItem(HItem);
  822. ASSERT_VALID_ITEM;
  823. LoadEnabled = true;
  824. if (ITEMFILE->FileName != HItem.pszText)
  825. {
  826. FSelectFile = HItem.pszText;
  827. Terminal->RenameFile(ITEMFILE, HItem.pszText, true);
  828. }
  829. #else
  830. DebugUsedParam(HItem);
  831. #endif
  832. }
  833. //---------------------------------------------------------------------------
  834. int __fastcall TUnixDirView::HiddenCount()
  835. {
  836. return FHiddenCount;
  837. }
  838. //---------------------------------------------------------------------------
  839. int __fastcall TUnixDirView::FilteredCount()
  840. {
  841. return FFilteredCount;
  842. }
  843. //---------------------------------------------------------------------------
  844. void __fastcall TUnixDirView::CreateDirectory(UnicodeString DirName)
  845. {
  846. CreateDirectoryEx(DirName, NULL);
  847. }
  848. //---------------------------------------------------------------------------
  849. void __fastcall TUnixDirView::CreateDirectoryEx(UnicodeString DirName, const TRemoteProperties * Properties)
  850. {
  851. #ifndef DESIGN_ONLY
  852. DebugAssert(Terminal);
  853. // if file would be created in current directory, select it after reload
  854. if (UnixExtractFileName(DirName) == DirName)
  855. {
  856. FSelectFile = DirName;
  857. }
  858. Terminal->CreateDirectory(DirName, Properties);
  859. #else
  860. DebugUsedParam(Properties);
  861. #endif
  862. }
  863. //---------------------------------------------------------------------------
  864. bool __fastcall TUnixDirView::GetIsRoot()
  865. {
  866. #ifndef DESIGN_ONLY
  867. return (PathName == ROOTDIRECTORY);
  868. #else
  869. return false;
  870. #endif
  871. }
  872. //---------------------------------------------------------------------------
  873. TColor __fastcall TUnixDirView::ItemColor(TListItem * Item)
  874. {
  875. DebugAssert(Item);
  876. #ifndef DESIGN_ONLY
  877. if (DimmHiddenFiles && !Item->Selected && ITEMFILE->IsHidden)
  878. {
  879. return clGrayText;
  880. }
  881. else
  882. #else
  883. DebugUsedParam(Item);
  884. #endif
  885. {
  886. return (TColor)clDefaultItemColor;
  887. }
  888. }
  889. //---------------------------------------------------------------------------
  890. TDateTime __fastcall TUnixDirView::ItemFileTime(TListItem * Item,
  891. TDateTimePrecision & Precision)
  892. {
  893. DebugAssert(Item);
  894. #ifndef DESIGN_ONLY
  895. switch (ITEMFILE->ModificationFmt)
  896. {
  897. case mfNone:
  898. Precision = tpNone;
  899. break;
  900. case mfMDHM:
  901. Precision = tpMinute;
  902. break;
  903. case mfMDY:
  904. Precision = tpDay;
  905. break;
  906. case mfFull:
  907. default:
  908. Precision = tpSecond;
  909. break;
  910. }
  911. return ITEMFILE->Modification;
  912. #else
  913. DebugUsedParam(Item);
  914. Precision = tpSecond;
  915. return Now();
  916. #endif
  917. }
  918. //---------------------------------------------------------------------------
  919. TObject * __fastcall TUnixDirView::ItemData(TListItem * Item)
  920. {
  921. #ifndef DESIGN_ONLY
  922. return ITEMFILE;
  923. #else
  924. DebugUsedParam(Item);
  925. return NULL;
  926. #endif
  927. }
  928. //---------------------------------------------------------------------------
  929. void __fastcall TUnixDirView::SetShowInaccesibleDirectories(bool value)
  930. {
  931. if (FShowInaccesibleDirectories != value)
  932. {
  933. FShowInaccesibleDirectories = value;
  934. if (DirOK) Reload(false);
  935. }
  936. }
  937. //---------------------------------------------------------------------------
  938. void __fastcall TUnixDirView::AddToDragFileList(TFileList * FileList,
  939. TListItem * Item)
  940. {
  941. UnicodeString FileName = ItemFullFileName(Item);
  942. #ifndef DESIGN_ONLY
  943. if (OnDDDragFileName != NULL)
  944. {
  945. OnDDDragFileName(this, ITEMFILE, FileName);
  946. }
  947. #endif
  948. FileList->AddItem(NULL, FileName);
  949. }
  950. //---------------------------------------------------------------------------
  951. void __fastcall TUnixDirView::UpdatePathLabelCaption()
  952. {
  953. if (Terminal != NULL)
  954. {
  955. TCustomDirView::UpdatePathLabelCaption();
  956. }
  957. else
  958. {
  959. PathLabel->Caption = UnicodeString();
  960. PathLabel->Mask = UnicodeString();
  961. }
  962. }