ScpExplorer.cpp 13 KB

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