ScpExplorer.cpp 17 KB

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