ScpExplorer.cpp 12 KB

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