ScpExplorer.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. //---------------------------------------------------------------------------
  2. #include <WinPCH.h>
  3. #pragma hdrstop
  4. #include "ScpExplorer.h"
  5. #include "NonVisual.h"
  6. #include "Glyphs.h"
  7. //---------------------------------------------------------------------------
  8. #pragma link "CustomDirView"
  9. #pragma link "CustomScpExplorer"
  10. #pragma link "CustomUnixDirView"
  11. #pragma link "IEListView"
  12. #pragma link "NortonLikeListView"
  13. #pragma link "UnixDirView"
  14. #pragma link "CustomDriveView"
  15. #pragma link "UnixDriveView"
  16. #pragma link "TB2Dock"
  17. #pragma link "TBX"
  18. #pragma link "TB2Item"
  19. #pragma link "TB2Toolbar"
  20. #pragma link "TBXStatusBars"
  21. #pragma link "TBXExtItems"
  22. #pragma link "TB2ExtItems"
  23. #pragma link "TBXToolPals"
  24. #pragma link "TBXLists"
  25. #pragma link "ThemePageControl"
  26. #pragma link "PathLabel"
  27. #pragma resource "*.dfm"
  28. //---------------------------------------------------------------------------
  29. __fastcall TScpExplorerForm::TScpExplorerForm(TComponent* Owner)
  30. : TCustomScpExplorerForm(Owner)
  31. {
  32. BackButton->LinkSubitems = HistoryMenu(osRemote, true)->Items;
  33. ForwardButton->LinkSubitems = HistoryMenu(osRemote, false)->Items;
  34. TopDock->PopupMenu = NonVisualDataModule->ExplorerBarPopup;
  35. CopyPopup(RemoteStatusBar, TopDock);
  36. CopyPopup(QueueDock, TopDock);
  37. CopyPopup(QueueLabel, TopDock);
  38. CopyPopup(RemoteDriveView, TopDock);
  39. CopyPopup(BottomDock, TopDock);
  40. CopyPopup(LeftDock, TopDock);
  41. CopyPopup(RightDock, TopDock);
  42. CopyPopup(QueueFileList, TopDock);
  43. CopyPopup(QueueFileListSplitter, TopDock);
  44. reinterpret_cast<TLabel*>(RemotePanelSplitter)->OnDblClick = RemotePanelSplitterDblClick;
  45. QueuePanel->Parent = RemotePanel;
  46. QueueSplitter->Parent = RemotePanel;
  47. // set common explorer shorcuts to our actions
  48. NonVisualDataModule->ExplorerShortcuts();
  49. NonVisualDataModule->QueueSpeedComboBoxItem(QueueSpeedComboBoxItem);
  50. }
  51. //---------------------------------------------------------------------------
  52. void __fastcall TScpExplorerForm::RestoreFormParams()
  53. {
  54. DebugAssert(Configuration);
  55. TCustomScpExplorerForm::RestoreFormParams();
  56. RestoreForm(WinConfiguration->ScpExplorer.WindowParams, this, false, ScpExplorerWindowParamsDefault);
  57. }
  58. //---------------------------------------------------------------------------
  59. void __fastcall TScpExplorerForm::ConfigurationChanged()
  60. {
  61. TCustomScpExplorerForm::ConfigurationChanged();
  62. UpdateRemotePathComboBox(true);
  63. }
  64. //---------------------------------------------------------------------------
  65. void __fastcall TScpExplorerForm::RestoreParams()
  66. {
  67. DebugAssert(Configuration);
  68. TCustomScpExplorerForm::RestoreParams();
  69. bool HadHandleAllocated = RemoteDirView->HandleAllocated();
  70. RemoteDirView->UnixColProperties->ParamsStr = WinConfiguration->ScpExplorer.DirViewParams;
  71. RemoteDirView->UnixColProperties->ExtVisible = false; // just to make sure
  72. RemoteDirView->DirViewStyle = (TDirViewStyle)WinConfiguration->ScpExplorer.ViewStyle;
  73. if (HadHandleAllocated)
  74. {
  75. // This is here to make our persistence checks in VerifyControl pass,
  76. // but we do not want the view linger in the middle of delayed recreation anyway
  77. RemoteDirView->HandleNeeded();
  78. }
  79. LoadToolbarsLayoutStr(WinConfiguration->ScpExplorer.ToolbarsLayout, WinConfiguration->ScpExplorer.ToolbarsButtons);
  80. if (IsUWP())
  81. {
  82. UpdatesToolbar->Visible = false;
  83. }
  84. SessionsPageControl->Visible = WinConfiguration->ScpExplorer.SessionsTabs;
  85. RemoteStatusBar->Visible = WinConfiguration->ScpExplorer.StatusBar;
  86. RemoteDrivePanel->Visible = WinConfiguration->ScpExplorer.DriveView;
  87. RemoteDrivePanel->Width =
  88. LoadDimension(
  89. WinConfiguration->ScpExplorer.DriveViewWidth, WinConfiguration->ScpExplorer.DriveViewWidthPixelsPerInch, this);
  90. }
  91. //---------------------------------------------------------------------------
  92. void __fastcall TScpExplorerForm::StoreParams()
  93. {
  94. DebugAssert(Configuration);
  95. Configuration->BeginUpdate();
  96. try
  97. {
  98. WinConfiguration->ScpExplorer.ToolbarsLayout = GetToolbarsLayoutStr();
  99. WinConfiguration->ScpExplorer.ToolbarsButtons = GetToolbarsButtonsStr();
  100. WinConfiguration->ScpExplorer.SessionsTabs = SessionsPageControl->Visible;
  101. WinConfiguration->ScpExplorer.StatusBar = RemoteStatusBar->Visible;
  102. WinConfiguration->ScpExplorer.WindowParams = StoreForm(this);
  103. WinConfiguration->ScpExplorer.DirViewParams = RemoteDirView->UnixColProperties->ParamsStr;
  104. WinConfiguration->ScpExplorer.ViewStyle = RemoteDirView->DirViewStyle;
  105. WinConfiguration->ScpExplorer.DriveView = RemoteDrivePanel->Visible;
  106. WinConfiguration->ScpExplorer.DriveViewWidth = RemoteDrivePanel->Width;
  107. WinConfiguration->ScpExplorer.DriveViewWidthPixelsPerInch = GetControlPixelsPerInch(this);
  108. TCustomScpExplorerForm::StoreParams();
  109. }
  110. __finally
  111. {
  112. WinConfiguration->EndUpdate();
  113. }
  114. }
  115. //---------------------------------------------------------------------------
  116. UnicodeString __fastcall TScpExplorerForm::DefaultDownloadTargetDirectory()
  117. {
  118. UnicodeString Result = WinConfiguration->ScpExplorer.LastLocalTargetDirectory;
  119. if (!DirectoryExists(Result))
  120. {
  121. Result = GetPersonalFolder();
  122. }
  123. return Result;
  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. AddStartupSequence(L"W");
  155. // See comment in TScpCommanderForm::DoShow()
  156. UpdateControls();
  157. if (DirView(osOther)->Enabled)
  158. {
  159. DirView(osOther)->SetFocus();
  160. }
  161. AddStartupSequence(L"U");
  162. TCustomScpExplorerForm::DoShow();
  163. AddStartupSequence(L"O");
  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 SessionToolbar2;
  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 fcMenu: return MenuToolbar;
  197. case fcExplorerMenuBand: return MenuToolbar;
  198. case fcExplorerAddressBand: return AddressToolbar;
  199. case fcExplorerToolbarBand: return ButtonsToolbar;
  200. case fcExplorerSelectionBand: return SelectionToolbar;
  201. case fcExplorerSessionBand: return SessionToolbar2;
  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, -1))
  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. int Params = GUIConfiguration->SynchronizeParams;
  228. if (DoFullSynchronizeDirectories(LocalDirectory, RemoteDirectory, Mode, Params, SaveMode, -1) >= 0)
  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. { RemoteDirPanel, QueueSplitter, QueuePanel, BottomDock, RemoteStatusBar };
  243. SetVerticalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  244. TControl * RemoteControlsOrder[] =
  245. { RemoteDrivePanel, RemotePanelSplitter, RemoteDirPanel };
  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. if (!FFailedAddress.IsEmpty())
  277. {
  278. EditControl->Text = FFailedAddress;
  279. EditControl->SelectAll();
  280. }
  281. FFailedAddress = UnicodeString();
  282. }
  283. //---------------------------------------------------------------------------
  284. void __fastcall TScpExplorerForm::AddressToolbarEndModal(TObject * /*Sender*/)
  285. {
  286. if (!FFailedAddress.IsEmpty())
  287. {
  288. GoToAddress();
  289. }
  290. }
  291. //---------------------------------------------------------------------------
  292. UnicodeString __fastcall TScpExplorerForm::RemotePathComboBoxText()
  293. {
  294. UnicodeString Result;
  295. if (Terminal != NULL)
  296. {
  297. if (WinConfiguration->ScpExplorer.ShowFullAddress)
  298. {
  299. Result = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  300. }
  301. else
  302. {
  303. // this is called couple of times before the combo box is populated
  304. if (UnixPathComboBox->Strings->Count > 0)
  305. {
  306. Result = UnixPathComboBox->Strings->Strings[UnixPathComboBox->Strings->Count - 1];
  307. }
  308. }
  309. }
  310. return Result;
  311. }
  312. //---------------------------------------------------------------------------
  313. void __fastcall TScpExplorerForm::UnixPathComboBoxAcceptText(
  314. TObject * /*Sender*/, UnicodeString & NewText, bool & /*Accept*/)
  315. {
  316. if (RemoteDirView->Path != NewText)
  317. {
  318. if (!TryOpenDirectory(osRemote, NewText))
  319. {
  320. FFailedAddress = NewText;
  321. Abort();
  322. }
  323. else
  324. {
  325. NewText = RemotePathComboBoxText();
  326. }
  327. }
  328. }
  329. //---------------------------------------------------------------------------
  330. void __fastcall TScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  331. {
  332. TCustomScpExplorerForm::UpdateRemotePathComboBox(TextOnly);
  333. UnixPathComboBox->Text = RemotePathComboBoxText();
  334. }
  335. //---------------------------------------------------------------------------
  336. void __fastcall TScpExplorerForm::RemoteDirViewPathChange(
  337. TCustomDirView * /*Sender*/)
  338. {
  339. UpdateRemotePathComboBox(false);
  340. ResetIncrementalSearch();
  341. }
  342. //---------------------------------------------------------------------------
  343. void __fastcall TScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  344. {
  345. TCustomScpExplorerForm::ToolbarItemResize(Item, Width);
  346. if (Item == UnixPathComboBox)
  347. {
  348. dynamic_cast<TTBXComboBoxItem *>(Item)->MinListWidth = Width - 4;
  349. }
  350. }
  351. //---------------------------------------------------------------------------
  352. void __fastcall TScpExplorerForm::QueueSubmenuItemPopup(
  353. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  354. {
  355. NonVisualDataModule->QueueSpeedComboBoxItemUpdate(QueueSpeedComboBoxItem);
  356. }
  357. //---------------------------------------------------------------------------
  358. void __fastcall TScpExplorerForm::ChangePath(TOperationSide /*Side*/)
  359. {
  360. DebugFail();
  361. }
  362. //---------------------------------------------------------------------------
  363. bool __fastcall TScpExplorerForm::UpdateToolbarDisplayMode()
  364. {
  365. bool Result = TCustomScpExplorerForm::UpdateToolbarDisplayMode();
  366. if (Result)
  367. {
  368. // address combo width needs to be updated as caption visibility has changed
  369. ToolBarResize(AddressToolbar);
  370. }
  371. return Result;
  372. }
  373. //---------------------------------------------------------------------------
  374. void __fastcall TScpExplorerForm::RemoteStatusBarPanelClick(TTBXCustomStatusBar * /*Sender*/,
  375. TTBXStatusPanel *Panel)
  376. {
  377. FileStatusBarPanelClick(Panel, osRemote);
  378. }
  379. //---------------------------------------------------------------------------
  380. void __fastcall TScpExplorerForm::GoToAddress()
  381. {
  382. AddressToolbar->View->Selected = AddressToolbar->View->Find(UnixPathComboBox);
  383. AddressToolbar->View->EnterToolbarLoop(TTBEnterToolbarLoopOptions() << tbetExecuteSelected);
  384. }
  385. //---------------------------------------------------------------------------
  386. void __fastcall TScpExplorerForm::UpdateImages()
  387. {
  388. TCustomScpExplorerForm::UpdateImages();
  389. TImageList * ImageList = ShellImageListForControl(this, ilsSmall);
  390. UnixPathComboBox->Images = ImageList;
  391. UnixPathComboBox->SubMenuImages = ImageList;
  392. }
  393. //---------------------------------------------------------------------------
  394. bool TScpExplorerForm::SupportedSession(TSessionData * SessionData)
  395. {
  396. return !SessionData->IsLocalBrowser;
  397. }
  398. //---------------------------------------------------------------------------
  399. void __fastcall TScpExplorerForm::RemoteOpenDirButtonPopup(TTBCustomItem *, bool DebugUsedArg(FromLink))
  400. {
  401. CreateOpenDirMenu(RemoteOpenDirButton, osRemote);
  402. }
  403. //---------------------------------------------------------------------------
  404. void TScpExplorerForm::ResetLayoutColumns(TOperationSide)
  405. {
  406. RemoteDirView->UnixColProperties->ParamsStr = ScpExplorerDirViewParamsDefault;
  407. }
  408. //---------------------------------------------------------------------------
  409. void __fastcall TScpExplorerForm::UpdateControls()
  410. {
  411. TCustomScpExplorerForm::UpdateControls();
  412. if ((ActiveControl == NULL) && RemoteDirView->CanFocus())
  413. {
  414. ActiveControl = RemoteDirView;
  415. }
  416. ColumndsSubmenuItem->Enabled = (RemoteDirView->DirViewStyle == dvsReport);
  417. }