ScpExplorer.cpp 14 KB

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