ScpExplorer.cpp 12 KB

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