ScpExplorer.cpp 12 KB

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