ScpCommander.cpp 90 KB

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