ScpExplorer.cpp 15 KB

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