ScpExplorer.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. RemoteStatusBar->PopupMenu = TopDock->PopupMenu;
  46. QueueDock->PopupMenu = TopDock->PopupMenu;
  47. QueueLabel->PopupMenu = TopDock->PopupMenu;
  48. RemoteDriveView->PopupMenu = TopDock->PopupMenu;
  49. BottomDock->PopupMenu = TopDock->PopupMenu;
  50. LeftDock->PopupMenu = TopDock->PopupMenu;
  51. RightDock->PopupMenu = TopDock->PopupMenu;
  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);
  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.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->ViewStyle;
  112. WinConfiguration->ScpExplorer.DriveView = RemoteDriveView->Visible;
  113. WinConfiguration->ScpExplorer.DriveViewWidth = RemoteDriveView->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. return WinConfiguration->ScpExplorer.LastLocalTargetDirectory;
  126. }
  127. //---------------------------------------------------------------------------
  128. void __fastcall TScpExplorerForm::CopyParamDialogAfter(
  129. TTransferDirection Direction, bool Temp, const UnicodeString & TargetDirectory)
  130. {
  131. TCustomScpExplorerForm::CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  132. if ((Direction == tdToLocal) && !Temp)
  133. {
  134. WinConfiguration->ScpExplorer.LastLocalTargetDirectory = TargetDirectory;
  135. }
  136. }
  137. //---------------------------------------------------------------------------
  138. bool __fastcall TScpExplorerForm::CopyParamDialog(TTransferDirection Direction,
  139. TTransferType Type, Boolean Temp, TStrings * FileList,
  140. UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam, bool Confirm,
  141. bool DragDrop, int Options)
  142. {
  143. // Temp means d&d here so far, may change in future!
  144. if ((Direction == tdToLocal) && !Temp && TargetDirectory.IsEmpty())
  145. {
  146. TargetDirectory = DefaultDownloadTargetDirectory();
  147. }
  148. bool Result = TCustomScpExplorerForm::CopyParamDialog(
  149. Direction, Type, Temp, FileList, TargetDirectory, CopyParam, Confirm,
  150. DragDrop, Options);
  151. return Result;
  152. }
  153. //---------------------------------------------------------------------------
  154. void __fastcall TScpExplorerForm::DoShow()
  155. {
  156. // See comment in TScpCommanderForm::DoShow()
  157. UpdateControls();
  158. if (RemoteDirView->Enabled)
  159. {
  160. RemoteDirView->SetFocus();
  161. }
  162. FRemoteDirViewWasFocused = true;
  163. TCustomScpExplorerForm::DoShow();
  164. }
  165. //---------------------------------------------------------------------------
  166. bool __fastcall TScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  167. {
  168. if (Allowed == aaUpdate)
  169. {
  170. if (Action == NonVisualDataModule->FileListToCommandLineAction)
  171. {
  172. Action->Visible = false;
  173. }
  174. }
  175. #define FLAG ((TActionFlag)(Action->Tag))
  176. return
  177. TCustomScpExplorerForm::AllowedAction(Action, Allowed) &&
  178. // always require Explorer flag
  179. (FLAG & afExplorer) &&
  180. // if action is execution or update, we don't require any other flag
  181. // if we check for shortcut, we require that action is designed for remote panel
  182. ((Allowed != aaShortCut) || (FLAG & afRemote));
  183. #undef FLAG
  184. }
  185. //---------------------------------------------------------------------------
  186. TControl * __fastcall TScpExplorerForm::GetComponent(Byte Component)
  187. {
  188. switch (Component) {
  189. case fcSessionToolbar: return SessionToolbar;
  190. case fcCustomCommandsBand: return CustomCommandsToolbar;
  191. case fcColorMenu: return reinterpret_cast<TControl*>(ColorMenuItem);
  192. case fcTransferDropDown: return reinterpret_cast<TControl*>(TransferDropDown);
  193. case fcTransferList: return reinterpret_cast<TControl*>(TransferList);
  194. case fcTransferLabel: return reinterpret_cast<TControl*>(TransferLabel);
  195. case fcRemotePathComboBox: return reinterpret_cast<TControl*>(UnixPathComboBox);
  196. case fcExplorerMenuBand: return MenuToolbar;
  197. case fcExplorerAddressBand: return AddressToolbar;
  198. case fcExplorerToolbarBand: return ButtonsToolbar;
  199. case fcExplorerSelectionBand: return SelectionToolbar;
  200. case fcExplorerSessionBand: return SessionToolbar;
  201. case fcExplorerPreferencesBand: return PreferencesToolbar;
  202. case fcExplorerSortBand: return SortToolbar;
  203. case fcExplorerUpdatesBand: return UpdatesToolbar;
  204. case fcExplorerTransferBand: return TransferToolbar;
  205. case fcExplorerCustomCommandsBand: return CustomCommandsToolbar;
  206. default: return TCustomScpExplorerForm::GetComponent(Component);
  207. }
  208. }
  209. //---------------------------------------------------------------------------
  210. void __fastcall TScpExplorerForm::SynchronizeDirectories()
  211. {
  212. UnicodeString LocalDirectory = WinConfiguration->ScpExplorer.LastLocalTargetDirectory;
  213. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  214. if (DoSynchronizeDirectories(LocalDirectory, RemoteDirectory, false))
  215. {
  216. WinConfiguration->ScpExplorer.LastLocalTargetDirectory = LocalDirectory;
  217. }
  218. }
  219. //---------------------------------------------------------------------------
  220. void __fastcall TScpExplorerForm::FullSynchronizeDirectories()
  221. {
  222. UnicodeString LocalDirectory = WinConfiguration->ScpExplorer.LastLocalTargetDirectory;
  223. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  224. bool SaveMode = true;
  225. TSynchronizeMode Mode = (TSynchronizeMode)GUIConfiguration->SynchronizeMode;
  226. if (DoFullSynchronizeDirectories(LocalDirectory, RemoteDirectory, Mode,
  227. SaveMode, false))
  228. {
  229. WinConfiguration->ScpExplorer.LastLocalTargetDirectory = LocalDirectory;
  230. if (SaveMode)
  231. {
  232. GUIConfiguration->SynchronizeMode = Mode;
  233. }
  234. }
  235. }
  236. //---------------------------------------------------------------------------
  237. void __fastcall TScpExplorerForm::FixControlsPlacement()
  238. {
  239. TCustomScpExplorerForm::FixControlsPlacement();
  240. TControl * ControlsOrder[] =
  241. { RemoteDirView, QueueSplitter, QueuePanel, BottomDock, RemoteStatusBar };
  242. SetVerticalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  243. TControl * RemoteControlsOrder[] =
  244. { RemoteDriveView, RemotePanelSplitter, RemoteDirView };
  245. SetHorizontalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  246. }
  247. //---------------------------------------------------------------------------
  248. void __fastcall TScpExplorerForm::RemoteDirViewUpdateStatusBar(
  249. TObject * /*Sender*/, const TStatusFileInfo & FileInfo)
  250. {
  251. FStatusBarFileText = FileStatusBarText(FileInfo, osRemote);
  252. if (!CancelNote(false))
  253. {
  254. // if there's no note to cancel, we need to update status bar explicitly
  255. UpdateStatusBar();
  256. }
  257. UpdateFileStatusExtendedPanels(RemoteStatusBar, FileInfo);
  258. }
  259. //---------------------------------------------------------------------------
  260. void __fastcall TScpExplorerForm::RemotePanelSplitterDblClick(TObject * /*Sender*/)
  261. {
  262. // for some reason PostComponentHide is not necessary here (see queue panel)
  263. ComponentVisible[fcRemoteTree] = false;
  264. }
  265. //---------------------------------------------------------------------------
  266. void __fastcall TScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  267. {
  268. Panel->Caption = FStatusBarFileText;
  269. }
  270. //---------------------------------------------------------------------------
  271. void __fastcall TScpExplorerForm::UnixPathComboBoxBeginEdit(
  272. TTBEditItem * /*Sender*/, TTBEditItemViewer * /*Viewer*/, TEdit * EditControl)
  273. {
  274. InstallPathWordBreakProc(EditControl);
  275. }
  276. //---------------------------------------------------------------------------
  277. UnicodeString __fastcall TScpExplorerForm::RemotePathComboBoxText()
  278. {
  279. UnicodeString Result;
  280. if (Terminal != NULL)
  281. {
  282. if (WinConfiguration->ScpExplorer.ShowFullAddress)
  283. {
  284. Result = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  285. }
  286. else
  287. {
  288. // this is called couple of times before the combo box is populated
  289. if (UnixPathComboBox->Strings->Count > 0)
  290. {
  291. Result = UnixPathComboBox->Strings->Strings[UnixPathComboBox->Strings->Count - 1];
  292. }
  293. }
  294. }
  295. return Result;
  296. }
  297. //---------------------------------------------------------------------------
  298. void __fastcall TScpExplorerForm::UnixPathComboBoxAcceptText(
  299. TObject * /*Sender*/, UnicodeString & NewText, bool & /*Accept*/)
  300. {
  301. if (RemoteDirView->Path != NewText)
  302. {
  303. RemoteDirView->Path = NewText;
  304. NewText = RemotePathComboBoxText();
  305. }
  306. }
  307. //---------------------------------------------------------------------------
  308. void __fastcall TScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  309. {
  310. TCustomScpExplorerForm::UpdateRemotePathComboBox(TextOnly);
  311. UnixPathComboBox->Text = RemotePathComboBoxText();
  312. }
  313. //---------------------------------------------------------------------------
  314. void __fastcall TScpExplorerForm::RemoteDirViewPathChange(
  315. TCustomDirView * /*Sender*/)
  316. {
  317. UpdateRemotePathComboBox(false);
  318. }
  319. //---------------------------------------------------------------------------
  320. void __fastcall TScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  321. {
  322. TCustomScpExplorerForm::ToolbarItemResize(Item, Width);
  323. if (Item == UnixPathComboBox)
  324. {
  325. dynamic_cast<TTBXComboBoxItem *>(Item)->MinListWidth = Width - 4;
  326. }
  327. }
  328. //---------------------------------------------------------------------------
  329. void __fastcall TScpExplorerForm::QueueSubmenuItemPopup(
  330. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  331. {
  332. NonVisualDataModule->QueueSpeedComboBoxItemUpdate(QueueSpeedComboBoxItem);
  333. }
  334. //---------------------------------------------------------------------------
  335. void __fastcall TScpExplorerForm::ChangePath(TOperationSide /*Side*/)
  336. {
  337. DebugFail();
  338. }
  339. //---------------------------------------------------------------------------
  340. bool __fastcall TScpExplorerForm::UpdateToolbarDisplayMode()
  341. {
  342. bool Result = TCustomScpExplorerForm::UpdateToolbarDisplayMode();
  343. if (Result)
  344. {
  345. // address combo width needs to be updated as caption visibility has changed
  346. ToolBarResize(AddressToolbar);
  347. }
  348. return Result;
  349. }
  350. //---------------------------------------------------------------------------
  351. void __fastcall TScpExplorerForm::RemoteStatusBarPanelClick(TTBXCustomStatusBar * /*Sender*/,
  352. TTBXStatusPanel *Panel)
  353. {
  354. FileStatusBarPanelClick(Panel, osRemote);
  355. }
  356. //---------------------------------------------------------------------------
  357. void __fastcall TScpExplorerForm::GoToAddress()
  358. {
  359. AddressToolbar->View->Selected = AddressToolbar->View->Find(UnixPathComboBox);
  360. AddressToolbar->View->EnterToolbarLoop(TTBEnterToolbarLoopOptions() << tbetExecuteSelected);
  361. }
  362. //---------------------------------------------------------------------------
  363. void __fastcall TScpExplorerForm::UpdateImages()
  364. {
  365. TCustomScpExplorerForm::UpdateImages();
  366. TImageList * ImageList = ShellImageListForControl(this, ilsSmall);
  367. UnixPathComboBox->Images = ImageList;
  368. UnixPathComboBox->SubMenuImages = ImageList;
  369. }
  370. //---------------------------------------------------------------------------