ScpExplorer.cpp 13 KB

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