ScpExplorer.cpp 15 KB

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