ScpCommander.cpp 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "ScpCommander.h"
  5. #include <Common.h>
  6. #include <CoreMain.h>
  7. #include <Interface.h>
  8. #include <TextsCore.h>
  9. #include <TextsWin.h>
  10. #include <HelpWin.h>
  11. #include <VCLCommon.h>
  12. #include <GUITools.h>
  13. #include <DragDrop.hpp>
  14. #include <StrUtils.hpp>
  15. #include "Glyphs.h"
  16. #include "NonVisual.h"
  17. #include "Tools.h"
  18. #include "WinConfiguration.h"
  19. #include "TerminalManager.h"
  20. #include "Bookmarks.h"
  21. //---------------------------------------------------------------------------
  22. #pragma package(smart_init)
  23. #pragma link "CustomDirView"
  24. #pragma link "CustomScpExplorer"
  25. #pragma link "CustomUnixDirView"
  26. #pragma link "IEListView"
  27. #pragma link "NortonLikeListView"
  28. #pragma link "UnixDirView"
  29. #pragma link "DirView"
  30. #pragma link "PathLabel"
  31. #pragma link "HistoryComboBox"
  32. #pragma link "CustomDriveView"
  33. #pragma link "DriveView"
  34. #pragma link "UnixDriveView"
  35. #pragma link "TB2Dock"
  36. #pragma link "TB2Item"
  37. #pragma link "TB2Toolbar"
  38. #pragma link "TBX"
  39. #pragma link "TB2ExtItems"
  40. #pragma link "TBXExtItems"
  41. #pragma link "TBXLists"
  42. #pragma link "TBXStatusBars"
  43. #pragma link "TBXToolPals"
  44. #pragma link "ThemePageControl"
  45. #ifndef NO_RESOURCES
  46. #pragma resource "*.dfm"
  47. #endif
  48. //---------------------------------------------------------------------------
  49. class TSynchronizedBrowsingGuard
  50. {
  51. public:
  52. TSynchronizedBrowsingGuard()
  53. {
  54. FWasSynchronisingBrowsing = NonVisualDataModule->SynchronizeBrowsingAction->Checked;
  55. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  56. }
  57. ~TSynchronizedBrowsingGuard()
  58. {
  59. NonVisualDataModule->SynchronizeBrowsingAction->Checked = FWasSynchronisingBrowsing;
  60. }
  61. private:
  62. bool FWasSynchronisingBrowsing;
  63. };
  64. //---------------------------------------------------------------------------
  65. __fastcall TScpCommanderForm::TScpCommanderForm(TComponent* Owner)
  66. : TCustomScpExplorerForm(Owner)
  67. {
  68. FConstructed = true;
  69. FCurrentSide = osLocal;
  70. FLastLeftPanelWidth = LeftPanelWidth;
  71. FNormalPanelsWidth = -1;
  72. FSynchronisingBrowse = false;
  73. FFirstTerminal = true;
  74. FInternalDDDownloadList = new TStringList();
  75. FLocalPathComboBoxPaths = new TStringList();
  76. LocalPathComboUpdateDrives();
  77. LocalBackButton->LinkSubitems = HistoryMenu(osLocal, true)->Items;
  78. LocalForwardButton->LinkSubitems = HistoryMenu(osLocal, false)->Items;
  79. RemoteBackButton->LinkSubitems = HistoryMenu(osRemote, true)->Items;
  80. RemoteForwardButton->LinkSubitems = HistoryMenu(osRemote, false)->Items;
  81. TopDock->PopupMenu = NonVisualDataModule->CommanderBarPopup;
  82. CopyPopup(StatusBar, TopDock);
  83. CopyPopup(QueueDock, TopDock);
  84. CopyPopup(QueueLabel, TopDock);
  85. CopyPopup(BottomDock, TopDock);
  86. CopyPopup(QueueSeparatorPanel, TopDock);
  87. LocalTopDock->PopupMenu = NonVisualDataModule->LocalPanelPopup;
  88. CopyPopup(LocalPathLabel, LocalTopDock);
  89. CopyPopup(LocalStatusBar, LocalTopDock);
  90. CopyPopup(LocalDriveView, LocalTopDock);
  91. CopyPopup(LocalBottomDock, LocalTopDock);
  92. RemoteTopDock->PopupMenu = NonVisualDataModule->RemotePanelPopup;
  93. CopyPopup(RemotePathLabel, RemoteTopDock);
  94. CopyPopup(RemoteStatusBar, RemoteTopDock);
  95. CopyPopup(RemoteDriveView, RemoteTopDock);
  96. CopyPopup(RemoteBottomDock, RemoteTopDock);
  97. SetShortcuts();
  98. Splitter->ShowHint = True;
  99. LocalPanelSplitter->ShowHint = true;
  100. reinterpret_cast<TLabel*>(Splitter)->OnDblClick = SplitterDblClick;
  101. reinterpret_cast<TLabel*>(LocalPanelSplitter)->OnDblClick = PanelSplitterDblClick;
  102. reinterpret_cast<TLabel*>(RemotePanelSplitter)->OnDblClick = PanelSplitterDblClick;
  103. CommandLineCombo->Text = L"";
  104. FCommandLineComboPopulated = false;
  105. for (int i = 0; i < Toolbar2Toolbar->Items->Count; i++)
  106. {
  107. UpdateToolbar2ItemCaption(Toolbar2Toolbar->Items->Items[i]);
  108. }
  109. UseDesktopFont(LocalDirView);
  110. UseDesktopFont(LocalDriveView);
  111. UseDesktopFont(LocalPathLabel);
  112. UseDesktopFont(RemotePathLabel);
  113. UseDesktopFont(LocalStatusBar);
  114. UseDesktopFont(StatusBar);
  115. NonVisualDataModule->QueueSpeedComboBoxItem(QueueSpeedComboBoxItem);
  116. // particularly to reorder panels on right-to-left bidi mode
  117. ConfigurationChanged();
  118. }
  119. //---------------------------------------------------------------------------
  120. __fastcall TScpCommanderForm::~TScpCommanderForm()
  121. {
  122. delete FInternalDDDownloadList;
  123. SAFE_DESTROY(FLocalPathComboBoxPaths);
  124. }
  125. //---------------------------------------------------------------------------
  126. void __fastcall TScpCommanderForm::UpdateToolbar2ItemCaption(TTBCustomItem * Item)
  127. {
  128. Item->Caption =
  129. ShortCutToText(Item->ShortCut) + L" " +
  130. StripEllipsis(StripHotkey(Item->Caption));
  131. }
  132. //---------------------------------------------------------------------------
  133. void __fastcall TScpCommanderForm::RestoreFormParams()
  134. {
  135. DebugAssert(WinConfiguration);
  136. TCustomScpExplorerForm::RestoreFormParams();
  137. RestoreForm(WinConfiguration->ScpCommander.WindowParams, this);
  138. }
  139. //---------------------------------------------------------------------------
  140. void __fastcall TScpCommanderForm::RestoreParams()
  141. {
  142. DebugAssert(Configuration);
  143. TCustomScpExplorerForm::RestoreParams();
  144. LeftPanelWidth = WinConfiguration->ScpCommander.LocalPanelWidth;
  145. LoadToolbarsLayoutStr(WinConfiguration->ScpCommander.ToolbarsLayout, WinConfiguration->ScpCommander.ToolbarsButtons);
  146. if (IsUWP())
  147. {
  148. UpdatesToolbar->Visible = false;
  149. }
  150. SessionsPageControl->Visible = WinConfiguration->ScpCommander.SessionsTabs;
  151. StatusBar->Visible = WinConfiguration->ScpCommander.StatusBar;
  152. #define RESTORE_PANEL_PARAMS(PANEL) \
  153. PANEL ## DirView->ColProperties->ParamsStr = WinConfiguration->ScpCommander.PANEL ## Panel.DirViewParams; \
  154. PANEL ## StatusBar->Visible = WinConfiguration->ScpCommander.PANEL ## Panel.StatusBar; \
  155. PANEL ## DriveView->Visible = WinConfiguration->ScpCommander.PANEL ## Panel.DriveView; \
  156. if (PANEL ## DriveView->Align == alTop) \
  157. PANEL ## DriveView->Height = LoadDimension(WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewHeight, WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewHeightPixelsPerInch, this); \
  158. else \
  159. PANEL ## DriveView->Width = LoadDimension(WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewWidth, WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewWidthPixelsPerInch, this)
  160. RESTORE_PANEL_PARAMS(Local);
  161. RESTORE_PANEL_PARAMS(Remote);
  162. #undef RESTORE_PANEL_PARAMS
  163. FPanelsRestored = true;
  164. // just to make sure
  165. LocalDirView->DirColProperties->ExtVisible = false;
  166. RemoteDirView->UnixColProperties->ExtVisible = false;
  167. }
  168. //---------------------------------------------------------------------------
  169. void __fastcall TScpCommanderForm::StoreParams()
  170. {
  171. DebugAssert(WinConfiguration);
  172. WinConfiguration->BeginUpdate();
  173. try
  174. {
  175. WinConfiguration->ScpCommander.ToolbarsLayout = GetToolbarsLayoutStr();
  176. WinConfiguration->ScpCommander.ToolbarsButtons = GetToolbarsButtonsStr();
  177. WinConfiguration->ScpCommander.LocalPanelWidth = LeftPanelWidth;
  178. WinConfiguration->ScpCommander.SessionsTabs = SessionsPageControl->Visible;
  179. WinConfiguration->ScpCommander.StatusBar = StatusBar->Visible;
  180. SaveCommandLine();
  181. WinConfiguration->ScpCommander.CurrentPanel = FCurrentSide;
  182. #define STORE_PANEL_PARAMS(PANEL) \
  183. WinConfiguration->ScpCommander.PANEL ## Panel.DirViewParams = PANEL ## DirView->ColProperties->ParamsStr; \
  184. WinConfiguration->ScpCommander.PANEL ## Panel.StatusBar = PANEL ## StatusBar->Visible; \
  185. WinConfiguration->ScpCommander.PANEL ## Panel.DriveView = PANEL ## DriveView->Visible; \
  186. if (PANEL ## DriveView->Align == alTop) \
  187. { \
  188. WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewHeight = PANEL ## DriveView->Height; \
  189. WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewHeightPixelsPerInch = GetControlPixelsPerInch(this); \
  190. } \
  191. else \
  192. { \
  193. WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewWidth = PANEL ## DriveView->Width; \
  194. WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewWidthPixelsPerInch = GetControlPixelsPerInch(this); \
  195. }
  196. STORE_PANEL_PARAMS(Local);
  197. STORE_PANEL_PARAMS(Remote);
  198. #undef RESTORE_PANEL_PARAMS
  199. WinConfiguration->ScpCommander.WindowParams = StoreForm(this);
  200. TCustomScpExplorerForm::StoreParams();
  201. }
  202. __finally
  203. {
  204. WinConfiguration->EndUpdate();
  205. }
  206. }
  207. //---------------------------------------------------------------------------
  208. void __fastcall TScpCommanderForm::UpdateTerminal(TTerminal * Terminal)
  209. {
  210. TCustomScpExplorerForm::UpdateTerminal(Terminal);
  211. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  212. DebugAssert(ManagedTerminal != NULL);
  213. DebugAssert(LocalDirView != NULL);
  214. SAFE_DESTROY(ManagedTerminal->LocalExplorerState);
  215. if (WinConfiguration->PreservePanelState)
  216. {
  217. ManagedTerminal->LocalExplorerState = LocalDirView->SaveState();
  218. }
  219. }
  220. //---------------------------------------------------------------------------
  221. void __fastcall TScpCommanderForm::UpdateSessionData(TSessionData * Data)
  222. {
  223. // Keep in sync with TSessionData::CopyStateData
  224. TCustomScpExplorerForm::UpdateSessionData(Data);
  225. DebugAssert(LocalDirView);
  226. Data->LocalDirectory = LocalDirView->PathName;
  227. Data->SynchronizeBrowsing = NonVisualDataModule->SynchronizeBrowsingAction->Checked;
  228. }
  229. //---------------------------------------------------------------------------
  230. bool __fastcall TScpCommanderForm::InternalDDDownload(UnicodeString & TargetDirectory)
  231. {
  232. DebugAssert(IsFileControl(FDDTargetControl, osLocal));
  233. bool Result = false;
  234. if (FDDTargetControl == LocalDirView)
  235. {
  236. if (LocalDirView->DropTarget)
  237. {
  238. // when drop target is not directory, it is probably file type, which have
  239. // associated drop handler (such as ZIP file in WinXP). in this case we
  240. // must leave drop handling to destination application.
  241. // ! this check is duplicated in LocalDirViewDDTargetHasDropHandler()
  242. // for shellex downloads
  243. if (LocalDirView->ItemIsDirectory(LocalDirView->DropTarget))
  244. {
  245. TargetDirectory = LocalDirView->ItemFullFileName(LocalDirView->DropTarget);
  246. Result = true;
  247. }
  248. }
  249. else
  250. {
  251. TargetDirectory = DefaultDownloadTargetDirectory();
  252. Result = true;
  253. }
  254. }
  255. else if (FDDTargetControl == LocalDriveView)
  256. {
  257. DebugAssert(LocalDriveView->DropTarget != NULL);
  258. TargetDirectory = LocalDriveView->NodePathName(LocalDriveView->DropTarget);
  259. Result = true;
  260. }
  261. else
  262. {
  263. DebugFail();
  264. Abort();
  265. }
  266. return Result;
  267. }
  268. //---------------------------------------------------------------------------
  269. UnicodeString __fastcall TScpCommanderForm::DefaultDownloadTargetDirectory()
  270. {
  271. return IncludeTrailingBackslash(LocalDirView->Path);
  272. }
  273. //---------------------------------------------------------------------------
  274. bool __fastcall TScpCommanderForm::CopyParamDialog(TTransferDirection Direction,
  275. TTransferType Type, bool Temp, TStrings * FileList, UnicodeString & TargetDirectory,
  276. TGUICopyParamType & CopyParam, bool Confirm, bool DragDrop, int Options)
  277. {
  278. bool Result = false;
  279. // Temp means d&d here so far, may change in future!
  280. if (Temp && (Direction == tdToLocal) &&
  281. IsFileControl(FDDTargetControl, osLocal))
  282. {
  283. Result = InternalDDDownload(TargetDirectory);
  284. if (Result)
  285. {
  286. DebugAssert(FileList->Count > 0);
  287. FInternalDDDownloadList->Assign(FileList);
  288. }
  289. }
  290. else if (!Temp && TargetDirectory.IsEmpty())
  291. {
  292. if (Direction == tdToLocal)
  293. {
  294. TargetDirectory = DefaultDownloadTargetDirectory();
  295. }
  296. else
  297. {
  298. TargetDirectory = UnixIncludeTrailingBackslash(RemoteDirView->Path);
  299. }
  300. }
  301. if (!Result)
  302. {
  303. Result = TCustomScpExplorerForm::CopyParamDialog(Direction, Type, Temp,
  304. FileList, TargetDirectory, CopyParam, Confirm, DragDrop, Options);
  305. }
  306. return Result;
  307. }
  308. //---------------------------------------------------------------------------
  309. void __fastcall TScpCommanderForm::DoShow()
  310. {
  311. // Make sure the RemoteDirView is disabled (if not connected yet)
  312. // before the focusing below,
  313. // otherwise we disable the view while setting it focused
  314. // (UpdateControls gets calling within the SetFocus),
  315. // leading to VCL focus inconsistency wih Windows,
  316. // and the view [anothing actually] not getting focused after the session
  317. // is finally connected
  318. UpdateControls();
  319. // If we do not call SetFocus on any control before DoShow,
  320. // no control will get focused on Login dialog
  321. // (HACK seems like a bug in VCL)
  322. if (WinConfiguration->ScpCommander.CurrentPanel == osLocal)
  323. {
  324. LocalDirView->SetFocus();
  325. FRemoteDirViewWasFocused = false;
  326. }
  327. else
  328. {
  329. if (RemoteDirView->Enabled)
  330. {
  331. RemoteDirView->SetFocus();
  332. }
  333. else
  334. {
  335. LocalDirView->SetFocus();
  336. }
  337. FRemoteDirViewWasFocused = true;
  338. }
  339. TCustomScpExplorerForm::DoShow();
  340. }
  341. //---------------------------------------------------------------------------
  342. Boolean __fastcall TScpCommanderForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  343. {
  344. #define FLAG ((TActionFlag)(Action->Tag))
  345. return
  346. TCustomScpExplorerForm::AllowedAction(Action, Allowed) &&
  347. // always require Commander flag
  348. (FLAG & afCommander) &&
  349. // if action is execution or update, we don't require any other flag
  350. // if we check for shortcut, we require proper dirview to be selected
  351. ((Allowed != aaShortCut) ||
  352. ((FLAG & afLocal) && (FCurrentSide == osLocal)) ||
  353. ((FLAG & afRemote) && (FCurrentSide == osRemote))
  354. );
  355. #undef FLAG
  356. }
  357. //---------------------------------------------------------------------------
  358. TCustomDirView * __fastcall TScpCommanderForm::DirView(TOperationSide Side)
  359. {
  360. Side = GetSide(Side);
  361. if (Side == osLocal)
  362. {
  363. return LocalDirView;
  364. }
  365. else
  366. {
  367. return TCustomScpExplorerForm::DirView(Side);
  368. }
  369. }
  370. //---------------------------------------------------------------------------
  371. bool __fastcall TScpCommanderForm::DirViewEnabled(TOperationSide Side)
  372. {
  373. Side = GetSide(Side);
  374. if (Side == osLocal)
  375. {
  376. return true;
  377. }
  378. else
  379. {
  380. return TCustomScpExplorerForm::DirViewEnabled(Side);
  381. }
  382. }
  383. //---------------------------------------------------------------------------
  384. bool __fastcall TScpCommanderForm::IsFileControl(TObject * Control,
  385. TOperationSide Side)
  386. {
  387. return
  388. ((Side == osLocal) &&
  389. ((Control == LocalDirView) || (Control == LocalDriveView))) ||
  390. TCustomScpExplorerForm::IsFileControl(Control, Side);
  391. }
  392. //---------------------------------------------------------------------------
  393. void __fastcall TScpCommanderForm::ReloadLocalDirectory(const UnicodeString Directory)
  394. {
  395. if (Directory.IsEmpty() || SamePaths(Directory, LocalDirView->Path))
  396. {
  397. LocalDirView->ReloadDirectory();
  398. LocalDriveView->ValidateDirectory(LocalDriveView->Selected);
  399. }
  400. TCustomScpExplorerForm::ReloadLocalDirectory();
  401. }
  402. //---------------------------------------------------------------------------
  403. void __fastcall TScpCommanderForm::BatchStart(void *& Storage)
  404. {
  405. Storage = new bool;
  406. *static_cast<bool*>(Storage) = LocalDirView->WatchForChanges;
  407. LocalDirView->WatchForChanges = false;
  408. LocalDriveView->WatchDirectory = false;
  409. TCustomScpExplorerForm::BatchStart(Storage);
  410. }
  411. //---------------------------------------------------------------------------
  412. void __fastcall TScpCommanderForm::BatchEnd(void * Storage)
  413. {
  414. TCustomScpExplorerForm::BatchEnd(Storage);
  415. DebugAssert(Storage != NULL);
  416. LocalDirView->WatchForChanges = *static_cast<bool*>(Storage);
  417. LocalDriveView->WatchDirectory = LocalDirView->WatchForChanges;
  418. delete Storage;
  419. }
  420. //---------------------------------------------------------------------------
  421. void __fastcall TScpCommanderForm::StartingDisconnected()
  422. {
  423. TCustomScpExplorerForm::StartingDisconnected();
  424. LocalDefaultDirectory();
  425. }
  426. //---------------------------------------------------------------------------
  427. void __fastcall TScpCommanderForm::TerminalChanged(bool Replaced)
  428. {
  429. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  430. TCustomScpExplorerForm::TerminalChanged(Replaced);
  431. if (Terminal)
  432. {
  433. // we will load completelly different directory, so particularly
  434. // do not attempt to select previously selected directory
  435. LocalDirView->ContinueSession(false);
  436. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  437. DebugAssert(ManagedTerminal != NULL);
  438. // reset home directory
  439. LocalDirView->HomeDirectory = L"";
  440. if (FFirstTerminal || !WinConfiguration->ScpCommander.PreserveLocalDirectory)
  441. {
  442. UnicodeString LocalDirectory = ManagedTerminal->StateData->LocalDirectory;
  443. bool DocumentsDir = LocalDirectory.IsEmpty();
  444. if (!DocumentsDir)
  445. {
  446. try
  447. {
  448. LocalDirView->Path = LocalDirectory;
  449. }
  450. catch(Exception & E)
  451. {
  452. DocumentsDir = true;
  453. if (!Terminal->SessionData->UpdateDirectories)
  454. {
  455. Terminal->ShowExtendedException(&E);
  456. }
  457. }
  458. }
  459. if (DocumentsDir)
  460. {
  461. LocalDefaultDirectory();
  462. }
  463. }
  464. FFirstTerminal = false;
  465. if (WinConfiguration->DefaultDirIsHome &&
  466. !Terminal->SessionData->UpdateDirectories)
  467. {
  468. LocalDirView->HomeDirectory = ExpandFileName(Terminal->SessionData->LocalDirectory);
  469. }
  470. if (WinConfiguration->PreservePanelState &&
  471. !WinConfiguration->ScpCommander.PreserveLocalDirectory)
  472. {
  473. if (ManagedTerminal->LocalExplorerState != NULL)
  474. {
  475. LocalDirView->RestoreState(ManagedTerminal->LocalExplorerState);
  476. }
  477. else
  478. {
  479. LocalDirView->ClearState();
  480. }
  481. NonVisualDataModule->SynchronizeBrowsingAction->Checked = ManagedTerminal->StateData->SynchronizeBrowsing;
  482. }
  483. }
  484. }
  485. //---------------------------------------------------------------------------
  486. void __fastcall TScpCommanderForm::LocalDefaultDirectory()
  487. {
  488. try
  489. {
  490. LocalDirView->HomeDirectory = L"";
  491. LocalDirView->ExecuteHomeDirectory();
  492. }
  493. catch(Exception & E)
  494. {
  495. ShowExtendedException(NULL, &E);
  496. LocalDirView->Path = ExtractFilePath(Application->ExeName);
  497. }
  498. }
  499. //---------------------------------------------------------------------------
  500. void __fastcall TScpCommanderForm::ConfigurationChanged()
  501. {
  502. TCustomScpExplorerForm::ConfigurationChanged();
  503. if (WinConfiguration->DefaultDirIsHome && Terminal &&
  504. !Terminal->SessionData->UpdateDirectories)
  505. {
  506. LocalDirView->HomeDirectory = ExpandFileName(Terminal->SessionData->LocalDirectory);
  507. }
  508. else
  509. {
  510. LocalDirView->HomeDirectory = L"";
  511. }
  512. LocalDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  513. LocalDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  514. LocalDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  515. LocalDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  516. LocalDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  517. LocalDirView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  518. LocalDriveView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  519. LocalDirView->NortonLike = WinConfiguration->ScpCommander.NortonLikeMode;
  520. RemoteDirView->NortonLike = WinConfiguration->ScpCommander.NortonLikeMode;
  521. LocalDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  522. LocalDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  523. if (LocalDirView->RowSelect != WinConfiguration->FullRowSelect)
  524. {
  525. LocalDirView->RowSelect = WinConfiguration->FullRowSelect;
  526. // selection is not redrawn automatically when RowSelect changes
  527. LocalDirView->Invalidate();
  528. }
  529. // See also LocalDirViewDDTargetHasDropHandler
  530. LocalDirView->DragDropFilesEx->ShellExtensions->DropHandler = !WinConfiguration->DDFakeFile;
  531. LocalDriveView->DragDropFilesEx->ShellExtensions->DropHandler = !WinConfiguration->DDFakeFile;
  532. if (Panel(true)->Left > Panel(false)->Left)
  533. {
  534. DisableAlign();
  535. try
  536. {
  537. int AWidth = ClientWidth;
  538. Panel(false)->Align = alClient;
  539. // In bidi mode it gets swapped to alRight, what does not work with the rest of this logic
  540. Splitter->Align = alLeft;
  541. Panel(true)->Align = alLeft;
  542. TControl * ControlsOrder[] =
  543. { Panel(true), Splitter, Panel(false) };
  544. SetHorizontalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  545. Panel(true)->TabOrder = 0;
  546. Panel(false)->TabOrder = 1;
  547. ClientWidth = AWidth;
  548. LeftPanelWidth = FLastLeftPanelWidth;
  549. }
  550. __finally
  551. {
  552. EnableAlign();
  553. }
  554. int LocalIndex = MenuToolbar->Items->IndexOf(LocalMenuButton);
  555. int RemoteIndex = MenuToolbar->Items->IndexOf(RemoteMenuButton);
  556. MenuToolbar->Items->Move(LocalIndex, RemoteIndex);
  557. RemoteIndex = MenuToolbar->Items->IndexOf(RemoteMenuButton);
  558. MenuToolbar->Items->Move(RemoteIndex, LocalIndex);
  559. SWAP(TShortCut, NonVisualDataModule->LocalChangePathAction->ShortCut,
  560. NonVisualDataModule->RemoteChangePathAction->ShortCut);
  561. }
  562. if ((RemoteDriveView->Align == alLeft) != WinConfiguration->ScpCommander.TreeOnLeft)
  563. {
  564. TScpCommanderPanelConfiguration LocalPanel = WinConfiguration->ScpCommander.LocalPanel;
  565. TScpCommanderPanelConfiguration RemotePanel = WinConfiguration->ScpCommander.RemotePanel;
  566. bool TreeOnLeft = WinConfiguration->ScpCommander.TreeOnLeft;
  567. // save value only is it was set yet
  568. if (FPanelsRestored)
  569. {
  570. if (TreeOnLeft)
  571. {
  572. // want to be on left, so it is on top, saving height
  573. LocalPanel.DriveViewHeight = LocalDriveView->Height;
  574. RemotePanel.DriveViewHeight = RemoteDriveView->Height;
  575. }
  576. else
  577. {
  578. LocalPanel.DriveViewWidth = LocalDriveView->Width;
  579. RemotePanel.DriveViewWidth = RemoteDriveView->Width;
  580. }
  581. }
  582. TAlign NonClientAlign = (TreeOnLeft ? alLeft : alTop);
  583. // VCL adjusts cursors only between crVSplit and crHSplit,
  584. // See TSplitter.RequestAlign
  585. TCursor SplitterCursor = (TreeOnLeft ? crSizeWE : crSizeNS);
  586. LocalDriveView->Align = NonClientAlign;
  587. LocalPanelSplitter->Align = NonClientAlign;
  588. LocalPanelSplitter->Cursor = SplitterCursor;
  589. RemoteDriveView->Align = NonClientAlign;
  590. RemotePanelSplitter->Align = NonClientAlign;
  591. RemotePanelSplitter->Cursor = SplitterCursor;
  592. FixControlsPlacement();
  593. if (TreeOnLeft)
  594. {
  595. LocalDriveView->Width = LocalPanel.DriveViewWidth;
  596. RemoteDriveView->Width = RemotePanel.DriveViewWidth;
  597. }
  598. else
  599. {
  600. LocalDriveView->Height = LocalPanel.DriveViewHeight;
  601. RemoteDriveView->Height = RemotePanel.DriveViewHeight;
  602. }
  603. // in case it trigges config-changed event (does not),
  604. // make sure it does only after we apply the TreeOnLeft change to avoid endless recursion
  605. WinConfiguration->ScpCommander.LocalPanel = LocalPanel;
  606. WinConfiguration->ScpCommander.RemotePanel = RemotePanel;
  607. }
  608. if (FExplorerKeyboardShortcuts != WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  609. {
  610. SetShortcuts();
  611. }
  612. }
  613. //---------------------------------------------------------------------------
  614. void __fastcall TScpCommanderForm::SetShortcuts()
  615. {
  616. // set common norton shorcuts to our actions
  617. NonVisualDataModule->CommanderShortcuts();
  618. FExplorerKeyboardShortcuts = WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts;
  619. }
  620. //---------------------------------------------------------------------------
  621. TPanel * __fastcall TScpCommanderForm::Panel(bool Left)
  622. {
  623. bool SwappedPanels = WinConfiguration->ScpCommander.SwappedPanels;
  624. if (IsRightToLeft())
  625. {
  626. SwappedPanels = !SwappedPanels;
  627. }
  628. return (SwappedPanels == Left ? RemotePanel : LocalPanel);
  629. }
  630. //---------------------------------------------------------------------------
  631. TPanel * __fastcall TScpCommanderForm::CurrentPanel()
  632. {
  633. return (FCurrentSide == osLocal ? LocalPanel : RemotePanel);
  634. }
  635. //---------------------------------------------------------------------------
  636. void __fastcall TScpCommanderForm::SetLeftPanelWidth(double value)
  637. {
  638. double Total = LocalPanel->Width + RemotePanel->Width;
  639. FLeftPanelWidth = value;
  640. if (value * Total != Panel(true)->Width)
  641. {
  642. Panel(true)->Width = static_cast<int>(value * Total);
  643. UpdateControls();
  644. }
  645. }
  646. //---------------------------------------------------------------------------
  647. double __fastcall TScpCommanderForm::GetLeftPanelWidth()
  648. {
  649. return FLeftPanelWidth;
  650. }
  651. //---------------------------------------------------------------------------
  652. void __fastcall TScpCommanderForm::SplitterMoved(TObject * /*Sender*/)
  653. {
  654. double Left = Panel(true)->Width;
  655. double Total = LocalPanel->Width + RemotePanel->Width;
  656. FLeftPanelWidth = Left / Total;
  657. FLastLeftPanelWidth = LeftPanelWidth;
  658. UpdateControls();
  659. }
  660. //---------------------------------------------------------------------------
  661. void __fastcall TScpCommanderForm::SplitterCanResize(TObject * /*Sender*/,
  662. int &NewSize, bool & /*Accept*/)
  663. {
  664. // When splitter is drag so far to right, that width contraint of remote panel would
  665. // be violated, it doesn't stop, but extend form width.
  666. // Following prevents this behavior.
  667. if (ClientWidth - NewSize - Splitter->Width < Panel(false)->Constraints->MinWidth)
  668. NewSize = (ClientWidth - Panel(false)->Constraints->MinWidth - Splitter->Width);
  669. }
  670. //---------------------------------------------------------------------------
  671. void __fastcall TScpCommanderForm::SplitterDblClick(TObject * /*Sender*/)
  672. {
  673. LeftPanelWidth = 0.5;
  674. }
  675. //---------------------------------------------------------------------------
  676. void __fastcall TScpCommanderForm::PanelSplitterDblClick(TObject * Sender)
  677. {
  678. TSplitter * Splitter = dynamic_cast<TSplitter *>(Sender);
  679. DebugAssert(Splitter != NULL);
  680. TCustomDriveView * DriveView;
  681. TCustomDriveView * OtherDriveView;
  682. if (Splitter == LocalPanelSplitter)
  683. {
  684. DriveView = LocalDriveView;
  685. OtherDriveView = RemoteDriveView;
  686. }
  687. else
  688. {
  689. DriveView = RemoteDriveView;
  690. OtherDriveView = LocalDriveView;
  691. }
  692. bool TreeOnLeft = WinConfiguration->ScpCommander.TreeOnLeft;
  693. DebugAssert(DriveView->Visible);
  694. if (OtherDriveView->Visible)
  695. {
  696. if (TreeOnLeft)
  697. {
  698. DriveView->Width = OtherDriveView->Width;
  699. }
  700. else
  701. {
  702. DriveView->Height = OtherDriveView->Height;
  703. }
  704. }
  705. else
  706. {
  707. if (TreeOnLeft)
  708. {
  709. OtherDriveView->Width = DriveView->Width;
  710. }
  711. else
  712. {
  713. OtherDriveView->Height = DriveView->Height;
  714. }
  715. OtherDriveView->Visible = true;
  716. }
  717. FixControlsPlacement();
  718. }
  719. //---------------------------------------------------------------------------
  720. void __fastcall TScpCommanderForm::UpdateControls()
  721. {
  722. TCustomScpExplorerForm::UpdateControls();
  723. UnicodeString SplitterLongHint = Splitter->Hint;
  724. int P = SplitterLongHint.Pos(L"|");
  725. if (P == 0)
  726. {
  727. P = SplitterLongHint.Pos(L"\n");
  728. }
  729. SplitterLongHint.Delete(1, P);
  730. Splitter->Hint = FORMAT(L"%0.0f%%\n%s", (LeftPanelWidth*100, SplitterLongHint));
  731. UnicodeString ACommandLinePromptLabel = LoadStr(COMMAND_LINE_LABEL) + " " +
  732. ((FCurrentSide == osRemote) ? L"$" : L">");
  733. if (CommandLinePromptLabel->Caption != ACommandLinePromptLabel)
  734. {
  735. CommandLinePromptLabel->Caption = ACommandLinePromptLabel;
  736. // command line combo width needs to be updated as caption width has probably changed
  737. ToolBarResize(CommandLineToolbar);
  738. }
  739. LocalDirView->Color = (SessionColor != 0 ? SessionColor : clWindow);
  740. LocalDriveView->Color = LocalDirView->Color;
  741. bool LocalSide = (FCurrentSide == osLocal);
  742. TAction * CurrentCopyAction = LocalSide ? NonVisualDataModule->LocalCopyAction : NonVisualDataModule->RemoteCopyAction;
  743. if (CurrentCopyItem->Action != CurrentCopyAction)
  744. {
  745. CurrentCopyItem->Action = CurrentCopyAction;
  746. CurrentCopyToolbar2Item->Action = CurrentCopyAction;
  747. UpdateToolbar2ItemCaption(CurrentCopyToolbar2Item);
  748. CurrentCopyNonQueueItem->Action = LocalSide ? NonVisualDataModule->LocalCopyNonQueueAction : NonVisualDataModule->RemoteCopyNonQueueAction;
  749. CurrentCopyQueueItem->Action = LocalSide ? NonVisualDataModule->LocalCopyQueueAction : NonVisualDataModule->RemoteCopyQueueAction;
  750. TAction * CurrentMoveAction = LocalSide ? NonVisualDataModule->LocalMoveAction : NonVisualDataModule->RemoteMoveAction;
  751. CurrentMoveItem->Action = CurrentMoveAction;
  752. CurrentMoveToolbar2Item->Action = CurrentMoveAction;
  753. UpdateToolbar2ItemCaption(CurrentMoveToolbar2Item);
  754. }
  755. CommandLineCombo->Enabled = (FCurrentSide == osLocal) || CanConsole();
  756. CommandLinePromptLabel->Enabled = CommandLineCombo->Enabled;
  757. }
  758. //---------------------------------------------------------------------------
  759. void __fastcall TScpCommanderForm::ChangePath(TOperationSide Side)
  760. {
  761. DebugAssert((Side == osLocal) || (Side == osRemote));
  762. TTBXComboBoxItem * PathComboBox;
  763. if (Side == osLocal)
  764. {
  765. PathComboBox = LocalPathComboBox;
  766. }
  767. else
  768. {
  769. PathComboBox = RemotePathComboBox;
  770. }
  771. ClickToolbarItem(PathComboBox, false);
  772. }
  773. //---------------------------------------------------------------------------
  774. TControl * __fastcall TScpCommanderForm::GetComponent(Byte Component)
  775. {
  776. switch (Component) {
  777. case fcToolBar2: return Toolbar2Toolbar; // name changed to enforce change of default visibility
  778. case fcStatusBar: return StatusBar;
  779. case fcLocalStatusBar: return LocalStatusBar;
  780. case fcRemoteStatusBar: return RemoteStatusBar;
  781. case fcCommandLinePanel: return CommandLineToolbar;
  782. case fcLocalTree: return LocalDriveView;
  783. case fcSessionToolbar: return SessionToolbar;
  784. case fcCustomCommandsBand: return CustomCommandsToolbar;
  785. case fcColorMenu: return reinterpret_cast<TControl*>(ColorMenuItem);
  786. case fcTransferDropDown: return reinterpret_cast<TControl*>(TransferDropDown);
  787. case fcTransferList: return reinterpret_cast<TControl*>(TransferList);
  788. case fcTransferLabel: return reinterpret_cast<TControl*>(TransferLabel);
  789. case fcLocalPopup: return reinterpret_cast<TControl *>(NonVisualDataModule->LocalFilePopup);
  790. case fcRemotePathComboBox: return reinterpret_cast<TControl*>(RemotePathComboBox);
  791. case fcCommanderMenuBand: return MenuToolbar;
  792. case fcCommanderSessionBand: return SessionToolbar;
  793. case fcCommanderPreferencesBand: return PreferencesToolbar;
  794. case fcCommanderSortBand: return SortToolbar;
  795. case fcCommanderCommandsBand: return CommandsToolbar;
  796. case fcCommanderUpdatesBand: return UpdatesToolbar;
  797. case fcCommanderTransferBand: return TransferToolbar;
  798. case fcCommanderCustomCommandsBand: return CustomCommandsToolbar;
  799. case fcCommanderLocalHistoryBand: return LocalHistoryToolbar;
  800. case fcCommanderLocalNavigationBand: return LocalNavigationToolbar;
  801. case fcCommanderLocalFileBand: return LocalFileToolbar;
  802. case fcCommanderLocalSelectionBand: return LocalSelectionToolbar;
  803. case fcCommanderRemoteHistoryBand: return RemoteHistoryToolbar;
  804. case fcCommanderRemoteNavigationBand: return RemoteNavigationToolbar;
  805. case fcCommanderRemoteFileBand: return RemoteFileToolbar;
  806. case fcCommanderRemoteSelectionBand: return RemoteSelectionToolbar;
  807. default: return TCustomScpExplorerForm::GetComponent(Component);
  808. }
  809. }
  810. //---------------------------------------------------------------------------
  811. void __fastcall TScpCommanderForm::FixControlsPlacement()
  812. {
  813. TCustomScpExplorerForm::FixControlsPlacement();
  814. QueueSeparatorPanel->Visible = QueuePanel->Visible;
  815. LocalPanelSplitter->Visible = LocalDriveView->Visible;
  816. TControl * ControlsOrder[] =
  817. { BottomDock, QueueSeparatorPanel, QueueSplitter, QueuePanel, StatusBar };
  818. SetVerticalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  819. TControl * LocalControlsOrder[] =
  820. { LocalTopDock, LocalPathLabel, LocalDriveView, LocalPanelSplitter,
  821. LocalDirView, LocalBottomDock, LocalStatusBar };
  822. SetVerticalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  823. SetHorizontalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  824. TControl * RemoteControlsOrder[] =
  825. { RemoteTopDock, RemotePathLabel, RemoteDriveView, RemotePanelSplitter,
  826. RemoteDirView, RemoteBottomDock, RemoteStatusBar };
  827. SetVerticalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  828. SetHorizontalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  829. if (LocalDirView->ItemFocused != NULL)
  830. {
  831. LocalDirView->ItemFocused->MakeVisible(false);
  832. }
  833. }
  834. //---------------------------------------------------------------------------
  835. bool __fastcall TScpCommanderForm::GetHasDirView(TOperationSide Side)
  836. {
  837. return TCustomScpExplorerForm::GetHasDirView(Side) || (Side == osLocal);
  838. }
  839. //---------------------------------------------------------------------------
  840. void __fastcall TScpCommanderForm::CompareDirectories()
  841. {
  842. LocalDirView->CompareFiles(RemoteDirView, false,
  843. WinConfiguration->ScpCommander.CompareCriterias());
  844. RemoteDirView->CompareFiles(LocalDirView, false,
  845. WinConfiguration->ScpCommander.CompareCriterias());
  846. if (LocalDirView->SelCount + RemoteDirView->SelCount == 0)
  847. {
  848. MessageDialog(LoadStr(COMPARE_NO_DIFFERENCES), qtInformation, qaOK,
  849. HELP_COMPARE_NO_DIFFERENCES);
  850. }
  851. }
  852. //---------------------------------------------------------------------------
  853. void __fastcall TScpCommanderForm::SynchronizeDirectories()
  854. {
  855. UnicodeString LocalDirectory = LocalDirView->PathName;
  856. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  857. DoSynchronizeDirectories(LocalDirectory, RemoteDirectory, false);
  858. }
  859. //---------------------------------------------------------------------------
  860. void __fastcall TScpCommanderForm::FullSynchronizeDirectories()
  861. {
  862. UnicodeString LocalDirectory = LocalDirView->PathName;
  863. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  864. bool SaveMode = !(GUIConfiguration->SynchronizeModeAuto < 0);
  865. TSynchronizeMode Mode =
  866. (SaveMode ? (TSynchronizeMode)GUIConfiguration->SynchronizeModeAuto :
  867. ((FCurrentSide == osLocal) ? smRemote : smLocal));
  868. int Params = GUIConfiguration->SynchronizeParams;
  869. if (DoFullSynchronizeDirectories(LocalDirectory, RemoteDirectory, Mode, Params, SaveMode, false) >= 0)
  870. {
  871. if (SaveMode)
  872. {
  873. GUIConfiguration->SynchronizeModeAuto = Mode;
  874. }
  875. }
  876. }
  877. //---------------------------------------------------------------------------
  878. void __fastcall TScpCommanderForm::ExploreLocalDirectory()
  879. {
  880. OpenFolderInExplorer(LocalDirView->Path);
  881. }
  882. //---------------------------------------------------------------------------
  883. void __fastcall TScpCommanderForm::LocalDirViewExecFile(TObject *Sender,
  884. TListItem *Item, bool &AllowExec)
  885. {
  886. DebugAssert(Item);
  887. if ((UpperCase(PFileRec(Item->Data)->FileExt) == L"LNK") &&
  888. DirectoryExists(ApiPath(ResolveFileShortCut(LocalDirView->ItemFullFileName(Item), true))))
  889. {
  890. AllowExec = true;
  891. }
  892. else
  893. {
  894. DoDirViewExecFile(Sender, Item, AllowExec);
  895. }
  896. }
  897. //---------------------------------------------------------------------------
  898. void __fastcall TScpCommanderForm::LocalFileControlDDDragEnter(TObject *Sender,
  899. IDataObject *DataObj, int grfKeyState, TPoint &Point, int &dwEffect,
  900. bool &Accept)
  901. {
  902. // LocalDirViewDDDragEnter is duplication of
  903. // TCustomScpExplorerForm::DirViewDDDragEnter, but it differs in
  904. // literal type of 'DataObj' parameter.Actual type is however same
  905. FileControlDDDragEnter(Sender, DataObj, grfKeyState, Point, dwEffect, Accept);
  906. }
  907. //---------------------------------------------------------------------------
  908. bool __fastcall TScpCommanderForm::PanelOperation(TOperationSide Side,
  909. bool DragDrop)
  910. {
  911. return TCustomScpExplorerForm::PanelOperation(Side, DragDrop) ||
  912. (DropSourceControl == LocalDirView);
  913. }
  914. //---------------------------------------------------------------------------
  915. void __fastcall TScpCommanderForm::FileOperationProgress(
  916. TFileOperationProgressType & ProgressData)
  917. {
  918. // Heuristic: When operation finishes and DD targed is local dir view,
  919. // we suppose that drag&drop download finished, so local dir view should be
  920. // reloaded
  921. if (!ProgressData.InProgress && FProgressForm &&
  922. IsFileControl(FDDTargetControl, osLocal) &&
  923. ((ProgressData.Operation == ::foCopy) || (ProgressData.Operation == ::foMove)))
  924. {
  925. ReloadLocalDirectory();
  926. }
  927. TCustomScpExplorerForm::FileOperationProgress(ProgressData);
  928. }
  929. //---------------------------------------------------------------------------
  930. UnicodeString __fastcall TScpCommanderForm::ChangeFilePath(UnicodeString Path, TOperationSide Side)
  931. {
  932. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  933. UnicodeString Result;
  934. while (!Path.IsEmpty())
  935. {
  936. int P = Path.Pos(Side == osLocal ? L'\\' : L'/');
  937. if (P > 0)
  938. {
  939. Result += Terminal->ChangeFileName(&CopyParams, Path.SubString(1, P - 1), Side, false) +
  940. (Side == osLocal ? L'/' : L'\\');
  941. Path.Delete(1, P);
  942. }
  943. else
  944. {
  945. Result += Terminal->ChangeFileName(&CopyParams, Path, osLocal, false);
  946. Path = L"";
  947. }
  948. }
  949. return Result;
  950. }
  951. //---------------------------------------------------------------------------
  952. void __fastcall TScpCommanderForm::CreateRemoteDirectory(const UnicodeString & Path)
  953. {
  954. UnicodeString Dir = UnixExtractFileDir(Path);
  955. if (!IsUnixRootPath(Dir) && !Terminal->FileExists(Dir))
  956. {
  957. CreateRemoteDirectory(Dir);
  958. }
  959. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  960. TCustomScpExplorerForm::CreateRemoteDirectory(Path, Properties);
  961. }
  962. //---------------------------------------------------------------------------
  963. void __fastcall TScpCommanderForm::SynchronizeBrowsingLocal(
  964. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  965. {
  966. Terminal->ExceptionOnFail = true;
  967. TStrings * Paths = new TStringList();
  968. try
  969. {
  970. Paths->Add(IncludeTrailingBackslash(PrevPath));
  971. Paths->Add(IncludeTrailingBackslash(LocalDirView->Path));
  972. UnicodeString CommonPath;
  973. if (ExtractCommonPath(Paths, CommonPath))
  974. {
  975. PrevPath = IncludeTrailingBackslash(PrevPath);
  976. CommonPath = IncludeTrailingBackslash(CommonPath);
  977. NewPath = RemoteDirView->Path;
  978. while (!SamePaths(PrevPath, CommonPath))
  979. {
  980. if (NewPath == UnixExcludeTrailingBackslash(NewPath))
  981. {
  982. Abort();
  983. }
  984. NewPath = UnixExtractFilePath(UnixExcludeTrailingBackslash(NewPath));
  985. PrevPath = ExtractFilePath(ExcludeTrailingBackslash(PrevPath));
  986. }
  987. NewPath = UnixIncludeTrailingBackslash(NewPath) +
  988. ToUnixPath(LocalDirView->Path.SubString(PrevPath.Length() + 1,
  989. LocalDirView->Path.Length() - PrevPath.Length()));
  990. }
  991. else
  992. {
  993. Abort();
  994. }
  995. if (Create)
  996. {
  997. CreateRemoteDirectory(UnixExcludeTrailingBackslash(NewPath));
  998. }
  999. RemoteDirView->Path = NewPath;
  1000. }
  1001. __finally
  1002. {
  1003. Terminal->ExceptionOnFail = false;
  1004. delete Paths;
  1005. }
  1006. }
  1007. //---------------------------------------------------------------------------
  1008. void __fastcall TScpCommanderForm::CreateLocalDirectory(const UnicodeString & Path)
  1009. {
  1010. UnicodeString Dir = ExtractFileDir(Path);
  1011. if (!Dir.IsEmpty() && !DirectoryExists(Dir))
  1012. {
  1013. CreateLocalDirectory(Dir);
  1014. }
  1015. LocalDirView->CreateDirectory(Path);
  1016. }
  1017. //---------------------------------------------------------------------------
  1018. void __fastcall TScpCommanderForm::SynchronizeBrowsingRemote(
  1019. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  1020. {
  1021. TStrings * Paths = new TStringList();
  1022. try
  1023. {
  1024. Paths->Add(UnixIncludeTrailingBackslash(PrevPath));
  1025. Paths->Add(UnixIncludeTrailingBackslash(RemoteDirView->Path));
  1026. UnicodeString CommonPath;
  1027. if (UnixExtractCommonPath(Paths, CommonPath))
  1028. {
  1029. PrevPath = UnixIncludeTrailingBackslash(PrevPath);
  1030. CommonPath = UnixIncludeTrailingBackslash(CommonPath);
  1031. UnicodeString NewLocalPath;
  1032. NewPath = ExcludeTrailingBackslash(LocalDirView->Path);
  1033. while (!UnixSamePath(PrevPath, CommonPath))
  1034. {
  1035. NewLocalPath = ExcludeTrailingBackslash(ExtractFileDir(NewPath));
  1036. if (NewLocalPath == NewPath)
  1037. {
  1038. Abort();
  1039. }
  1040. NewPath = NewLocalPath;
  1041. PrevPath = UnixExtractFilePath(UnixExcludeTrailingBackslash(PrevPath));
  1042. }
  1043. NewPath = IncludeTrailingBackslash(NewPath) +
  1044. ChangeFilePath(
  1045. RemoteDirView->Path.SubString(PrevPath.Length() + 1,
  1046. RemoteDirView->Path.Length() - PrevPath.Length()),
  1047. osRemote);
  1048. }
  1049. else
  1050. {
  1051. Abort();
  1052. }
  1053. }
  1054. __finally
  1055. {
  1056. delete Paths;
  1057. }
  1058. if (Create)
  1059. {
  1060. CreateLocalDirectory(ExcludeTrailingBackslash(NewPath));
  1061. }
  1062. LocalDirView->Path = NewPath;
  1063. }
  1064. //---------------------------------------------------------------------------
  1065. void __fastcall TScpCommanderForm::SynchronizeBrowsing(TCustomDirView * ADirView,
  1066. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  1067. {
  1068. if (ADirView == LocalDirView)
  1069. {
  1070. SynchronizeBrowsingLocal(PrevPath, NewPath, Create);
  1071. }
  1072. else
  1073. {
  1074. SynchronizeBrowsingRemote(PrevPath, NewPath, Create);
  1075. }
  1076. }
  1077. //---------------------------------------------------------------------------
  1078. void __fastcall TScpCommanderForm::SynchronizeBrowsing(TCustomDirView * ADirView)
  1079. {
  1080. UnicodeString PrevPath;
  1081. // cannot assign to UnicodeString before the class is constructed,
  1082. // if we do, the value get lost when UnicodeString constructor gets finally called,
  1083. // what results in memory leak in the best case
  1084. if (FConstructed)
  1085. {
  1086. PrevPath = FPrevPath[ADirView == LocalDirView];
  1087. FPrevPath[ADirView == LocalDirView] = ADirView->Path;
  1088. }
  1089. if (!FSynchronisingBrowse && NonVisualDataModule->SynchronizeBrowsingAction->Checked &&
  1090. !PrevPath.IsEmpty() && PrevPath != ADirView->Path)
  1091. {
  1092. TValueRestorer<bool> AllowTransferPresetAutoSelectRestorer(FAllowTransferPresetAutoSelect);
  1093. FAllowTransferPresetAutoSelect = false;
  1094. TValueRestorer<bool> SynchronisingBrowseRestorer(FSynchronisingBrowse);
  1095. FSynchronisingBrowse = true;
  1096. try
  1097. {
  1098. UnicodeString NewPath;
  1099. bool Error = false;
  1100. std::unique_ptr<TStrings> ErrorMoreMessages;
  1101. UnicodeString ErrorHelpKeyword;
  1102. try
  1103. {
  1104. SynchronizeBrowsing(ADirView, PrevPath, NewPath, false);
  1105. }
  1106. // EAbort means that we do not know how to synchronize browsing
  1107. // there's no fallback scenario for that
  1108. catch(EAbort &)
  1109. {
  1110. throw;
  1111. }
  1112. catch(Exception & E)
  1113. {
  1114. // what does this say?
  1115. if (Application->Terminated)
  1116. {
  1117. throw;
  1118. }
  1119. else
  1120. {
  1121. Error = true;
  1122. ErrorMoreMessages.reset(ExceptionToMoreMessages(&E));
  1123. ErrorHelpKeyword =
  1124. MergeHelpKeyword(HELP_SYNC_DIR_BROWSE_ERROR, GetExceptionHelpKeyword(&E));
  1125. }
  1126. }
  1127. // this was moved here out of the above catch clause,
  1128. // to avoid deep nesting, what seems to cause some stray access violations
  1129. if (Error)
  1130. {
  1131. if (MoreMessageDialog(FMTLOAD(SYNC_DIR_BROWSE_CREATE2, (NewPath)),
  1132. ErrorMoreMessages.get(), qtConfirmation, qaYes | qaNo,
  1133. ErrorHelpKeyword) == qaYes)
  1134. {
  1135. try
  1136. {
  1137. SynchronizeBrowsing(ADirView, PrevPath, NewPath, true);
  1138. }
  1139. catch(Exception & E)
  1140. {
  1141. if (!Application->Terminated)
  1142. {
  1143. Terminal->ShowExtendedException(&E);
  1144. }
  1145. throw;
  1146. }
  1147. }
  1148. else
  1149. {
  1150. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  1151. }
  1152. }
  1153. }
  1154. catch(Exception & E)
  1155. {
  1156. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  1157. // what does this say?
  1158. if (Application->Terminated)
  1159. {
  1160. throw;
  1161. }
  1162. else
  1163. {
  1164. MessageDialog(LoadStr(SYNC_DIR_BROWSE_ERROR), qtInformation, qaOK,
  1165. HELP_SYNC_DIR_BROWSE_ERROR);
  1166. }
  1167. }
  1168. // note the value restorers at the beginning of this block
  1169. }
  1170. }
  1171. //---------------------------------------------------------------------------
  1172. void __fastcall TScpCommanderForm::DoDirViewLoaded(TCustomDirView * ADirView)
  1173. {
  1174. TCustomScpExplorerForm::DoDirViewLoaded(ADirView);
  1175. UpdateControls();
  1176. SynchronizeBrowsing(ADirView);
  1177. }
  1178. //---------------------------------------------------------------------------
  1179. void __fastcall TScpCommanderForm::AddEditLink(TOperationSide Side, bool Add)
  1180. {
  1181. if (GetSide(Side) == osLocal)
  1182. {
  1183. bool Edit = false;
  1184. UnicodeString FileName;
  1185. UnicodeString PointTo;
  1186. bool SymbolicLink = true;
  1187. if (LocalDirView->ItemFocused)
  1188. {
  1189. DebugAssert(LocalDirView->ItemFocused->Data);
  1190. PFileRec FileRec = (PFileRec)LocalDirView->ItemFocused->Data;
  1191. Edit = !Add && (UpperCase(FileRec->FileExt) == L"LNK");
  1192. if (Edit)
  1193. {
  1194. UnicodeString FullName = LocalDirView->ItemFullFileName(LocalDirView->ItemFocused);
  1195. FileName = FullName;
  1196. PointTo = ResolveFileShortCut(FullName, false);
  1197. if (PointTo.IsEmpty())
  1198. {
  1199. throw Exception(FMTLOAD(RESOLVE_SHORTCUT_ERROR, (FullName)));
  1200. }
  1201. }
  1202. else
  1203. {
  1204. PointTo = FileRec->FileName;
  1205. }
  1206. }
  1207. if (DoSymlinkDialog(FileName, PointTo, osLocal, SymbolicLink, Edit, false))
  1208. {
  1209. Configuration->Usage->Inc(L"LocalShortcutsCreated");
  1210. DebugAssert(SymbolicLink);
  1211. DebugAssert(!FileName.IsEmpty());
  1212. DebugAssert(!PointTo.IsEmpty());
  1213. if (ExtractFileDrive(FileName) == L"" && FileName[1] != L'\\')
  1214. {
  1215. FileName = IncludeTrailingBackslash(LocalDirView->PathName) + FileName;
  1216. }
  1217. if (ExtractFileDrive(PointTo) == L"" && PointTo[1] != L'\\')
  1218. {
  1219. PointTo = IncludeTrailingBackslash(LocalDirView->PathName) + PointTo;
  1220. }
  1221. if (ExtractFileExt(FileName) == L"")
  1222. {
  1223. FileName = FileName + L".lnk";
  1224. }
  1225. if (Edit)
  1226. {
  1227. DeleteFileChecked(FileName);
  1228. }
  1229. if (!CreateFileShortCut(PointTo, FileName, L""))
  1230. {
  1231. throw Exception(CREATE_SHORTCUT_ERROR);
  1232. }
  1233. }
  1234. }
  1235. else
  1236. {
  1237. TCustomScpExplorerForm::AddEditLink(Side, Add);
  1238. }
  1239. }
  1240. //---------------------------------------------------------------------------
  1241. void __fastcall TScpCommanderForm::DoOpenDirectoryDialog(TOpenDirectoryMode Mode,
  1242. TOperationSide Side)
  1243. {
  1244. bool UseLocationProfiles;
  1245. do
  1246. {
  1247. UseLocationProfiles = WinConfiguration->UseLocationProfiles;
  1248. // Location profiles dialog is not ready to be run without terminal
  1249. if (UseLocationProfiles && (Terminal != NULL))
  1250. {
  1251. TStrings * LocalDirectories = NULL;
  1252. TStrings * RemoteDirectories = NULL;
  1253. try
  1254. {
  1255. LocalDirectories = CreateVisitedDirectories(osLocal);
  1256. RemoteDirectories = CreateVisitedDirectories(osRemote);
  1257. UnicodeString Local = LocalDirView->PathName;
  1258. UnicodeString Remote = RemoteDirView->PathName;
  1259. if (LocationProfilesDialog(Mode, Side, Local, Remote, LocalDirectories,
  1260. RemoteDirectories, Terminal))
  1261. {
  1262. DoOpenBookmark(Local, Remote);
  1263. }
  1264. }
  1265. __finally
  1266. {
  1267. delete LocalDirectories;
  1268. delete RemoteDirectories;
  1269. }
  1270. }
  1271. else
  1272. {
  1273. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1274. TCustomScpExplorerForm::DoOpenDirectoryDialog(Mode, Side);
  1275. }
  1276. // for second and further rounds, always do browse only
  1277. Mode = odBrowse;
  1278. }
  1279. while (UseLocationProfiles != WinConfiguration->UseLocationProfiles);
  1280. }
  1281. //---------------------------------------------------------------------------
  1282. void __fastcall TScpCommanderForm::DoOpenBookmark(UnicodeString Local, UnicodeString Remote)
  1283. {
  1284. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1285. // make sure that whatever path is valid it is opened first and only
  1286. // after that an eventual error is reported
  1287. try
  1288. {
  1289. if (!Local.IsEmpty())
  1290. {
  1291. LocalDirView->Path = Local;
  1292. }
  1293. }
  1294. __finally
  1295. {
  1296. if (!Remote.IsEmpty())
  1297. {
  1298. // While we might get here when the session is closed (from location profiles),
  1299. // it's not a problem as the Path setter is noop then
  1300. RemoteDirView->Path = Remote;
  1301. }
  1302. }
  1303. }
  1304. //---------------------------------------------------------------------------
  1305. bool __fastcall TScpCommanderForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  1306. {
  1307. bool Result;
  1308. if (WinConfiguration->UseLocationProfiles)
  1309. {
  1310. DoOpenBookmark(Bookmark->Local, Bookmark->Remote);
  1311. Result = true;
  1312. }
  1313. else
  1314. {
  1315. Result = TCustomScpExplorerForm::OpenBookmark(Side, Bookmark);
  1316. }
  1317. return Result;
  1318. }
  1319. //---------------------------------------------------------------------------
  1320. void __fastcall TScpCommanderForm::LocalDirViewDDTargetHasDropHandler(
  1321. TObject * /*Sender*/, TListItem * Item, int & /*Effect*/, bool & DropHandler)
  1322. {
  1323. // When drop target is not directory, it is probably file type, which have
  1324. // associated drop handler (such as EXE file). In this case we
  1325. // cannot allow drop when when using shellex,
  1326. // as drop handlers are disabled, so drop would error
  1327. // (see TShellExtension.DropHandler assignment in ConfigurationChanged),
  1328. if (WinConfiguration->DDFakeFile &&
  1329. !LocalDirView->ItemIsDirectory(Item))
  1330. {
  1331. DropHandler = false;
  1332. }
  1333. }
  1334. //---------------------------------------------------------------------------
  1335. bool __fastcall TScpCommanderForm::DDGetTarget(
  1336. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  1337. {
  1338. bool Result;
  1339. if (!FDDFakeFileTarget.IsEmpty())
  1340. {
  1341. Directory = FDDFakeFileTarget;
  1342. FDDFakeFileTarget = L"";
  1343. Result = true;
  1344. CounterName = L"DownloadsDragDropInternal";
  1345. ForceQueue = false;
  1346. }
  1347. else
  1348. {
  1349. Result = TCustomScpExplorerForm::DDGetTarget(Directory, ForceQueue, CounterName);
  1350. }
  1351. return Result;
  1352. }
  1353. //---------------------------------------------------------------------------
  1354. void __fastcall TScpCommanderForm::DDFakeFileInitDrag(TFileList * FileList,
  1355. bool & Created)
  1356. {
  1357. FDDFakeFileTarget = L"";
  1358. TCustomScpExplorerForm::DDFakeFileInitDrag(FileList, Created);
  1359. }
  1360. //---------------------------------------------------------------------------
  1361. void __fastcall TScpCommanderForm::LocalFileControlDDFileOperation(
  1362. TObject * /*Sender*/, int dwEffect, UnicodeString SourcePath,
  1363. UnicodeString TargetPath, bool Paste, bool & DoOperation)
  1364. {
  1365. if (IsFileControl(DropSourceControl, osRemote))
  1366. {
  1367. UnicodeString TargetDirectory;
  1368. if (InternalDDDownload(TargetDirectory))
  1369. {
  1370. // See TCustomScpExplorerForm::QueueDDProcessDropped
  1371. if (FDDExtMapFile != NULL)
  1372. {
  1373. FDDFakeFileTarget = TargetDirectory;
  1374. }
  1375. else
  1376. {
  1377. DebugAssert(FInternalDDDownloadList->Count > 0);
  1378. DebugAssert(dwEffect == DROPEFFECT_Copy || dwEffect == DROPEFFECT_Move);
  1379. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  1380. TTransferType TransferType = dwEffect == DROPEFFECT_Copy ? ttCopy : ttMove;
  1381. int Options =
  1382. FLAGMASK(DraggingAllFilesFromDirView(osRemote, FInternalDDDownloadList), coAllFiles);
  1383. bool NoConfirmation = Paste ? false : (WinConfiguration->DDTransferConfirmation == asOff);
  1384. if (CopyParamDialog(tdToLocal, TransferType,
  1385. false, FInternalDDDownloadList, TargetDirectory, CopyParams, NoConfirmation, true, Options))
  1386. {
  1387. int Params =
  1388. (TransferType == ttMove ? cpDelete : 0);
  1389. DDDownload(FInternalDDDownloadList, TargetDirectory,
  1390. &CopyParams, Params);
  1391. Configuration->Usage->Inc(L"DownloadsDragDropInternal");
  1392. FInternalDDDownloadList->Clear();
  1393. }
  1394. }
  1395. DoOperation = false;
  1396. }
  1397. }
  1398. }
  1399. //---------------------------------------------------------------------------
  1400. void __fastcall TScpCommanderForm::RemoteFileControlDDFileOperationExecuted(
  1401. TObject * /*Sender*/, int dwEffect, UnicodeString /*SourcePath*/,
  1402. UnicodeString /*TargetPath*/)
  1403. {
  1404. if ((dwEffect == DROPEFFECT_Move) &&
  1405. IsFileControl(DropSourceControl, osLocal))
  1406. {
  1407. ReloadLocalDirectory();
  1408. }
  1409. }
  1410. //---------------------------------------------------------------------------
  1411. void __fastcall TScpCommanderForm::LocalDirViewEnter(TObject * /*Sender*/)
  1412. {
  1413. SideEnter(osLocal);
  1414. }
  1415. //---------------------------------------------------------------------------
  1416. void __fastcall TScpCommanderForm::LocalDriveViewEnter(TObject * /*Sender*/)
  1417. {
  1418. MakeNextInTabOrder(LocalDirView, LocalDriveView);
  1419. SideEnter(osLocal);
  1420. }
  1421. //---------------------------------------------------------------------------
  1422. void __fastcall TScpCommanderForm::SideEnter(TOperationSide Side)
  1423. {
  1424. if (Visible && (FCurrentSide != Side))
  1425. {
  1426. // this may get called yet before controls are initialized
  1427. CommandLineCombo->Strings->Clear();
  1428. FCommandLineComboPopulated = false;
  1429. }
  1430. TCustomScpExplorerForm::SideEnter(Side);
  1431. if (Visible)
  1432. {
  1433. UpdateControls();
  1434. UpdatePanelsPathLabelsStatus();
  1435. }
  1436. }
  1437. //---------------------------------------------------------------------------
  1438. void __fastcall TScpCommanderForm::UpdatePanelsPathLabelsStatus()
  1439. {
  1440. LocalPathLabel->UpdateStatus();
  1441. RemotePathLabel->UpdateStatus();
  1442. }
  1443. //---------------------------------------------------------------------------
  1444. void __fastcall TScpCommanderForm::OpenConsole(UnicodeString Command)
  1445. {
  1446. SaveCommandLine();
  1447. try
  1448. {
  1449. TCustomScpExplorerForm::OpenConsole(Command);
  1450. }
  1451. __finally
  1452. {
  1453. FCommandLineComboPopulated = false;
  1454. }
  1455. }
  1456. //---------------------------------------------------------------------------
  1457. void __fastcall TScpCommanderForm::SaveCommandLine()
  1458. {
  1459. if (FCommandLineComboPopulated)
  1460. {
  1461. CustomWinConfiguration->History[
  1462. FCurrentSide == osRemote ? L"Commands" : L"LocalCommands"] =
  1463. CommandLineCombo->Strings;
  1464. }
  1465. }
  1466. //---------------------------------------------------------------------------
  1467. bool __fastcall TScpCommanderForm::ExecuteCommandLine()
  1468. {
  1469. UnicodeString Command = CommandLineCombo->Text;
  1470. bool Result =
  1471. !NonVisualDataModule->Busy &&
  1472. !Command.IsEmpty() &&
  1473. ((FCurrentSide != osRemote) ||
  1474. (Terminal->AllowedAnyCommand(Command) &&
  1475. EnsureCommandSessionFallback(fcAnyCommand)));
  1476. if (Result)
  1477. {
  1478. CommandLinePopulate();
  1479. SaveToHistory(CommandLineCombo->Strings, Command);
  1480. CommandLineCombo->Text = L"";
  1481. if (FCurrentSide == osRemote)
  1482. {
  1483. OpenConsole(Command);
  1484. }
  1485. else
  1486. {
  1487. ExecuteShellChecked(Command);
  1488. }
  1489. }
  1490. return Result;
  1491. }
  1492. //---------------------------------------------------------------------------
  1493. void __fastcall TScpCommanderForm::CommandLinePopulate()
  1494. {
  1495. if (!FCommandLineComboPopulated)
  1496. {
  1497. TStrings * CommandsHistory;
  1498. CommandsHistory = CustomWinConfiguration->History[
  1499. FCurrentSide == osRemote ? L"Commands" : L"LocalCommands"];
  1500. if ((CommandsHistory != NULL) && (CommandsHistory->Count > 0))
  1501. {
  1502. CommandLineCombo->Strings = CommandsHistory;
  1503. }
  1504. else
  1505. {
  1506. CommandLineCombo->Strings->Clear();
  1507. }
  1508. FCommandLineComboPopulated = true;
  1509. }
  1510. }
  1511. //---------------------------------------------------------------------------
  1512. void __fastcall TScpCommanderForm::GoToCommandLine()
  1513. {
  1514. ComponentVisible[fcCommandLinePanel] = true;
  1515. if (CommandLineCombo->Enabled)
  1516. {
  1517. ClickToolbarItem(CommandLineCombo, true);
  1518. }
  1519. }
  1520. //---------------------------------------------------------------------------
  1521. void __fastcall TScpCommanderForm::GoToTree()
  1522. {
  1523. if (FCurrentSide == osLocal)
  1524. {
  1525. ComponentVisible[fcLocalTree] = true;
  1526. LocalDriveView->SetFocus();
  1527. }
  1528. else
  1529. {
  1530. TCustomScpExplorerForm::GoToTree();
  1531. }
  1532. }
  1533. //---------------------------------------------------------------------------
  1534. void __fastcall TScpCommanderForm::PanelExportStore(TOperationSide Side,
  1535. TPanelExport Export, TPanelExportDestination Destination,
  1536. TStrings * ExportData)
  1537. {
  1538. if (Destination == pedCommandLine)
  1539. {
  1540. ComponentVisible[fcCommandLinePanel] = true;
  1541. UnicodeString Buf;
  1542. for (int Index = 0; Index < ExportData->Count; Index++)
  1543. {
  1544. Buf += ExportData->Strings[Index] + L" ";
  1545. }
  1546. CommandLineCombo->Text = CommandLineCombo->Text + Buf;
  1547. }
  1548. else
  1549. {
  1550. TCustomScpExplorerForm::PanelExportStore(Side, Export, Destination, ExportData);
  1551. }
  1552. }
  1553. //---------------------------------------------------------------------------
  1554. int __fastcall TScpCommanderForm::GetStaticComponentsHeight()
  1555. {
  1556. return TCustomScpExplorerForm::GetStaticComponentsHeight() +
  1557. (BottomDock->Visible ? BottomDock->Height : 0) +
  1558. (QueueSeparatorPanel->Visible ? QueueSeparatorPanel->Height : 0) +
  1559. (StatusBar->Visible ? StatusBar->Height : 0);
  1560. }
  1561. //---------------------------------------------------------------------------
  1562. void __fastcall TScpCommanderForm::SysResizing(unsigned int Cmd)
  1563. {
  1564. TCustomScpExplorerForm::SysResizing(Cmd);
  1565. if ((Cmd == SC_MAXIMIZE) ||
  1566. ((Cmd == SC_DEFAULT) && (WindowState != wsMaximized)))
  1567. {
  1568. FNormalPanelsWidth = LocalPanel->Width + RemotePanel->Width;
  1569. }
  1570. else if ((Cmd == SC_RESTORE) ||
  1571. ((Cmd == SC_DEFAULT) && (WindowState == wsMaximized)))
  1572. {
  1573. if (FNormalPanelsWidth >= 0)
  1574. {
  1575. Panel(true)->Width = static_cast<int>(FLeftPanelWidth * FNormalPanelsWidth);
  1576. FNormalPanelsWidth = -1;
  1577. }
  1578. }
  1579. }
  1580. //---------------------------------------------------------------------------
  1581. void __fastcall TScpCommanderForm::Resize()
  1582. {
  1583. TCustomScpExplorerForm::Resize();
  1584. LeftPanelWidth = FLastLeftPanelWidth;
  1585. UpdateControls();
  1586. }
  1587. //---------------------------------------------------------------------------
  1588. void __fastcall TScpCommanderForm::PathLabelDblClick(TObject * Sender)
  1589. {
  1590. OpenDirectory(Sender == LocalPathLabel ? osLocal : osRemote);
  1591. }
  1592. //---------------------------------------------------------------------------
  1593. void __fastcall TScpCommanderForm::LocalPathLabelGetStatus(
  1594. TCustomPathLabel * /*Sender*/, bool & Active)
  1595. {
  1596. // WORKAROUND this strange form is here to make borland compiler work :-)
  1597. Active = Active || LocalDriveView->Focused();
  1598. }
  1599. //---------------------------------------------------------------------------
  1600. void __fastcall TScpCommanderForm::RemotePathLabelGetStatus(
  1601. TCustomPathLabel * /*Sender*/, bool & Active)
  1602. {
  1603. // WORKAROUND this strange form is here to make borland compiler work :-)
  1604. Active = Active || RemoteDriveView->Focused();
  1605. }
  1606. //---------------------------------------------------------------------------
  1607. void __fastcall TScpCommanderForm::LocalPathLabelPathClick(
  1608. TCustomPathLabel * /*Sender*/, UnicodeString Path)
  1609. {
  1610. if (SamePaths(Path, LocalDirView->Path))
  1611. {
  1612. OpenDirectory(osLocal);
  1613. }
  1614. else
  1615. {
  1616. LocalDirView->Path = Path;
  1617. }
  1618. }
  1619. //---------------------------------------------------------------------------
  1620. void __fastcall TScpCommanderForm::RemotePathLabelPathClick(
  1621. TCustomPathLabel * /*Sender*/, UnicodeString Path)
  1622. {
  1623. if (UnixSamePath(Path, RemoteDirView->Path))
  1624. {
  1625. OpenDirectory(osRemote);
  1626. }
  1627. else
  1628. {
  1629. RemoteDirView->Path = Path;
  1630. }
  1631. }
  1632. //---------------------------------------------------------------------------
  1633. void __fastcall TScpCommanderForm::LocalDirViewFileIconForName(
  1634. TObject * /*Sender*/, TListItem * /*Item*/, UnicodeString & FileName)
  1635. {
  1636. UnicodeString PartialExt = Configuration->PartialExt;
  1637. if (AnsiSameText(ExtractFileExt(FileName), PartialExt))
  1638. {
  1639. FileName.SetLength(FileName.Length() - PartialExt.Length());
  1640. }
  1641. if (WinConfiguration->LocalIconsByExt)
  1642. {
  1643. FileName = ExtractFileName(FileName);
  1644. }
  1645. }
  1646. //---------------------------------------------------------------------------
  1647. void __fastcall TScpCommanderForm::LocalDirViewUpdateStatusBar(
  1648. TObject * /*Sender*/, const TStatusFileInfo & FileInfo)
  1649. {
  1650. UpdateFileStatusBar(LocalStatusBar, FileInfo, osLocal);
  1651. }
  1652. //---------------------------------------------------------------------------
  1653. void __fastcall TScpCommanderForm::RemoteDirViewUpdateStatusBar(
  1654. TObject * /*Sender*/, const TStatusFileInfo & FileInfo)
  1655. {
  1656. UpdateFileStatusBar(RemoteStatusBar, FileInfo, osRemote);
  1657. }
  1658. //---------------------------------------------------------------------------
  1659. void __fastcall TScpCommanderForm::LocalStatusBarClick(TObject * /*Sender*/)
  1660. {
  1661. LocalDirView->SetFocus();
  1662. }
  1663. //---------------------------------------------------------------------------
  1664. UnicodeString __fastcall TScpCommanderForm::PathForCaption()
  1665. {
  1666. UnicodeString Result;
  1667. if (FCurrentSide == osLocal)
  1668. {
  1669. // for consistency do not show even local path when there is no terminal
  1670. if (Terminal != NULL)
  1671. {
  1672. switch (WinConfiguration->PathInCaption)
  1673. {
  1674. case picShort:
  1675. {
  1676. Result = ExtractFileName(LocalDirView->PathName);
  1677. if (Result.IsEmpty())
  1678. {
  1679. Result = LocalDirView->PathName;
  1680. }
  1681. }
  1682. break;
  1683. case picFull:
  1684. Result = LocalDirView->PathName;
  1685. break;
  1686. }
  1687. }
  1688. }
  1689. else
  1690. {
  1691. Result = TCustomScpExplorerForm::PathForCaption();
  1692. }
  1693. return Result;
  1694. }
  1695. //---------------------------------------------------------------------------
  1696. void __fastcall TScpCommanderForm::GetTransferPresetAutoSelectData(
  1697. TCopyParamRuleData & Data)
  1698. {
  1699. TCustomScpExplorerForm::GetTransferPresetAutoSelectData(Data);
  1700. Data.LocalDirectory = LocalDirView->PathName;
  1701. }
  1702. //---------------------------------------------------------------------------
  1703. void __fastcall TScpCommanderForm::BeforeAction()
  1704. {
  1705. TCustomScpExplorerForm::BeforeAction();
  1706. if (LocalDirView->ItemFocused != NULL)
  1707. {
  1708. LocalDirView->ItemFocused->CancelEdit();
  1709. }
  1710. }
  1711. //---------------------------------------------------------------------------
  1712. void __fastcall TScpCommanderForm::RemoteDirViewPathChange(TCustomDirView * /*Sender*/)
  1713. {
  1714. UpdateRemotePathComboBox(false);
  1715. }
  1716. //---------------------------------------------------------------------------
  1717. void __fastcall TScpCommanderForm::UpdateImages()
  1718. {
  1719. TCustomScpExplorerForm::UpdateImages();
  1720. TImageList * ImageList = ShellImageListForControl(this, ilsSmall);
  1721. RemotePathComboBox->Images = ImageList;
  1722. RemotePathComboBox->SubMenuImages = ImageList;
  1723. LocalPathComboBox->Images = ImageList;
  1724. LocalPathComboBox->SubMenuImages = ImageList;
  1725. }
  1726. //---------------------------------------------------------------------------
  1727. void __fastcall TScpCommanderForm::LocalPathComboUpdateDrives()
  1728. {
  1729. FLocalSpecialPaths = 0;
  1730. TStrings* Strings = LocalPathComboBox->Strings;
  1731. Strings->BeginUpdate();
  1732. try
  1733. {
  1734. Strings->Clear();
  1735. FLocalPathComboBoxPaths->Clear();
  1736. Strings->Add(LoadStr(SPECIAL_FOLDER_MY_DOCUMENTS));
  1737. FLocalPathComboBoxPaths->AddObject(GetPersonalFolder(),
  1738. (TObject *)DriveInfo->SpecialFolder[CSIDL_PERSONAL]->ImageIndex);
  1739. FLocalSpecialPaths++;
  1740. Strings->Add(LoadStr(SPECIAL_FOLDER_DESKTOP));
  1741. FLocalPathComboBoxPaths->AddObject(GetDesktopFolder(),
  1742. (TObject *)DriveInfo->SpecialFolder[CSIDL_DESKTOP]->ImageIndex);
  1743. FLocalSpecialPaths++;
  1744. std::unique_ptr<TStrings> Drives(LocalDriveView->GetDrives());
  1745. for (int Index = 0; Index < Drives->Count; Index++)
  1746. {
  1747. UnicodeString Drive = Drives->Strings[Index];
  1748. if (DriveInfo->Get(Drive)->Valid)
  1749. {
  1750. UnicodeString Caption = DriveInfo->GetPrettyName(Drive);
  1751. if (DriveInfo->IsRealDrive(Drive))
  1752. {
  1753. Caption.Insert(L"&", 0);
  1754. }
  1755. Strings->Add(Caption);
  1756. UnicodeString RootPath = DriveInfo->GetDriveRoot(Drive);
  1757. int ImageIndex = DriveInfo->GetImageIndex(Drive);
  1758. FLocalPathComboBoxPaths->AddObject(RootPath, reinterpret_cast<TObject *>(ImageIndex));
  1759. }
  1760. }
  1761. }
  1762. __finally
  1763. {
  1764. Strings->EndUpdate();
  1765. }
  1766. }
  1767. //---------------------------------------------------------------------------
  1768. void __fastcall TScpCommanderForm::LocalPathComboUpdate()
  1769. {
  1770. // this may get called even after destructor finishes
  1771. // (e.g. from SetDockAllowDrag invoked [indirectly] from StoreParams)
  1772. if (FLocalPathComboBoxPaths != NULL)
  1773. {
  1774. DebugAssert(FLocalPathComboBoxPaths->Count == LocalPathComboBox->Strings->Count);
  1775. int Index = 0;
  1776. while ((Index < FLocalPathComboBoxPaths->Count) &&
  1777. !SamePaths(FLocalPathComboBoxPaths->Strings[Index],
  1778. LocalDirView->Path.SubString(1, FLocalPathComboBoxPaths->Strings[Index].Length())))
  1779. {
  1780. Index++;
  1781. }
  1782. // what to do if not?
  1783. if (Index < FLocalPathComboBoxPaths->Count)
  1784. {
  1785. LocalPathComboBox->ItemIndex = Index;
  1786. }
  1787. }
  1788. }
  1789. //---------------------------------------------------------------------------
  1790. void __fastcall TScpCommanderForm::LocalDirViewPathChange(TCustomDirView * /*Sender*/)
  1791. {
  1792. LocalPathComboUpdate();
  1793. if (IsUncPath(LocalDirView->Path))
  1794. {
  1795. Configuration->Usage->Inc(L"BrowsedUncPath");
  1796. }
  1797. }
  1798. //---------------------------------------------------------------------------
  1799. void __fastcall TScpCommanderForm::LocalPathComboBoxCancel(TObject * /*Sender*/)
  1800. {
  1801. LocalPathComboUpdate();
  1802. }
  1803. //---------------------------------------------------------------------------
  1804. void __fastcall TScpCommanderForm::LocalPathComboBoxAdjustImageIndex(
  1805. TTBXComboBoxItem * /*Sender*/, const UnicodeString AText, int AIndex,
  1806. int & ImageIndex)
  1807. {
  1808. // this may get called even before constructor starts
  1809. // (e.g. from FixControlsPlacement)
  1810. if (FLocalPathComboBoxPaths != NULL)
  1811. {
  1812. DebugAssert(FLocalPathComboBoxPaths->Count == LocalPathComboBox->Strings->Count);
  1813. DebugAssert(AIndex < FLocalPathComboBoxPaths->Count);
  1814. if (AIndex < 0)
  1815. {
  1816. AIndex = LocalPathComboBox->ItemIndex;
  1817. }
  1818. if (AIndex >= 0)
  1819. {
  1820. ImageIndex = int(FLocalPathComboBoxPaths->Objects[AIndex]);
  1821. }
  1822. }
  1823. }
  1824. //---------------------------------------------------------------------------
  1825. void __fastcall TScpCommanderForm::LocalPathComboBoxItemClick(TObject * /*Sender*/)
  1826. {
  1827. DebugAssert(FLocalPathComboBoxPaths->Count == LocalPathComboBox->Strings->Count);
  1828. DebugAssert((LocalPathComboBox->ItemIndex >= 0) && (LocalPathComboBox->ItemIndex < FLocalPathComboBoxPaths->Count));
  1829. UnicodeString Path = FLocalPathComboBoxPaths->Strings[LocalPathComboBox->ItemIndex];
  1830. if (LocalPathComboBox->ItemIndex >= FLocalSpecialPaths)
  1831. {
  1832. LocalDirView->ExecuteDrive(DriveInfo->GetDriveKey(Path));
  1833. }
  1834. else
  1835. {
  1836. LocalDirView->Path = Path;
  1837. }
  1838. }
  1839. //---------------------------------------------------------------------------
  1840. void __fastcall TScpCommanderForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  1841. {
  1842. TCustomScpExplorerForm::ToolbarItemResize(Item, Width);
  1843. if ((Item == LocalPathComboBox) ||
  1844. (Item == RemotePathComboBox) ||
  1845. (Item == CommandLineCombo))
  1846. {
  1847. dynamic_cast<TTBXComboBoxItem *>(Item)->MinListWidth = Width - 4;
  1848. }
  1849. }
  1850. //---------------------------------------------------------------------------
  1851. void __fastcall TScpCommanderForm::CommandLineComboPopup(
  1852. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  1853. {
  1854. CommandLinePopulate();
  1855. }
  1856. //---------------------------------------------------------------------------
  1857. void __fastcall TScpCommanderForm::CommandLineComboBeginEdit(
  1858. TTBEditItem * /*Sender*/, TTBEditItemViewer * /*Viewer*/, TEdit *EditControl)
  1859. {
  1860. InstallPathWordBreakProc(EditControl);
  1861. FCommandLineComboEdit = EditControl;
  1862. FToolbarEditOldWndProc = EditControl->WindowProc;
  1863. EditControl->WindowProc = CommandLineComboEditWndProc;
  1864. }
  1865. //---------------------------------------------------------------------------
  1866. void __fastcall TScpCommanderForm::ExitToolbar()
  1867. {
  1868. CurrentPanel()->SetFocus();
  1869. }
  1870. //---------------------------------------------------------------------------
  1871. void __fastcall TScpCommanderForm::CommandLineComboEditWndProc(TMessage & Message)
  1872. {
  1873. bool Handled = false;
  1874. if (Message.Msg == WM_CHAR)
  1875. {
  1876. switch (reinterpret_cast<TWMChar &>(Message).CharCode)
  1877. {
  1878. case VK_ESCAPE:
  1879. CommandLineCombo->Text = L"";
  1880. ExitToolbar();
  1881. Handled = true;
  1882. break;
  1883. case VK_TAB:
  1884. CommandLineCombo->Text = FCommandLineComboEdit->Text;
  1885. ExitToolbar();
  1886. Handled = true;
  1887. break;
  1888. case VK_RETURN:
  1889. CommandLineCombo->Text = FCommandLineComboEdit->Text;
  1890. ExitToolbar();
  1891. if (!ExecuteCommandLine())
  1892. {
  1893. // re-enter command line
  1894. // (most probably exited by now as message dialog was shown)
  1895. GoToCommandLine();
  1896. }
  1897. Handled = true;
  1898. break;
  1899. }
  1900. }
  1901. if (!Handled)
  1902. {
  1903. FToolbarEditOldWndProc(Message);
  1904. }
  1905. }
  1906. //---------------------------------------------------------------------------
  1907. void __fastcall TScpCommanderForm::LocalDriveViewRefreshDrives(TObject * /*Sender*/)
  1908. {
  1909. LocalPathComboUpdateDrives();
  1910. LocalPathComboUpdate();
  1911. }
  1912. //---------------------------------------------------------------------------
  1913. void __fastcall TScpCommanderForm::HomeDirectory(TOperationSide Side)
  1914. {
  1915. bool SynchronizeBrowsing = NonVisualDataModule->SynchronizeBrowsingAction->Checked;
  1916. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1917. TCustomScpExplorerForm::HomeDirectory(Side);
  1918. if (SynchronizeBrowsing)
  1919. {
  1920. TCustomScpExplorerForm::HomeDirectory(GetOtherSize(Side));
  1921. }
  1922. }
  1923. //---------------------------------------------------------------------------
  1924. void __fastcall TScpCommanderForm::QueueSubmenuItemPopup(
  1925. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  1926. {
  1927. NonVisualDataModule->QueueSpeedComboBoxItemUpdate(QueueSpeedComboBoxItem);
  1928. }
  1929. //---------------------------------------------------------------------------
  1930. void __fastcall TScpCommanderForm::DoFocusRemotePath(TTerminal * Terminal, const UnicodeString & Path)
  1931. {
  1932. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1933. TCustomScpExplorerForm::DoFocusRemotePath(Terminal, Path);
  1934. }
  1935. //---------------------------------------------------------------------------
  1936. TOperationSide __fastcall TScpCommanderForm::GetOtherSize(TOperationSide Side)
  1937. {
  1938. Side = GetSide(Side);
  1939. return ReverseOperationSide(Side);
  1940. }
  1941. //---------------------------------------------------------------------------
  1942. void __fastcall TScpCommanderForm::HistoryGo(TOperationSide Side, int Index)
  1943. {
  1944. TOperationSide OtherSide = GetOtherSize(Side);
  1945. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked &&
  1946. ((Index < 0) ? (-Index < DirView(OtherSide)->BackCount) : (Index < DirView(OtherSide)->ForwardCount)))
  1947. {
  1948. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1949. TCustomScpExplorerForm::HistoryGo(Side, Index);
  1950. TCustomScpExplorerForm::HistoryGo(OtherSide, Index);
  1951. }
  1952. else
  1953. {
  1954. TCustomScpExplorerForm::HistoryGo(Side, Index);
  1955. }
  1956. }
  1957. //---------------------------------------------------------------------------
  1958. void __fastcall TScpCommanderForm::DirViewHistoryGo(
  1959. TCustomDirView * Sender, int Index, bool & Cancel)
  1960. {
  1961. TOperationSide Side = (Sender == DirView(osRemote) ? osRemote : osLocal);
  1962. HistoryGo(Side, Index);
  1963. Cancel = true;
  1964. }
  1965. //---------------------------------------------------------------------------
  1966. bool __fastcall TScpCommanderForm::EligibleForImageDisplayMode(TTBCustomItem * Item)
  1967. {
  1968. return
  1969. TCustomScpExplorerForm::EligibleForImageDisplayMode(Item) &&
  1970. ((Item->Parent == NULL) || (Item->Parent->ParentComponent != Toolbar2Toolbar));
  1971. }
  1972. //---------------------------------------------------------------------------
  1973. bool __fastcall TScpCommanderForm::UpdateToolbarDisplayMode()
  1974. {
  1975. bool Result = TCustomScpExplorerForm::UpdateToolbarDisplayMode();
  1976. if (Result)
  1977. {
  1978. // command line combo width needs to be updated as caption visibility has changed
  1979. ToolBarResize(CommandLineToolbar);
  1980. }
  1981. return Result;
  1982. }
  1983. //---------------------------------------------------------------------------
  1984. void __fastcall TScpCommanderForm::QueueLabelUpdateStatus()
  1985. {
  1986. TCustomScpExplorerForm::QueueLabelUpdateStatus();
  1987. // this is here to deactivate panels path labels when moving focus from
  1988. // directory tree to queue
  1989. UpdatePanelsPathLabelsStatus();
  1990. }
  1991. //---------------------------------------------------------------------------
  1992. void __fastcall TScpCommanderForm::LocalDirViewContextPopup(TObject * /*Sender*/,
  1993. TPoint & MousePos, bool & Handled)
  1994. {
  1995. if (!WinConfiguration->ScpCommander.SystemContextMenu && !FForceSystemContextMenu)
  1996. {
  1997. DirViewContextPopupDefaultItem(osLocal, NonVisualDataModule->LocalOpenMenuItem, dcaOpen);
  1998. DirViewContextPopupDefaultItem(osLocal, NonVisualDataModule->LocalEditMenuItem, dcaEdit);
  1999. DirViewContextPopupDefaultItem(osLocal, NonVisualDataModule->LocalCopyMenuItem, dcaCopy);
  2000. DirViewContextPopup(osLocal, fcLocalPopup, MousePos);
  2001. Handled = true;
  2002. }
  2003. }
  2004. //---------------------------------------------------------------------------
  2005. void __fastcall TScpCommanderForm::DisplaySystemContextMenu()
  2006. {
  2007. TAutoFlag Flag(FForceSystemContextMenu);
  2008. if ((FLastContextPopupScreenPoint.x >= 0) && (FLastContextPopupScreenPoint.Y >= 0))
  2009. {
  2010. LocalDirView->DisplayContextMenu(FLastContextPopupScreenPoint);
  2011. }
  2012. else
  2013. {
  2014. LocalDirView->DisplayContextMenuInSitu();
  2015. }
  2016. }
  2017. //---------------------------------------------------------------------------
  2018. void __fastcall TScpCommanderForm::LocalStatusBarPanelClick(TTBXCustomStatusBar * /*Sender*/,
  2019. TTBXStatusPanel * Panel)
  2020. {
  2021. FileStatusBarPanelClick(Panel, osLocal);
  2022. }
  2023. //---------------------------------------------------------------------------
  2024. void __fastcall TScpCommanderForm::RemoteStatusBarPanelClick(TTBXCustomStatusBar * /*Sender*/,
  2025. TTBXStatusPanel *Panel)
  2026. {
  2027. FileStatusBarPanelClick(Panel, osRemote);
  2028. }
  2029. //---------------------------------------------------------------------------
  2030. void __fastcall TScpCommanderForm::GoToAddress()
  2031. {
  2032. OpenDirectory(GetSide(osCurrent));
  2033. }
  2034. //---------------------------------------------------------------------------
  2035. void __fastcall TScpCommanderForm::RemotePathLabelMaskClick(TObject * /*Sender*/)
  2036. {
  2037. Filter(osRemote);
  2038. }
  2039. //---------------------------------------------------------------------------
  2040. void __fastcall TScpCommanderForm::LocalPathLabelMaskClick(TObject * /*Sender*/)
  2041. {
  2042. Filter(osLocal);
  2043. }
  2044. //---------------------------------------------------------------------------
  2045. void __fastcall TScpCommanderForm::LocalOpenDirButtonPopup(TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  2046. {
  2047. CreateOpenDirMenu(LocalOpenDirButton, osLocal);
  2048. }
  2049. //---------------------------------------------------------------------------
  2050. void __fastcall TScpCommanderForm::RemoteOpenDirButtonPopup(TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  2051. {
  2052. CreateOpenDirMenu(RemoteOpenDirButton, osRemote);
  2053. }
  2054. //---------------------------------------------------------------------------
  2055. void __fastcall TScpCommanderForm::CopyFilesToClipboard(TOperationSide Side)
  2056. {
  2057. if (GetSide(Side) == osLocal)
  2058. {
  2059. TInstantOperationVisualizer Visualizer;
  2060. LocalDirView->CopyToClipBoard();
  2061. }
  2062. else
  2063. {
  2064. TCustomScpExplorerForm::CopyFilesToClipboard(Side);
  2065. }
  2066. }
  2067. //---------------------------------------------------------------------------
  2068. void __fastcall TScpCommanderForm::PasteFromClipBoard()
  2069. {
  2070. if (DoesClipboardContainOurFiles() && (GetSide(osCurrent) == osLocal))
  2071. {
  2072. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  2073. {
  2074. ClipboardDownload(LocalDirView->Path, !WinConfiguration->ConfirmTransferring, false);
  2075. }
  2076. }
  2077. else
  2078. {
  2079. TCustomScpExplorerForm::PasteFromClipBoard();
  2080. }
  2081. }
  2082. //---------------------------------------------------------------------------