ScpExplorer.cpp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 "CustomPathComboBox"
  22. #pragma link "IEComboBox"
  23. #pragma link "UnixPathComboBox"
  24. #pragma link "IEPathComboBox"
  25. #pragma link "CustomDriveView"
  26. #pragma link "UnixDriveView"
  27. #pragma link "TB2Dock"
  28. #pragma link "TBX"
  29. #pragma link "TB2Item"
  30. #pragma link "TB2Toolbar"
  31. #pragma link "TBXStatusBars"
  32. #pragma link "TBXExtItems"
  33. #pragma link "TB2ExtItems"
  34. #pragma link "TBXToolPals"
  35. #pragma link "TBXLists"
  36. #pragma resource "*.dfm"
  37. //---------------------------------------------------------------------------
  38. __fastcall TScpExplorerForm::TScpExplorerForm(TComponent* Owner)
  39. : TCustomScpExplorerForm(Owner)
  40. {
  41. BackButton->LinkSubitems = HistoryMenu(osRemote, true)->Items;
  42. ForwardButton->LinkSubitems = HistoryMenu(osRemote, false)->Items;
  43. TopDock->PopupMenu = NonVisualDataModule->ExplorerBarPopup;
  44. RemoteStatusBar->PopupMenu = TopDock->PopupMenu;
  45. QueueDock->PopupMenu = TopDock->PopupMenu;
  46. RemoteDriveView->PopupMenu = TopDock->PopupMenu;
  47. BottomDock->PopupMenu = TopDock->PopupMenu;
  48. LeftDock->PopupMenu = TopDock->PopupMenu;
  49. RightDock->PopupMenu = TopDock->PopupMenu;
  50. reinterpret_cast<TLabel*>(RemotePanelSplitter)->OnDblClick = RemotePanelSplitterDblClick;
  51. QueuePanel->Parent = RemotePanel;
  52. QueueSplitter->Parent = RemotePanel;
  53. // set common explorer shorcuts to our actions
  54. NonVisualDataModule->ExplorerShortcuts();
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TScpExplorerForm::RestoreFormParams()
  58. {
  59. assert(Configuration);
  60. TCustomScpExplorerForm::RestoreFormParams();
  61. RestoreForm(WinConfiguration->ScpExplorer.WindowParams, this);
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TScpExplorerForm::ConfigurationChanged()
  65. {
  66. TCustomScpExplorerForm::ConfigurationChanged();
  67. UnixPathComboBox->ShowFullPath = WinConfiguration->ScpExplorer.ShowFullAddress;
  68. }
  69. //---------------------------------------------------------------------------
  70. void __fastcall TScpExplorerForm::RestoreParams()
  71. {
  72. assert(Configuration);
  73. TCustomScpExplorerForm::RestoreParams();
  74. RemoteDirView->UnixColProperties->ParamsStr = WinConfiguration->ScpExplorer.DirViewParams;
  75. RemoteDirView->UnixColProperties->ExtVisible = false; // just to make sure
  76. RemoteDirView->ViewStyle = (TViewStyle)WinConfiguration->ScpExplorer.ViewStyle;
  77. LoadToolbarsLayoutStr(WinConfiguration->ScpExplorer.ToolbarsLayout);
  78. SessionCombo->EditWidth = WinConfiguration->ScpExplorer.SessionComboWidth;
  79. RemoteStatusBar->Visible = WinConfiguration->ScpExplorer.StatusBar;
  80. RemoteDriveView->Visible = WinConfiguration->ScpExplorer.DriveView;
  81. RemoteDriveView->Width = WinConfiguration->ScpExplorer.DriveViewWidth;
  82. }
  83. //---------------------------------------------------------------------------
  84. void __fastcall TScpExplorerForm::StoreParams()
  85. {
  86. assert(Configuration);
  87. Configuration->BeginUpdate();
  88. try
  89. {
  90. WinConfiguration->ScpExplorer.ToolbarsLayout = GetToolbarsLayoutStr();
  91. WinConfiguration->ScpExplorer.SessionComboWidth = SessionCombo->EditWidth;
  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. RemoteDirView->SetFocus();
  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. }