ScpExplorer.cpp 14 KB

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