ScpCommander.cpp 76 KB

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