ScpExplorer.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "ScpExplorer.h"
  5. #include <Common.h>
  6. #include <CoreMain.h>
  7. #include "NonVisual.h"
  8. #include "Glyphs.h"
  9. #include "Tools.h"
  10. #include "WinConfiguration.h"
  11. #include <VCLCommon.h>
  12. #include <TextsWin.h>
  13. //---------------------------------------------------------------------------
  14. #pragma package(smart_init)
  15. #pragma link "CustomDirView"
  16. #pragma link "CustomScpExplorer"
  17. #pragma link "CustomUnixDirView"
  18. #pragma link "IEListView"
  19. #pragma link "NortonLikeListView"
  20. #pragma link "UnixDirView"
  21. #pragma link "CustomDriveView"
  22. #pragma link "UnixDriveView"
  23. #pragma link "TB2Dock"
  24. #pragma link "TBX"
  25. #pragma link "TB2Item"
  26. #pragma link "TB2Toolbar"
  27. #pragma link "TBXStatusBars"
  28. #pragma link "TBXExtItems"
  29. #pragma link "TB2ExtItems"
  30. #pragma link "TBXToolPals"
  31. #pragma link "TBXLists"
  32. #pragma link "ThemePageControl"
  33. #pragma link "PathLabel"
  34. #pragma resource "*.dfm"
  35. //---------------------------------------------------------------------------
  36. __fastcall TScpExplorerForm::TScpExplorerForm(TComponent* Owner)
  37. : TCustomScpExplorerForm(Owner)
  38. {
  39. BackButton->LinkSubitems = HistoryMenu(osRemote, true)->Items;
  40. ForwardButton->LinkSubitems = HistoryMenu(osRemote, false)->Items;
  41. TopDock->PopupMenu = NonVisualDataModule->ExplorerBarPopup;
  42. CopyPopup(RemoteStatusBar, TopDock);
  43. CopyPopup(QueueDock, TopDock);
  44. CopyPopup(QueueLabel, TopDock);
  45. CopyPopup(RemoteDriveView, TopDock);
  46. CopyPopup(BottomDock, TopDock);
  47. CopyPopup(LeftDock, TopDock);
  48. CopyPopup(RightDock, TopDock);
  49. CopyPopup(QueueFileList, TopDock);
  50. CopyPopup(QueueFileListSplitter, TopDock);
  51. reinterpret_cast<TLabel*>(RemotePanelSplitter)->OnDblClick = RemotePanelSplitterDblClick;
  52. QueuePanel->Parent = RemotePanel;
  53. QueueSplitter->Parent = RemotePanel;
  54. // set common explorer shorcuts to our actions
  55. NonVisualDataModule->ExplorerShortcuts();
  56. NonVisualDataModule->QueueSpeedComboBoxItem(QueueSpeedComboBoxItem);
  57. }
  58. //---------------------------------------------------------------------------
  59. void __fastcall TScpExplorerForm::RestoreFormParams()
  60. {
  61. DebugAssert(Configuration);
  62. TCustomScpExplorerForm::RestoreFormParams();
  63. RestoreForm(WinConfiguration->ScpExplorer.WindowParams, this, false, ScpExplorerWindowParamsDefault);
  64. }
  65. //---------------------------------------------------------------------------
  66. void __fastcall TScpExplorerForm::ConfigurationChanged()
  67. {
  68. TCustomScpExplorerForm::ConfigurationChanged();
  69. UpdateRemotePathComboBox(true);
  70. }
  71. //---------------------------------------------------------------------------
  72. void __fastcall TScpExplorerForm::RestoreParams()
  73. {
  74. DebugAssert(Configuration);
  75. TCustomScpExplorerForm::RestoreParams();
  76. bool HadHandleAllocated = RemoteDirView->HandleAllocated();
  77. RemoteDirView->UnixColProperties->ParamsStr = WinConfiguration->ScpExplorer.DirViewParams;
  78. RemoteDirView->UnixColProperties->ExtVisible = false; // just to make sure
  79. RemoteDirView->DirViewStyle = (TDirViewStyle)WinConfiguration->ScpExplorer.ViewStyle;
  80. if (HadHandleAllocated)
  81. {
  82. // This is here to make our persistence checks in VerifyControl pass,
  83. // but we do not want the view linger in the middle of delayed recreation anyway
  84. RemoteDirView->HandleNeeded();
  85. }
  86. LoadToolbarsLayoutStr(WinConfiguration->ScpExplorer.ToolbarsLayout, WinConfiguration->ScpExplorer.ToolbarsButtons);
  87. if (IsUWP())
  88. {
  89. UpdatesToolbar->Visible = false;
  90. }
  91. SessionsPageControl->Visible = WinConfiguration->ScpExplorer.SessionsTabs;
  92. RemoteStatusBar->Visible = WinConfiguration->ScpExplorer.StatusBar;
  93. RemoteDrivePanel->Visible = WinConfiguration->ScpExplorer.DriveView;
  94. RemoteDrivePanel->Width =
  95. LoadDimension(
  96. WinConfiguration->ScpExplorer.DriveViewWidth, WinConfiguration->ScpExplorer.DriveViewWidthPixelsPerInch, this);
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TScpExplorerForm::StoreParams()
  100. {
  101. DebugAssert(Configuration);
  102. Configuration->BeginUpdate();
  103. try
  104. {
  105. WinConfiguration->ScpExplorer.ToolbarsLayout = GetToolbarsLayoutStr();
  106. WinConfiguration->ScpExplorer.ToolbarsButtons = GetToolbarsButtonsStr();
  107. WinConfiguration->ScpExplorer.SessionsTabs = SessionsPageControl->Visible;
  108. WinConfiguration->ScpExplorer.StatusBar = RemoteStatusBar->Visible;
  109. WinConfiguration->ScpExplorer.WindowParams = StoreForm(this);
  110. WinConfiguration->ScpExplorer.DirViewParams = RemoteDirView->UnixColProperties->ParamsStr;
  111. WinConfiguration->ScpExplorer.ViewStyle = RemoteDirView->DirViewStyle;
  112. WinConfiguration->ScpExplorer.DriveView = RemoteDrivePanel->Visible;
  113. WinConfiguration->ScpExplorer.DriveViewWidth = RemoteDrivePanel->Width;
  114. WinConfiguration->ScpExplorer.DriveViewWidthPixelsPerInch = GetControlPixelsPerInch(this);
  115. TCustomScpExplorerForm::StoreParams();
  116. }
  117. __finally
  118. {
  119. WinConfiguration->EndUpdate();
  120. }
  121. }
  122. //---------------------------------------------------------------------------
  123. UnicodeString __fastcall TScpExplorerForm::DefaultDownloadTargetDirectory()
  124. {
  125. UnicodeString Result = WinConfiguration->ScpExplorer.LastLocalTargetDirectory;
  126. if (!DirectoryExists(Result))
  127. {
  128. Result = GetPersonalFolder();
  129. }
  130. return Result;
  131. }
  132. //---------------------------------------------------------------------------
  133. void __fastcall TScpExplorerForm::CopyParamDialogAfter(
  134. TTransferDirection Direction, bool Temp, const UnicodeString & TargetDirectory)
  135. {
  136. TCustomScpExplorerForm::CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  137. if ((Direction == tdToLocal) && !Temp)
  138. {
  139. WinConfiguration->ScpExplorer.LastLocalTargetDirectory = TargetDirectory;
  140. }
  141. }
  142. //---------------------------------------------------------------------------
  143. bool __fastcall TScpExplorerForm::CopyParamDialog(TTransferDirection Direction,
  144. TTransferType Type, Boolean Temp, TStrings * FileList,
  145. UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam, bool Confirm,
  146. bool DragDrop, int Options)
  147. {
  148. // Temp means d&d here so far, may change in future!
  149. if ((Direction == tdToLocal) && !Temp && TargetDirectory.IsEmpty())
  150. {
  151. TargetDirectory = DefaultDownloadTargetDirectory();
  152. }
  153. bool Result = TCustomScpExplorerForm::CopyParamDialog(
  154. Direction, Type, Temp, FileList, TargetDirectory, CopyParam, Confirm,
  155. DragDrop, Options);
  156. return Result;
  157. }
  158. //---------------------------------------------------------------------------
  159. void __fastcall TScpExplorerForm::DoShow()
  160. {
  161. AddStartupSequence(L"W");
  162. // See comment in TScpCommanderForm::DoShow()
  163. UpdateControls();
  164. if (DirView(osOther)->Enabled)
  165. {
  166. DirView(osOther)->SetFocus();
  167. }
  168. AddStartupSequence(L"U");
  169. TCustomScpExplorerForm::DoShow();
  170. AddStartupSequence(L"O");
  171. }
  172. //---------------------------------------------------------------------------
  173. bool __fastcall TScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  174. {
  175. if (Allowed == aaUpdate)
  176. {
  177. if (Action == NonVisualDataModule->FileListToCommandLineAction)
  178. {
  179. Action->Visible = false;
  180. }
  181. }
  182. #define FLAG ((TActionFlag)(Action->Tag))
  183. return
  184. TCustomScpExplorerForm::AllowedAction(Action, Allowed) &&
  185. // always require Explorer flag
  186. (FLAG & afExplorer) &&
  187. // if action is execution or update, we don't require any other flag
  188. // if we check for shortcut, we require that action is designed for remote panel
  189. ((Allowed != aaShortCut) || (FLAG & afRemote));
  190. #undef FLAG
  191. }
  192. //---------------------------------------------------------------------------
  193. TControl * __fastcall TScpExplorerForm::GetComponent(Byte Component)
  194. {
  195. switch (Component) {
  196. case fcSessionToolbar: return SessionToolbar2;
  197. case fcCustomCommandsBand: return CustomCommandsToolbar;
  198. case fcColorMenu: return reinterpret_cast<TControl*>(ColorMenuItem);
  199. case fcTransferDropDown: return reinterpret_cast<TControl*>(TransferDropDown);
  200. case fcTransferList: return reinterpret_cast<TControl*>(TransferList);
  201. case fcTransferLabel: return reinterpret_cast<TControl*>(TransferLabel);
  202. case fcRemotePathComboBox: return reinterpret_cast<TControl*>(UnixPathComboBox);
  203. case fcMenu: return MenuToolbar;
  204. case fcExplorerMenuBand: return MenuToolbar;
  205. case fcExplorerAddressBand: return AddressToolbar;
  206. case fcExplorerToolbarBand: return ButtonsToolbar;
  207. case fcExplorerSelectionBand: return SelectionToolbar;
  208. case fcExplorerSessionBand: return SessionToolbar2;
  209. case fcExplorerPreferencesBand: return PreferencesToolbar;
  210. case fcExplorerSortBand: return SortToolbar;
  211. case fcExplorerUpdatesBand: return UpdatesToolbar;
  212. case fcExplorerTransferBand: return TransferToolbar;
  213. case fcExplorerCustomCommandsBand: return CustomCommandsToolbar;
  214. default: return TCustomScpExplorerForm::GetComponent(Component);
  215. }
  216. }
  217. //---------------------------------------------------------------------------
  218. void __fastcall TScpExplorerForm::SynchronizeDirectories()
  219. {
  220. UnicodeString LocalDirectory = WinConfiguration->ScpExplorer.LastLocalTargetDirectory;
  221. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  222. if (DoSynchronizeDirectories(LocalDirectory, RemoteDirectory, -1))
  223. {
  224. WinConfiguration->ScpExplorer.LastLocalTargetDirectory = LocalDirectory;
  225. }
  226. }
  227. //---------------------------------------------------------------------------
  228. void __fastcall TScpExplorerForm::FullSynchronizeDirectories()
  229. {
  230. UnicodeString LocalDirectory = WinConfiguration->ScpExplorer.LastLocalTargetDirectory;
  231. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  232. bool SaveMode = true;
  233. TSynchronizeMode Mode = (TSynchronizeMode)GUIConfiguration->SynchronizeMode;
  234. int Params = GUIConfiguration->SynchronizeParams;
  235. if (DoFullSynchronizeDirectories(LocalDirectory, RemoteDirectory, Mode, Params, SaveMode, -1) >= 0)
  236. {
  237. WinConfiguration->ScpExplorer.LastLocalTargetDirectory = LocalDirectory;
  238. if (SaveMode)
  239. {
  240. GUIConfiguration->SynchronizeMode = Mode;
  241. }
  242. }
  243. }
  244. //---------------------------------------------------------------------------
  245. void __fastcall TScpExplorerForm::FixControlsPlacement()
  246. {
  247. TCustomScpExplorerForm::FixControlsPlacement();
  248. TControl * ControlsOrder[] =
  249. { RemoteDirPanel, QueueSplitter, QueuePanel, BottomDock, RemoteStatusBar };
  250. SetVerticalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  251. TControl * RemoteControlsOrder[] =
  252. { RemoteDrivePanel, RemotePanelSplitter, RemoteDirPanel };
  253. SetHorizontalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  254. }
  255. //---------------------------------------------------------------------------
  256. void __fastcall TScpExplorerForm::RemoteDirViewUpdateStatusBar(
  257. TObject * /*Sender*/, const TStatusFileInfo & FileInfo)
  258. {
  259. FStatusBarFileText = FileStatusBarText(FileInfo, osRemote);
  260. if (!CancelNote(false))
  261. {
  262. // if there's no note to cancel, we need to update status bar explicitly
  263. UpdateStatusBar();
  264. }
  265. UpdateFileStatusExtendedPanels(RemoteStatusBar, FileInfo);
  266. }
  267. //---------------------------------------------------------------------------
  268. void __fastcall TScpExplorerForm::RemotePanelSplitterDblClick(TObject * /*Sender*/)
  269. {
  270. // for some reason PostComponentHide is not necessary here (see queue panel)
  271. ComponentVisible[fcRemoteTree] = false;
  272. }
  273. //---------------------------------------------------------------------------
  274. void __fastcall TScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  275. {
  276. Panel->Caption = FStatusBarFileText;
  277. }
  278. //---------------------------------------------------------------------------
  279. void __fastcall TScpExplorerForm::UnixPathComboBoxBeginEdit(
  280. TTBEditItem * /*Sender*/, TTBEditItemViewer * /*Viewer*/, TEdit * EditControl)
  281. {
  282. InstallPathWordBreakProc(EditControl);
  283. if (!FFailedAddress.IsEmpty())
  284. {
  285. EditControl->Text = FFailedAddress;
  286. EditControl->SelectAll();
  287. }
  288. FFailedAddress = UnicodeString();
  289. }
  290. //---------------------------------------------------------------------------
  291. void __fastcall TScpExplorerForm::AddressToolbarEndModal(TObject * /*Sender*/)
  292. {
  293. if (!FFailedAddress.IsEmpty())
  294. {
  295. GoToAddress();
  296. }
  297. }
  298. //---------------------------------------------------------------------------
  299. UnicodeString __fastcall TScpExplorerForm::RemotePathComboBoxText()
  300. {
  301. UnicodeString Result;
  302. if (Terminal != NULL)
  303. {
  304. if (WinConfiguration->ScpExplorer.ShowFullAddress)
  305. {
  306. Result = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  307. }
  308. else
  309. {
  310. // this is called couple of times before the combo box is populated
  311. if (UnixPathComboBox->Strings->Count > 0)
  312. {
  313. Result = UnixPathComboBox->Strings->Strings[UnixPathComboBox->Strings->Count - 1];
  314. }
  315. }
  316. }
  317. return Result;
  318. }
  319. //---------------------------------------------------------------------------
  320. void __fastcall TScpExplorerForm::UnixPathComboBoxAcceptText(
  321. TObject * /*Sender*/, UnicodeString & NewText, bool & /*Accept*/)
  322. {
  323. if (RemoteDirView->Path != NewText)
  324. {
  325. if (!TryOpenDirectory(osRemote, NewText))
  326. {
  327. FFailedAddress = NewText;
  328. Abort();
  329. }
  330. else
  331. {
  332. NewText = RemotePathComboBoxText();
  333. }
  334. }
  335. }
  336. //---------------------------------------------------------------------------
  337. void __fastcall TScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  338. {
  339. TCustomScpExplorerForm::UpdateRemotePathComboBox(TextOnly);
  340. UnixPathComboBox->Text = RemotePathComboBoxText();
  341. }
  342. //---------------------------------------------------------------------------
  343. void __fastcall TScpExplorerForm::RemoteDirViewPathChange(
  344. TCustomDirView * /*Sender*/)
  345. {
  346. UpdateRemotePathComboBox(false);
  347. ResetIncrementalSearch();
  348. }
  349. //---------------------------------------------------------------------------
  350. void __fastcall TScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  351. {
  352. TCustomScpExplorerForm::ToolbarItemResize(Item, Width);
  353. if (Item == UnixPathComboBox)
  354. {
  355. dynamic_cast<TTBXComboBoxItem *>(Item)->MinListWidth = Width - 4;
  356. }
  357. }
  358. //---------------------------------------------------------------------------
  359. void __fastcall TScpExplorerForm::QueueSubmenuItemPopup(
  360. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  361. {
  362. NonVisualDataModule->QueueSpeedComboBoxItemUpdate(QueueSpeedComboBoxItem);
  363. }
  364. //---------------------------------------------------------------------------
  365. void __fastcall TScpExplorerForm::ChangePath(TOperationSide /*Side*/)
  366. {
  367. DebugFail();
  368. }
  369. //---------------------------------------------------------------------------
  370. bool __fastcall TScpExplorerForm::UpdateToolbarDisplayMode()
  371. {
  372. bool Result = TCustomScpExplorerForm::UpdateToolbarDisplayMode();
  373. if (Result)
  374. {
  375. // address combo width needs to be updated as caption visibility has changed
  376. ToolBarResize(AddressToolbar);
  377. }
  378. return Result;
  379. }
  380. //---------------------------------------------------------------------------
  381. void __fastcall TScpExplorerForm::RemoteStatusBarPanelClick(TTBXCustomStatusBar * /*Sender*/,
  382. TTBXStatusPanel *Panel)
  383. {
  384. FileStatusBarPanelClick(Panel, osRemote);
  385. }
  386. //---------------------------------------------------------------------------
  387. void __fastcall TScpExplorerForm::GoToAddress()
  388. {
  389. AddressToolbar->View->Selected = AddressToolbar->View->Find(UnixPathComboBox);
  390. AddressToolbar->View->EnterToolbarLoop(TTBEnterToolbarLoopOptions() << tbetExecuteSelected);
  391. }
  392. //---------------------------------------------------------------------------
  393. void __fastcall TScpExplorerForm::UpdateImages()
  394. {
  395. TCustomScpExplorerForm::UpdateImages();
  396. TImageList * ImageList = ShellImageListForControl(this, ilsSmall);
  397. UnixPathComboBox->Images = ImageList;
  398. UnixPathComboBox->SubMenuImages = ImageList;
  399. }
  400. //---------------------------------------------------------------------------
  401. bool TScpExplorerForm::SupportedSession(TSessionData * SessionData)
  402. {
  403. return !SessionData->IsLocalBrowser;
  404. }
  405. //---------------------------------------------------------------------------
  406. void __fastcall TScpExplorerForm::RemoteOpenDirButtonPopup(TTBCustomItem *, bool DebugUsedArg(FromLink))
  407. {
  408. CreateOpenDirMenu(RemoteOpenDirButton, osRemote);
  409. }
  410. //---------------------------------------------------------------------------
  411. void TScpExplorerForm::ResetLayoutColumns(TOperationSide)
  412. {
  413. RemoteDirView->UnixColProperties->ParamsStr = ScpExplorerDirViewParamsDefault;
  414. }
  415. //---------------------------------------------------------------------------
  416. void __fastcall TScpExplorerForm::UpdateControls()
  417. {
  418. TCustomScpExplorerForm::UpdateControls();
  419. if ((ActiveControl == NULL) && RemoteDirView->CanFocus())
  420. {
  421. ActiveControl = RemoteDirView;
  422. }
  423. ColumndsSubmenuItem->Enabled = (RemoteDirView->DirViewStyle == dvsReport);
  424. }