ScpCommander.cpp 78 KB

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