ScpExplorer.cpp 16 KB

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