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. if (Directory.IsEmpty() || SamePaths(Directory, OtherLocalDirView->Path))
  468. {
  469. OtherLocalDirView->ReloadDirectory();
  470. OtherLocalDriveView->ValidateDirectory(OtherLocalDriveView->Selected);
  471. }
  472. TCustomScpExplorerForm::ReloadLocalDirectory();
  473. }
  474. //---------------------------------------------------------------------------
  475. void __fastcall TScpCommanderForm::BatchStart(void *& Storage)
  476. {
  477. Storage = new bool;
  478. *static_cast<bool*>(Storage) = LocalDirView->WatchForChanges;
  479. LocalDirView->WatchForChanges = false;
  480. LocalDriveView->WatchDirectory = false;
  481. OtherLocalDirView->WatchForChanges = false;
  482. OtherLocalDriveView->WatchDirectory = false;
  483. TCustomScpExplorerForm::BatchStart(Storage);
  484. }
  485. //---------------------------------------------------------------------------
  486. void __fastcall TScpCommanderForm::BatchEnd(void * Storage)
  487. {
  488. TCustomScpExplorerForm::BatchEnd(Storage);
  489. DebugAssert(Storage != NULL);
  490. LocalDirView->WatchForChanges = *static_cast<bool*>(Storage);
  491. LocalDriveView->WatchDirectory = LocalDirView->WatchForChanges;
  492. OtherLocalDirView->WatchForChanges = LocalDirView->WatchForChanges;
  493. OtherLocalDriveView->WatchDirectory = LocalDirView->WatchForChanges;
  494. delete Storage;
  495. }
  496. //---------------------------------------------------------------------------
  497. void __fastcall TScpCommanderForm::StartingDisconnected()
  498. {
  499. TCustomScpExplorerForm::StartingDisconnected();
  500. LocalDefaultDirectory();
  501. }
  502. //---------------------------------------------------------------------------
  503. void __fastcall TScpCommanderForm::TerminalChanged(bool Replaced)
  504. {
  505. NonVisualDataModule->SynchronizeBrowsingAction2->Checked = false;
  506. TCustomScpExplorerForm::TerminalChanged(Replaced);
  507. if (Terminal)
  508. {
  509. // we will load completelly different directory, so particularly
  510. // do not attempt to select previously selected directory
  511. LocalDirView->ContinueSession(false);
  512. // reset home directory
  513. LocalDirView->HomeDirectory = L"";
  514. if (FFirstTerminal || !WinConfiguration->ScpCommander.PreserveLocalDirectory)
  515. {
  516. UnicodeString LocalDirectory = Terminal->StateData->LocalDirectory;
  517. if (!LocalDirectory.IsEmpty())
  518. {
  519. try
  520. {
  521. LocalDirView->Path = LocalDirectory;
  522. }
  523. catch(Exception & E)
  524. {
  525. if (!Terminal->SessionData->UpdateDirectories)
  526. {
  527. Terminal->ShowExtendedException(&E);
  528. }
  529. }
  530. }
  531. }
  532. FFirstTerminal = false;
  533. // Happens when opening a connection from a command-line (StartingDisconnected was not called),
  534. // which does not have a local directory set yet.
  535. if (LocalDirView->Path.IsEmpty())
  536. {
  537. LocalDefaultDirectory();
  538. }
  539. if (WinConfiguration->DefaultDirIsHome &&
  540. !Terminal->SessionData->UpdateDirectories)
  541. {
  542. LocalDirView->HomeDirectory = Terminal->SessionData->LocalDirectoryExpanded;
  543. }
  544. if (WinConfiguration->PreservePanelState &&
  545. !WinConfiguration->ScpCommander.PreserveLocalDirectory)
  546. {
  547. if (Terminal->LocalExplorerState != NULL)
  548. {
  549. LocalDirView->RestoreState(Terminal->LocalExplorerState);
  550. }
  551. else
  552. {
  553. LocalDirView->ClearState();
  554. }
  555. NonVisualDataModule->SynchronizeBrowsingAction2->Checked = Terminal->StateData->SynchronizeBrowsing;
  556. }
  557. }
  558. }
  559. //---------------------------------------------------------------------------
  560. void __fastcall TScpCommanderForm::DoLocalDefaultDirectory(TDirView * DirView, const UnicodeString & LastPath)
  561. {
  562. bool DocumentsDir = true;
  563. if (!LastPath.IsEmpty())
  564. {
  565. try
  566. {
  567. DirView->Path = LastPath;
  568. DocumentsDir = false;
  569. }
  570. catch (...)
  571. {
  572. }
  573. }
  574. if (DocumentsDir)
  575. {
  576. try
  577. {
  578. DirView->HomeDirectory = L"";
  579. UnicodeString HomeDrive = DriveInfo->GetDriveKey(DirView->HomeDirectory);
  580. if (DriveInfo->Get(HomeDrive)->DriveType == DRIVE_REMOTE)
  581. {
  582. DirView->Path = DriveInfo->AnyValidPath();
  583. }
  584. else
  585. {
  586. DirView->ExecuteHomeDirectory();
  587. }
  588. }
  589. catch(Exception & E)
  590. {
  591. ShowExtendedException(NULL, &E);
  592. DirView->Path = ExtractFilePath(Application->ExeName);
  593. }
  594. }
  595. }
  596. //---------------------------------------------------------------------------
  597. void __fastcall TScpCommanderForm::LocalDefaultDirectory()
  598. {
  599. DoLocalDefaultDirectory(LocalDirView, WinConfiguration->ScpCommander.LocalPanel.LastPath);
  600. }
  601. //---------------------------------------------------------------------------
  602. void __fastcall TScpCommanderForm::ConfigurationChanged()
  603. {
  604. TCustomScpExplorerForm::ConfigurationChanged();
  605. if (WinConfiguration->DefaultDirIsHome && Terminal &&
  606. !Terminal->SessionData->UpdateDirectories)
  607. {
  608. LocalDirView->HomeDirectory = Terminal->SessionData->LocalDirectoryExpanded;
  609. }
  610. else
  611. {
  612. LocalDirView->HomeDirectory = L"";
  613. }
  614. LocalDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  615. LocalDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  616. OtherLocalDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  617. OtherLocalDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  618. LocalDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  619. LocalDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  620. OtherLocalDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  621. OtherLocalDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  622. LocalDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  623. OtherLocalDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  624. LocalDirView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  625. LocalDriveView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  626. OtherLocalDirView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  627. OtherLocalDriveView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  628. LocalDirView->NortonLike = WinConfiguration->ScpCommander.NortonLikeMode;
  629. OtherLocalDirView->NortonLike = WinConfiguration->ScpCommander.NortonLikeMode;
  630. RemoteDirView->NortonLike = WinConfiguration->ScpCommander.NortonLikeMode;
  631. LocalDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  632. LocalDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  633. OtherLocalDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  634. OtherLocalDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  635. LocalDirView->TimeoutShellIconRetrieval = WinConfiguration->TimeoutShellIconRetrieval;
  636. LocalDirView->UseIconUpdateThread = WinConfiguration->UseIconUpdateThread;
  637. OtherLocalDirView->TimeoutShellIconRetrieval = WinConfiguration->TimeoutShellIconRetrieval;
  638. OtherLocalDirView->UseIconUpdateThread = WinConfiguration->UseIconUpdateThread;
  639. UpdateRowSelect(LocalDirView);
  640. UpdateRowSelect(OtherLocalDirView);
  641. // See also LocalDirViewDDTargetHasDropHandler
  642. LocalDirView->DragDropFilesEx->ShellExtensions->DropHandler = !WinConfiguration->DDFakeFile;
  643. LocalDriveView->DragDropFilesEx->ShellExtensions->DropHandler = !WinConfiguration->DDFakeFile;
  644. OtherLocalDirView->DragDropFilesEx->ShellExtensions->DropHandler = !WinConfiguration->DDFakeFile;
  645. OtherLocalDriveView->DragDropFilesEx->ShellExtensions->DropHandler = !WinConfiguration->DDFakeFile;
  646. if (Panel(true)->Left > Panel(false)->Left)
  647. {
  648. DisableAlign();
  649. try
  650. {
  651. int AWidth = ClientWidth;
  652. Panel(false)->Align = alClient;
  653. // In bidi mode it gets swapped to alRight, what does not work with the rest of this logic
  654. Splitter->Align = alLeft;
  655. Panel(true)->Align = alLeft;
  656. TControl * ControlsOrder[] =
  657. { Panel(true), Splitter, Panel(false) };
  658. SetHorizontalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  659. Panel(true)->TabOrder = 0;
  660. Panel(false)->TabOrder = 1;
  661. ClientWidth = AWidth;
  662. LeftPanelWidth = FLastLeftPanelWidth;
  663. }
  664. __finally
  665. {
  666. EnableAlign();
  667. }
  668. int LocalIndex = MenuToolbar->Items->IndexOf(LocalMenuButton);
  669. int RemoteIndex = MenuToolbar->Items->IndexOf(RemoteMenuButton);
  670. MenuToolbar->Items->Move(LocalIndex, RemoteIndex);
  671. RemoteIndex = MenuToolbar->Items->IndexOf(RemoteMenuButton);
  672. MenuToolbar->Items->Move(RemoteIndex, LocalIndex);
  673. SWAP(TShortCut, NonVisualDataModule->LocalChangePathAction2->ShortCut, NonVisualDataModule->RemoteChangePathAction2->ShortCut);
  674. SWAP(UnicodeString, NonVisualDataModule->CommanderLocalPanelAction->Caption, NonVisualDataModule->CommanderRemotePanelAction->Caption);
  675. SWAP(UnicodeString, NonVisualDataModule->CommanderLocalPanelAction->Hint, NonVisualDataModule->CommanderRemotePanelAction->Hint);
  676. }
  677. if ((RemoteDrivePanel->Align == alLeft) != WinConfiguration->ScpCommander.TreeOnLeft)
  678. {
  679. TScpCommanderPanelConfiguration LocalPanel = WinConfiguration->ScpCommander.LocalPanel;
  680. TScpCommanderPanelConfiguration RemotePanel = WinConfiguration->ScpCommander.RemotePanel;
  681. bool TreeOnLeft = WinConfiguration->ScpCommander.TreeOnLeft;
  682. // save value only if it was set yet
  683. if (FPanelsRestored)
  684. {
  685. if (TreeOnLeft)
  686. {
  687. // want to be on left, so it is on top, saving height
  688. LocalPanel.DriveViewHeight = LocalDriveView->Height;
  689. RemotePanel.DriveViewHeight = RemoteDrivePanel->Height;
  690. }
  691. else
  692. {
  693. LocalPanel.DriveViewWidth = LocalDriveView->Width;
  694. RemotePanel.DriveViewWidth = RemoteDrivePanel->Width;
  695. }
  696. }
  697. TAlign NonClientAlign = (TreeOnLeft ? alLeft : alTop);
  698. // VCL adjusts cursors only between crVSplit and crHSplit,
  699. // See TSplitter.RequestAlign
  700. TCursor SplitterCursor = (TreeOnLeft ? crSizeWE : crSizeNS);
  701. LocalDriveView->Align = NonClientAlign;
  702. OtherLocalDriveView->Align = NonClientAlign;
  703. LocalPanelSplitter->Align = NonClientAlign;
  704. LocalPanelSplitter->Cursor = SplitterCursor;
  705. RemoteDrivePanel->Align = NonClientAlign;
  706. RemotePanelSplitter->Align = NonClientAlign;
  707. RemotePanelSplitter->Cursor = SplitterCursor;
  708. FixControlsPlacement();
  709. if (TreeOnLeft)
  710. {
  711. LocalDriveView->Width = LocalPanel.DriveViewWidth;
  712. RemoteDrivePanel->Width = RemotePanel.DriveViewWidth;
  713. }
  714. else
  715. {
  716. LocalDriveView->Height = LocalPanel.DriveViewHeight;
  717. RemoteDrivePanel->Height = RemotePanel.DriveViewHeight;
  718. }
  719. // in case it trigges config-changed event (does not),
  720. // make sure it does only after we apply the TreeOnLeft change to avoid endless recursion
  721. WinConfiguration->ScpCommander.LocalPanel = LocalPanel;
  722. WinConfiguration->ScpCommander.RemotePanel = RemotePanel;
  723. }
  724. if (FExplorerKeyboardShortcuts != WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  725. {
  726. SetShortcuts();
  727. }
  728. }
  729. //---------------------------------------------------------------------------
  730. void __fastcall TScpCommanderForm::SetShortcuts()
  731. {
  732. // set common norton shorcuts to our actions
  733. NonVisualDataModule->CommanderShortcuts();
  734. FExplorerKeyboardShortcuts = WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts;
  735. }
  736. //---------------------------------------------------------------------------
  737. TPanel * __fastcall TScpCommanderForm::Panel(bool Left)
  738. {
  739. bool SwappedPanels = WinConfiguration->ScpCommander.SwappedPanels;
  740. if (IsRightToLeft())
  741. {
  742. SwappedPanels = !SwappedPanels;
  743. }
  744. return (SwappedPanels == Left ? RemotePanel : LocalPanel);
  745. }
  746. //---------------------------------------------------------------------------
  747. TPanel * __fastcall TScpCommanderForm::CurrentPanel()
  748. {
  749. return (FCurrentSide == osLocal ? LocalPanel : RemotePanel);
  750. }
  751. //---------------------------------------------------------------------------
  752. void __fastcall TScpCommanderForm::SetLeftPanelWidth(double value)
  753. {
  754. double Total = LocalPanel->Width + RemotePanel->Width;
  755. FLeftPanelWidth = value;
  756. if (value * Total != Panel(true)->Width)
  757. {
  758. Panel(true)->Width = static_cast<int>(value * Total);
  759. UpdateControls();
  760. }
  761. }
  762. //---------------------------------------------------------------------------
  763. double __fastcall TScpCommanderForm::GetLeftPanelWidth()
  764. {
  765. return FLeftPanelWidth;
  766. }
  767. //---------------------------------------------------------------------------
  768. void __fastcall TScpCommanderForm::SplitterMoved(TObject * /*Sender*/)
  769. {
  770. double Left = Panel(true)->Width;
  771. double Total = LocalPanel->Width + RemotePanel->Width;
  772. FLeftPanelWidth = Left / Total;
  773. FLastLeftPanelWidth = LeftPanelWidth;
  774. UpdateControls();
  775. }
  776. //---------------------------------------------------------------------------
  777. void __fastcall TScpCommanderForm::SplitterCanResize(TObject * /*Sender*/,
  778. int &NewSize, bool & /*Accept*/)
  779. {
  780. // When splitter is drag so far to right, that width contraint of remote panel would
  781. // be violated, it doesn't stop, but extend form width.
  782. // Following prevents this behavior.
  783. if (ClientWidth - NewSize - Splitter->Width < Panel(false)->Constraints->MinWidth)
  784. NewSize = (ClientWidth - Panel(false)->Constraints->MinWidth - Splitter->Width);
  785. }
  786. //---------------------------------------------------------------------------
  787. void __fastcall TScpCommanderForm::SplitterDblClick(TObject * /*Sender*/)
  788. {
  789. LeftPanelWidth = 0.5;
  790. }
  791. //---------------------------------------------------------------------------
  792. void __fastcall TScpCommanderForm::PanelSplitterDblClick(TObject * Sender)
  793. {
  794. TSplitter * Splitter = dynamic_cast<TSplitter *>(Sender);
  795. DebugAssert(Splitter != NULL);
  796. TControl * DriveView;
  797. TControl * OtherDriveView;
  798. if (Splitter == LocalPanelSplitter)
  799. {
  800. DriveView = LocalDriveView;
  801. OtherDriveView = RemoteDrivePanel;
  802. }
  803. else
  804. {
  805. DriveView = RemoteDrivePanel;
  806. OtherDriveView = LocalDriveView;
  807. }
  808. bool TreeOnLeft = WinConfiguration->ScpCommander.TreeOnLeft;
  809. DebugAssert(DriveView->Visible);
  810. if (OtherDriveView->Visible)
  811. {
  812. if (TreeOnLeft)
  813. {
  814. DriveView->Width = OtherDriveView->Width;
  815. }
  816. else
  817. {
  818. DriveView->Height = OtherDriveView->Height;
  819. }
  820. }
  821. else
  822. {
  823. if (TreeOnLeft)
  824. {
  825. OtherDriveView->Width = DriveView->Width;
  826. }
  827. else
  828. {
  829. OtherDriveView->Height = DriveView->Height;
  830. }
  831. OtherDriveView->Visible = true;
  832. }
  833. FixControlsPlacement();
  834. }
  835. //---------------------------------------------------------------------------
  836. void __fastcall TScpCommanderForm::UpdateControls()
  837. {
  838. // Before TCustomScpExplorerForm disables them (when disconnecting)
  839. bool DirViewWasFocused = DirView(osOther)->Focused();
  840. bool DriveViewWasFocused = DriveView(osOther)->Focused();
  841. TCustomScpExplorerForm::UpdateControls();
  842. UnicodeString SplitterLongHint = Splitter->Hint;
  843. int P = SplitterLongHint.Pos(L"|");
  844. if (P == 0)
  845. {
  846. P = SplitterLongHint.Pos(L"\n");
  847. }
  848. SplitterLongHint.Delete(1, P);
  849. Splitter->Hint = FORMAT(L"%0.0f%%\n%s", (LeftPanelWidth*100, SplitterLongHint));
  850. UnicodeString ACommandLinePromptLabel = LoadStr(COMMAND_LINE_LABEL) + " " +
  851. (!IsSideLocalBrowser(FCurrentSide) ? L"$" : L">");
  852. if (CommandLinePromptLabel->Caption != ACommandLinePromptLabel)
  853. {
  854. CommandLinePromptLabel->Caption = ACommandLinePromptLabel;
  855. // command line combo width needs to be updated as caption width has probably changed
  856. ToolBarResize(CommandLineToolbar);
  857. }
  858. LocalDirView->DarkMode = WinConfiguration->UseDarkTheme();
  859. LocalDriveView->DarkMode = LocalDirView->DarkMode;
  860. OtherLocalDirView->DarkMode = LocalDirView->DarkMode;
  861. OtherLocalDriveView->DarkMode = LocalDirView->DarkMode;
  862. LocalDirView->Color = PanelColor();
  863. LocalDriveView->Color = LocalDirView->Color;
  864. OtherLocalDirView->Color = LocalDirView->Color;
  865. OtherLocalDriveView->Color = LocalDirView->Color;
  866. LocalDirView->Font->Color = GetWindowTextColor(LocalDirView->Color);
  867. LocalDriveView->Font->Color = LocalDirView->Font->Color;
  868. OtherLocalDirView->Font->Color = LocalDirView->Font->Color;
  869. OtherLocalDriveView->Font->Color = LocalDirView->Font->Color;
  870. // TODO_OTHER_LOCAL
  871. bool LocalSide = (FCurrentSide == osLocal);
  872. TAction * CurrentCopyAction = LocalSide ? NonVisualDataModule->LocalCopyAction : NonVisualDataModule->RemoteCopyAction;
  873. if (CurrentCopyItem->Action != CurrentCopyAction)
  874. {
  875. CurrentCopyItem->Action = CurrentCopyAction;
  876. CurrentCopyToolbar2Item->Action = CurrentCopyAction;
  877. UpdateToolbar2ItemCaption(CurrentCopyToolbar2Item);
  878. CurrentCopyNonQueueItem->Action = LocalSide ? NonVisualDataModule->LocalCopyNonQueueAction : NonVisualDataModule->RemoteCopyNonQueueAction;
  879. CurrentCopyQueueItem->Action = LocalSide ? NonVisualDataModule->LocalCopyQueueAction : NonVisualDataModule->RemoteCopyQueueAction;
  880. TAction * CurrentMoveAction = LocalSide ? NonVisualDataModule->LocalMoveAction : NonVisualDataModule->RemoteMoveAction;
  881. CurrentMoveItem->Action = CurrentMoveAction;
  882. CurrentMoveToolbar2Item->Action = CurrentMoveAction;
  883. UpdateToolbar2ItemCaption(CurrentMoveToolbar2Item);
  884. }
  885. CommandLineCombo->Enabled = IsSideLocalBrowser(FCurrentSide) || CanConsole();
  886. CommandLinePromptLabel->Enabled = CommandLineCombo->Enabled;
  887. // Ad hoc hack to disable the drop down menu, when all its items (and all other buttons on the toolbar) are disabled,
  888. // otherwise it shines too much on the toolbar.
  889. RemoteNewSubmenuItem->Enabled = DirViewEnabled(osRemote);
  890. // When implicitly connecting a not-yet-connected session by switching to its tab opened with workspace,
  891. // Terminal property is still NULL, but ActiveTerminal is already set.
  892. // Had we used Terminal for the test, the window would switch to local-local mode temporarily while session is opening.
  893. bool HasTerminal = (TTerminalManager::Instance()->ActiveTerminal != NULL);
  894. RemoteDirView->Visible = HasTerminal;
  895. RemoteDriveView->Visible = HasTerminal;
  896. OtherLocalDirView->Visible = !HasTerminal;
  897. OtherLocalDriveView->Visible = !HasTerminal;
  898. bool LocalOnLeft = (Panel(true) == LocalPanel);
  899. LocalMenuButton->Caption = LoadStr(HasTerminal ? LOCAL_MENU_CAPTION : (LocalOnLeft ? LEFT_MENU_CAPTION : RIGHT_MENU_CAPTION));
  900. RemoteMenuButton->Caption = LoadStr(HasTerminal ? REMOTE_MENU_CAPTION : (LocalOnLeft ? RIGHT_MENU_CAPTION : LEFT_MENU_CAPTION));
  901. if (DirViewWasFocused)
  902. {
  903. if (DirView(osOther)->Enabled)
  904. {
  905. DirView(osOther)->SetFocus();
  906. }
  907. else
  908. {
  909. LocalDirView->SetFocus();
  910. }
  911. }
  912. if (DriveViewWasFocused)
  913. {
  914. if (DriveView(osOther)->Enabled)
  915. {
  916. DriveView(osOther)->SetFocus();
  917. }
  918. else
  919. {
  920. LocalDriveView->SetFocus();
  921. }
  922. }
  923. if (RemotePathLabel->FocusControl != DirView(osOther))
  924. {
  925. if (DebugAlwaysTrue(RemotePathLabel->FocusControl != NULL))
  926. {
  927. dynamic_cast<TCustomDirView *>(RemotePathLabel->FocusControl)->PathLabel = NULL;
  928. }
  929. DirView(osOther)->PathLabel = RemotePathLabel;
  930. RemotePathLabel->UnixPath = !IsSideLocalBrowser(osOther);
  931. DirView(osOther)->UpdateStatusBar();
  932. }
  933. }
  934. //---------------------------------------------------------------------------
  935. void __fastcall TScpCommanderForm::ChangePath(TOperationSide Side)
  936. {
  937. DebugAssert((Side == osLocal) || (Side == osRemote));
  938. TTBXComboBoxItem * PathComboBox;
  939. if (Side == osLocal)
  940. {
  941. PathComboBox = LocalPathComboBox;
  942. }
  943. else
  944. {
  945. PathComboBox = RemotePathComboBox;
  946. }
  947. ClickToolbarItem(PathComboBox, false);
  948. }
  949. //---------------------------------------------------------------------------
  950. TControl * __fastcall TScpCommanderForm::GetComponent(Byte Component)
  951. {
  952. switch (Component) {
  953. case fcToolBar2: return Toolbar2Toolbar; // name changed to enforce change of default visibility
  954. case fcStatusBar: return StatusBar;
  955. case fcLocalStatusBar: return LocalStatusBar;
  956. case fcRemoteStatusBar: return RemoteStatusBar;
  957. case fcCommandLinePanel: return CommandLineToolbar;
  958. case fcLocalTree: return LocalDriveView;
  959. case fcSessionToolbar: return SessionToolbar;
  960. case fcCustomCommandsBand: return CustomCommandsToolbar;
  961. case fcColorMenu: return reinterpret_cast<TControl*>(ColorMenuItem);
  962. case fcTransferDropDown: return reinterpret_cast<TControl*>(TransferDropDown);
  963. case fcTransferList: return reinterpret_cast<TControl*>(TransferList);
  964. case fcTransferLabel: return reinterpret_cast<TControl*>(TransferLabel);
  965. case fcLocalPopup: return reinterpret_cast<TControl *>(NonVisualDataModule->LocalFilePopup);
  966. case fcRemotePathComboBox: return reinterpret_cast<TControl*>(RemotePathComboBox);
  967. case fcCommanderMenuBand: return MenuToolbar;
  968. case fcCommanderSessionBand: return SessionToolbar;
  969. case fcCommanderPreferencesBand: return PreferencesToolbar;
  970. case fcCommanderSortBand: return SortToolbar;
  971. case fcCommanderCommandsBand: return CommandsToolbar;
  972. case fcCommanderUpdatesBand: return UpdatesToolbar;
  973. case fcCommanderTransferBand: return TransferToolbar;
  974. case fcCommanderCustomCommandsBand: return CustomCommandsToolbar;
  975. case fcCommanderLocalHistoryBand: return LocalHistoryToolbar;
  976. case fcCommanderLocalNavigationBand: return LocalNavigationToolbar;
  977. case fcCommanderLocalFileBand: return LocalFileToolbar;
  978. case fcCommanderLocalSelectionBand: return LocalSelectionToolbar;
  979. case fcCommanderRemoteHistoryBand: return RemoteHistoryToolbar;
  980. case fcCommanderRemoteNavigationBand: return RemoteNavigationToolbar;
  981. case fcCommanderRemoteFileBand: return RemoteFileToolbar;
  982. case fcCommanderRemoteSelectionBand: return RemoteSelectionToolbar;
  983. default: return TCustomScpExplorerForm::GetComponent(Component);
  984. }
  985. }
  986. //---------------------------------------------------------------------------
  987. void __fastcall TScpCommanderForm::FixControlsPlacement()
  988. {
  989. TCustomScpExplorerForm::FixControlsPlacement();
  990. QueueSeparatorPanel->Visible = QueuePanel->Visible;
  991. LocalPanelSplitter->Visible = LocalDriveView->Visible;
  992. TControl * ControlsOrder[] =
  993. { BottomDock, QueueSeparatorPanel, QueueSplitter, QueuePanel, StatusBar };
  994. SetVerticalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  995. TControl * LocalControlsOrder[] =
  996. { LocalTopDock, LocalPathLabel, LocalDriveView, LocalPanelSplitter,
  997. LocalDirView, LocalBottomDock, LocalStatusBar };
  998. SetVerticalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  999. SetHorizontalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  1000. TControl * RemoteControlsOrder[] =
  1001. { RemoteTopDock, RemotePathLabel, RemoteDrivePanel, RemotePanelSplitter,
  1002. RemoteDirPanel, RemoteBottomDock, RemoteStatusBar };
  1003. SetVerticalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  1004. SetHorizontalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  1005. MakeFocusedItemVisible(LocalDirView);
  1006. MakeFocusedItemVisible(OtherLocalDirView);
  1007. }
  1008. //---------------------------------------------------------------------------
  1009. bool __fastcall TScpCommanderForm::GetHasDirView(TOperationSide Side)
  1010. {
  1011. return TCustomScpExplorerForm::GetHasDirView(Side) || (Side == osLocal);
  1012. }
  1013. //---------------------------------------------------------------------------
  1014. void __fastcall TScpCommanderForm::CompareDirectories()
  1015. {
  1016. LocalDirView->CompareFiles(DirView(osOther), false,
  1017. WinConfiguration->ScpCommander.CompareCriterias());
  1018. DirView(osOther)->CompareFiles(LocalDirView, false,
  1019. WinConfiguration->ScpCommander.CompareCriterias());
  1020. if (LocalDirView->SelCount + DirView(osOther)->SelCount == 0)
  1021. {
  1022. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  1023. MessageDialog(Message, qtInformation, qaOK, HELP_COMPARE_NO_DIFFERENCES);
  1024. }
  1025. }
  1026. //---------------------------------------------------------------------------
  1027. void __fastcall TScpCommanderForm::SynchronizeDirectories()
  1028. {
  1029. DebugAssert(!IsLocalBrowserMode());
  1030. UnicodeString LocalDirectory = LocalDirView->PathName;
  1031. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  1032. DoSynchronizeDirectories(LocalDirectory, RemoteDirectory, -1);
  1033. }
  1034. //---------------------------------------------------------------------------
  1035. void __fastcall TScpCommanderForm::FullSynchronizeDirectories()
  1036. {
  1037. DebugAssert(!IsLocalBrowserMode());
  1038. UnicodeString LocalDirectory = LocalDirView->PathName;
  1039. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  1040. bool SaveMode = !(GUIConfiguration->SynchronizeModeAuto < 0);
  1041. TSynchronizeMode Mode =
  1042. (SaveMode ? (TSynchronizeMode)GUIConfiguration->SynchronizeModeAuto :
  1043. ((FCurrentSide == osLocal) ? smRemote : smLocal));
  1044. int Params = GUIConfiguration->SynchronizeParams;
  1045. if (DoFullSynchronizeDirectories(LocalDirectory, RemoteDirectory, Mode, Params, SaveMode, -1) >= 0)
  1046. {
  1047. if (SaveMode)
  1048. {
  1049. GUIConfiguration->SynchronizeModeAuto = Mode;
  1050. }
  1051. }
  1052. }
  1053. //---------------------------------------------------------------------------
  1054. void __fastcall TScpCommanderForm::ExploreLocalDirectory(TOperationSide Side)
  1055. {
  1056. DebugAssert(IsSideLocalBrowser(Side));
  1057. OpenFolderInExplorer(DirView(Side)->Path);
  1058. }
  1059. //---------------------------------------------------------------------------
  1060. void __fastcall TScpCommanderForm::LocalDirViewExecFile(TObject *Sender,
  1061. TListItem *Item, bool &AllowExec)
  1062. {
  1063. DebugAssert(Item);
  1064. TDirView * ADirView = DebugNotNull(dynamic_cast<TDirView *>(Sender));
  1065. if ((UpperCase(PFileRec(Item->Data)->FileExt) == L"LNK") &&
  1066. DirectoryExists(ApiPath(ResolveFileShortCut(ADirView->ItemFullFileName(Item), true))))
  1067. {
  1068. AllowExec = true;
  1069. }
  1070. else
  1071. {
  1072. DoDirViewExecFile(Sender, Item, AllowExec);
  1073. }
  1074. }
  1075. //---------------------------------------------------------------------------
  1076. void __fastcall TScpCommanderForm::LocalFileControlDDDragEnter(TObject *Sender,
  1077. IDataObject *DataObj, int grfKeyState, TPoint &Point, int &dwEffect,
  1078. bool &Accept)
  1079. {
  1080. // LocalDirViewDDDragEnter is duplication of
  1081. // TCustomScpExplorerForm::DirViewDDDragEnter, but it differs in
  1082. // literal type of 'DataObj' parameter.Actual type is however same
  1083. FileControlDDDragEnter(Sender, DataObj, grfKeyState, Point, dwEffect, Accept);
  1084. }
  1085. //---------------------------------------------------------------------------
  1086. bool __fastcall TScpCommanderForm::PanelOperation(TOperationSide Side,
  1087. bool DragDrop)
  1088. {
  1089. // TODO
  1090. return TCustomScpExplorerForm::PanelOperation(Side, DragDrop) ||
  1091. (DropSourceControl == LocalDirView);
  1092. }
  1093. //---------------------------------------------------------------------------
  1094. void __fastcall TScpCommanderForm::FileOperationProgress(
  1095. TFileOperationProgressType & ProgressData)
  1096. {
  1097. // Heuristic: When operation finishes and DD targed is local dir view,
  1098. // we suppose that drag&drop download finished, so local dir view should be
  1099. // reloaded
  1100. // TODO
  1101. if (!ProgressData.InProgress && FProgressForm &&
  1102. IsFileControl(FDDTargetControl, osLocal) &&
  1103. ((ProgressData.Operation == ::foCopy) || (ProgressData.Operation == ::foMove)))
  1104. {
  1105. ReloadLocalDirectory();
  1106. }
  1107. TCustomScpExplorerForm::FileOperationProgress(ProgressData);
  1108. }
  1109. //---------------------------------------------------------------------------
  1110. UnicodeString __fastcall TScpCommanderForm::ChangeFilePath(UnicodeString Path, TOperationSide Side)
  1111. {
  1112. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  1113. UnicodeString Result;
  1114. while (!Path.IsEmpty())
  1115. {
  1116. int P = Path.Pos(Side == osLocal ? L'\\' : L'/');
  1117. if (P > 0)
  1118. {
  1119. Result += Terminal->ChangeFileName(&CopyParams, Path.SubString(1, P - 1), Side, false) +
  1120. (Side == osLocal ? L'/' : L'\\');
  1121. Path.Delete(1, P);
  1122. }
  1123. else
  1124. {
  1125. Result += Terminal->ChangeFileName(&CopyParams, Path, osLocal, false);
  1126. Path = L"";
  1127. }
  1128. }
  1129. return Result;
  1130. }
  1131. //---------------------------------------------------------------------------
  1132. void __fastcall TScpCommanderForm::CreateRemoteDirectory(const UnicodeString & Path)
  1133. {
  1134. UnicodeString Dir = UnixExtractFileDir(Path);
  1135. if (!IsUnixRootPath(Dir) && !Terminal->FileExists(Dir))
  1136. {
  1137. CreateRemoteDirectory(Dir);
  1138. }
  1139. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  1140. TCustomScpExplorerForm::CreateRemoteDirectory(Path, Properties);
  1141. }
  1142. //---------------------------------------------------------------------------
  1143. void __fastcall TScpCommanderForm::SynchronizeBrowsingLocal(
  1144. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  1145. {
  1146. DebugAssert(!IsLocalBrowserMode());
  1147. Terminal->ExceptionOnFail = true;
  1148. TStrings * Paths = new TStringList();
  1149. try
  1150. {
  1151. Paths->Add(IncludeTrailingBackslash(PrevPath));
  1152. Paths->Add(IncludeTrailingBackslash(LocalDirView->Path));
  1153. UnicodeString CommonPath;
  1154. if (ExtractCommonPath(Paths, CommonPath))
  1155. {
  1156. PrevPath = IncludeTrailingBackslash(PrevPath);
  1157. CommonPath = IncludeTrailingBackslash(CommonPath);
  1158. NewPath = RemoteDirView->Path;
  1159. while (!SamePaths(PrevPath, CommonPath))
  1160. {
  1161. if (NewPath == UnixExcludeTrailingBackslash(NewPath))
  1162. {
  1163. Abort();
  1164. }
  1165. NewPath = UnixExtractFilePath(UnixExcludeTrailingBackslash(NewPath));
  1166. PrevPath = ExtractFilePath(ExcludeTrailingBackslash(PrevPath));
  1167. }
  1168. NewPath = UnixIncludeTrailingBackslash(NewPath) +
  1169. ToUnixPath(LocalDirView->Path.SubString(PrevPath.Length() + 1,
  1170. LocalDirView->Path.Length() - PrevPath.Length()));
  1171. }
  1172. else
  1173. {
  1174. Abort();
  1175. }
  1176. if (Create)
  1177. {
  1178. CreateRemoteDirectory(UnixExcludeTrailingBackslash(NewPath));
  1179. }
  1180. RemoteDirView->Path = NewPath;
  1181. }
  1182. __finally
  1183. {
  1184. Terminal->ExceptionOnFail = false;
  1185. delete Paths;
  1186. }
  1187. }
  1188. //---------------------------------------------------------------------------
  1189. void __fastcall TScpCommanderForm::CreateLocalDirectory(const UnicodeString & Path)
  1190. {
  1191. DebugAssert(!IsLocalBrowserMode()); // Used for synchronized browsing only
  1192. UnicodeString Dir = ExtractFileDir(Path);
  1193. if (!Dir.IsEmpty() && !DirectoryExists(Dir))
  1194. {
  1195. CreateLocalDirectory(Dir);
  1196. }
  1197. LocalDirView->CreateDirectory(Path);
  1198. }
  1199. //---------------------------------------------------------------------------
  1200. void __fastcall TScpCommanderForm::SynchronizeBrowsingRemote(
  1201. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  1202. {
  1203. TStrings * Paths = new TStringList();
  1204. try
  1205. {
  1206. Paths->Add(UnixIncludeTrailingBackslash(PrevPath));
  1207. Paths->Add(UnixIncludeTrailingBackslash(RemoteDirView->Path));
  1208. UnicodeString CommonPath;
  1209. if (UnixExtractCommonPath(Paths, CommonPath))
  1210. {
  1211. PrevPath = UnixIncludeTrailingBackslash(PrevPath);
  1212. CommonPath = UnixIncludeTrailingBackslash(CommonPath);
  1213. UnicodeString NewLocalPath;
  1214. NewPath = ExcludeTrailingBackslash(LocalDirView->Path);
  1215. while (!UnixSamePath(PrevPath, CommonPath))
  1216. {
  1217. NewLocalPath = ExcludeTrailingBackslash(ExtractFileDir(NewPath));
  1218. if (NewLocalPath == NewPath)
  1219. {
  1220. Abort();
  1221. }
  1222. NewPath = NewLocalPath;
  1223. PrevPath = UnixExtractFilePath(UnixExcludeTrailingBackslash(PrevPath));
  1224. }
  1225. NewPath = IncludeTrailingBackslash(NewPath) +
  1226. ChangeFilePath(
  1227. RemoteDirView->Path.SubString(PrevPath.Length() + 1,
  1228. RemoteDirView->Path.Length() - PrevPath.Length()),
  1229. osRemote);
  1230. }
  1231. else
  1232. {
  1233. Abort();
  1234. }
  1235. }
  1236. __finally
  1237. {
  1238. delete Paths;
  1239. }
  1240. if (Create)
  1241. {
  1242. CreateLocalDirectory(ExcludeTrailingBackslash(NewPath));
  1243. }
  1244. LocalDirView->Path = NewPath;
  1245. }
  1246. //---------------------------------------------------------------------------
  1247. void __fastcall TScpCommanderForm::SynchronizeBrowsing(TCustomDirView * ADirView,
  1248. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  1249. {
  1250. if (ADirView == LocalDirView)
  1251. {
  1252. SynchronizeBrowsingLocal(PrevPath, NewPath, Create);
  1253. }
  1254. else
  1255. {
  1256. SynchronizeBrowsingRemote(PrevPath, NewPath, Create);
  1257. }
  1258. }
  1259. //---------------------------------------------------------------------------
  1260. void __fastcall TScpCommanderForm::SynchronizeBrowsing(TCustomDirView * ADirView)
  1261. {
  1262. UnicodeString PrevPath;
  1263. // cannot assign to UnicodeString before the class is constructed,
  1264. // if we do, the value get lost when UnicodeString constructor gets finally called,
  1265. // what results in memory leak in the best case
  1266. if (FConstructed)
  1267. {
  1268. PrevPath = FPrevPath[ADirView == LocalDirView];
  1269. FPrevPath[ADirView == LocalDirView] = ADirView->Path;
  1270. }
  1271. if (!FSynchronisingBrowse && NonVisualDataModule->SynchronizeBrowsingAction2->Checked &&
  1272. !PrevPath.IsEmpty() && PrevPath != ADirView->Path)
  1273. {
  1274. DebugAssert(!IsLocalBrowserMode());
  1275. TValueRestorer<bool> AllowTransferPresetAutoSelectRestorer(FAllowTransferPresetAutoSelect);
  1276. FAllowTransferPresetAutoSelect = false;
  1277. TValueRestorer<bool> SynchronisingBrowseRestorer(FSynchronisingBrowse);
  1278. FSynchronisingBrowse = true;
  1279. try
  1280. {
  1281. UnicodeString NewPath;
  1282. bool Error = false;
  1283. std::unique_ptr<TStrings> ErrorMoreMessages;
  1284. UnicodeString ErrorHelpKeyword;
  1285. try
  1286. {
  1287. SynchronizeBrowsing(ADirView, PrevPath, NewPath, false);
  1288. }
  1289. // EAbort means that we do not know how to synchronize browsing
  1290. // there's no fallback scenario for that
  1291. catch(EAbort &)
  1292. {
  1293. throw;
  1294. }
  1295. catch(Exception & E)
  1296. {
  1297. // what does this say?
  1298. if (Application->Terminated)
  1299. {
  1300. throw;
  1301. }
  1302. else
  1303. {
  1304. Error = true;
  1305. ErrorMoreMessages.reset(ExceptionToMoreMessages(&E));
  1306. ErrorHelpKeyword =
  1307. MergeHelpKeyword(HELP_SYNC_DIR_BROWSE_ERROR, GetExceptionHelpKeyword(&E));
  1308. }
  1309. }
  1310. // this was moved here out of the above catch clause,
  1311. // to avoid deep nesting, what seems to cause some stray access violations
  1312. if (Error)
  1313. {
  1314. if (MoreMessageDialog(FMTLOAD(SYNC_DIR_BROWSE_CREATE2, (NewPath)),
  1315. ErrorMoreMessages.get(), qtConfirmation, qaYes | qaNo,
  1316. ErrorHelpKeyword) == qaYes)
  1317. {
  1318. try
  1319. {
  1320. SynchronizeBrowsing(ADirView, PrevPath, NewPath, true);
  1321. }
  1322. catch(Exception & E)
  1323. {
  1324. if (!Application->Terminated)
  1325. {
  1326. Terminal->ShowExtendedException(&E);
  1327. }
  1328. throw;
  1329. }
  1330. }
  1331. else
  1332. {
  1333. NonVisualDataModule->SynchronizeBrowsingAction2->Checked = false;
  1334. }
  1335. }
  1336. }
  1337. catch(Exception & E)
  1338. {
  1339. NonVisualDataModule->SynchronizeBrowsingAction2->Checked = false;
  1340. // what does this say?
  1341. if (Application->Terminated)
  1342. {
  1343. throw;
  1344. }
  1345. else
  1346. {
  1347. MessageDialog(LoadStr(SYNC_DIR_BROWSE_ERROR), qtInformation, qaOK,
  1348. HELP_SYNC_DIR_BROWSE_ERROR);
  1349. }
  1350. }
  1351. // note the value restorers at the beginning of this block
  1352. }
  1353. }
  1354. //---------------------------------------------------------------------------
  1355. void __fastcall TScpCommanderForm::DoDirViewLoaded(TCustomDirView * ADirView)
  1356. {
  1357. TCustomScpExplorerForm::DoDirViewLoaded(ADirView);
  1358. UpdateControls();
  1359. SynchronizeBrowsing(ADirView);
  1360. }
  1361. //---------------------------------------------------------------------------
  1362. void __fastcall TScpCommanderForm::AddEditLink(TOperationSide Side, bool Add)
  1363. {
  1364. if (IsSideLocalBrowser(Side))
  1365. {
  1366. bool Edit = false;
  1367. UnicodeString FileName;
  1368. UnicodeString PointTo;
  1369. bool SymbolicLink = true;
  1370. TDirView * ADirView = DebugNotNull(dynamic_cast<TDirView *>(DirView(Side)));
  1371. if (ADirView->ItemFocused != NULL)
  1372. {
  1373. DebugAssert(ADirView->ItemFocused->Data);
  1374. PFileRec FileRec = (PFileRec)ADirView->ItemFocused->Data;
  1375. Edit = !Add && (UpperCase(FileRec->FileExt) == L"LNK");
  1376. if (Edit)
  1377. {
  1378. UnicodeString FullName = ADirView->ItemFullFileName(ADirView->ItemFocused);
  1379. FileName = FullName;
  1380. PointTo = ResolveFileShortCut(FullName, false);
  1381. if (PointTo.IsEmpty())
  1382. {
  1383. throw Exception(FMTLOAD(RESOLVE_SHORTCUT_ERROR, (FullName)));
  1384. }
  1385. }
  1386. else
  1387. {
  1388. PointTo = FileRec->FileName;
  1389. }
  1390. }
  1391. if (DoSymlinkDialog(FileName, PointTo, osLocal, SymbolicLink, Edit, false))
  1392. {
  1393. Configuration->Usage->Inc(L"LocalShortcutsCreated");
  1394. DebugAssert(SymbolicLink);
  1395. DebugAssert(!FileName.IsEmpty());
  1396. DebugAssert(!PointTo.IsEmpty());
  1397. if (ExtractFileDrive(FileName) == L"" && FileName[1] != L'\\')
  1398. {
  1399. FileName = IncludeTrailingBackslash(ADirView->PathName) + FileName;
  1400. }
  1401. if (ExtractFileDrive(PointTo) == L"" && PointTo[1] != L'\\')
  1402. {
  1403. PointTo = IncludeTrailingBackslash(ADirView->PathName) + PointTo;
  1404. }
  1405. if (ExtractFileExt(FileName) == L"")
  1406. {
  1407. FileName = FileName + L".lnk";
  1408. }
  1409. if (Edit)
  1410. {
  1411. DeleteFileChecked(FileName);
  1412. }
  1413. if (!CreateFileShortCut(PointTo, FileName, L""))
  1414. {
  1415. throw Exception(CREATE_SHORTCUT_ERROR);
  1416. }
  1417. }
  1418. }
  1419. else
  1420. {
  1421. TCustomScpExplorerForm::AddEditLink(Side, Add);
  1422. }
  1423. }
  1424. //---------------------------------------------------------------------------
  1425. void __fastcall TScpCommanderForm::DoOpenDirectoryDialog(TOpenDirectoryMode Mode,
  1426. TOperationSide Side)
  1427. {
  1428. bool UseLocationProfiles;
  1429. do
  1430. {
  1431. UseLocationProfiles = WinConfiguration->UseLocationProfiles;
  1432. // Location profiles dialog is not ready to be run without terminal
  1433. if (UseLocationProfiles && (Terminal != NULL))
  1434. {
  1435. TStrings * LocalDirectories = NULL;
  1436. TStrings * RemoteDirectories = NULL;
  1437. try
  1438. {
  1439. LocalDirectories = CreateVisitedDirectories(osLocal);
  1440. RemoteDirectories = CreateVisitedDirectories(osRemote);
  1441. UnicodeString Local = LocalDirView->PathName;
  1442. UnicodeString Remote = RemoteDirView->PathName;
  1443. if (LocationProfilesDialog(Mode, Side, Local, Remote, LocalDirectories,
  1444. RemoteDirectories, Terminal))
  1445. {
  1446. DoOpenBookmark(Local, Remote);
  1447. }
  1448. }
  1449. __finally
  1450. {
  1451. delete LocalDirectories;
  1452. delete RemoteDirectories;
  1453. }
  1454. }
  1455. else
  1456. {
  1457. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1458. TCustomScpExplorerForm::DoOpenDirectoryDialog(Mode, Side);
  1459. }
  1460. // for second and further rounds, always do browse only
  1461. Mode = odBrowse;
  1462. }
  1463. while (UseLocationProfiles != WinConfiguration->UseLocationProfiles);
  1464. }
  1465. //---------------------------------------------------------------------------
  1466. void __fastcall TScpCommanderForm::DoOpenBookmark(UnicodeString Local, UnicodeString Remote)
  1467. {
  1468. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1469. // make sure that whatever path is valid it is opened first and only
  1470. // after that an eventual error is reported
  1471. try
  1472. {
  1473. if (!Local.IsEmpty())
  1474. {
  1475. LocalDirView->Path = Local;
  1476. }
  1477. }
  1478. __finally
  1479. {
  1480. if (!Remote.IsEmpty())
  1481. {
  1482. // While we might get here when the session is closed (from location profiles),
  1483. // it's not a problem as the Path setter is noop then
  1484. RemoteDirView->Path = Remote;
  1485. }
  1486. }
  1487. }
  1488. //---------------------------------------------------------------------------
  1489. bool __fastcall TScpCommanderForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  1490. {
  1491. bool Result;
  1492. if (WinConfiguration->UseLocationProfiles && !IsLocalBrowserMode())
  1493. {
  1494. DoOpenBookmark(Bookmark->Local, Bookmark->Remote);
  1495. Result = true;
  1496. }
  1497. else
  1498. {
  1499. Result = TCustomScpExplorerForm::OpenBookmark(Side, Bookmark);
  1500. }
  1501. return Result;
  1502. }
  1503. //---------------------------------------------------------------------------
  1504. void __fastcall TScpCommanderForm::LocalDirViewDDTargetHasDropHandler(
  1505. TObject * Sender, TListItem * Item, int & /*Effect*/, bool & DropHandler)
  1506. {
  1507. // When drop target is not directory, it is probably file type, which have
  1508. // associated drop handler (such as EXE file). In this case we
  1509. // cannot allow drop when when using shellex,
  1510. // as drop handlers are disabled, so drop would error
  1511. // (see TShellExtension.DropHandler assignment in ConfigurationChanged),
  1512. if (WinConfiguration->DDFakeFile &&
  1513. !DebugNotNull(dynamic_cast<TDirView *>(Sender))->ItemIsDirectory(Item))
  1514. {
  1515. DropHandler = false;
  1516. }
  1517. }
  1518. //---------------------------------------------------------------------------
  1519. bool __fastcall TScpCommanderForm::DDGetTarget(
  1520. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  1521. {
  1522. bool Result;
  1523. if (!FDDFakeFileTarget.IsEmpty())
  1524. {
  1525. Directory = FDDFakeFileTarget;
  1526. FDDFakeFileTarget = L"";
  1527. Result = true;
  1528. CounterName = L"DownloadsDragDropInternal";
  1529. ForceQueue = false;
  1530. }
  1531. else
  1532. {
  1533. Result = TCustomScpExplorerForm::DDGetTarget(Directory, ForceQueue, CounterName);
  1534. }
  1535. return Result;
  1536. }
  1537. //---------------------------------------------------------------------------
  1538. void __fastcall TScpCommanderForm::DDFakeFileInitDrag(TFileList * FileList,
  1539. bool & Created)
  1540. {
  1541. FDDFakeFileTarget = L"";
  1542. TCustomScpExplorerForm::DDFakeFileInitDrag(FileList, Created);
  1543. }
  1544. //---------------------------------------------------------------------------
  1545. void __fastcall TScpCommanderForm::LocalFileControlDDFileOperation(
  1546. TObject * /*Sender*/, int dwEffect, UnicodeString SourcePath,
  1547. UnicodeString TargetPath, bool Paste, bool & DoOperation)
  1548. {
  1549. if (IsFileControl(DropSourceControl, osRemote) && !IsLocalBrowserMode())
  1550. {
  1551. UnicodeString TargetDirectory;
  1552. if (InternalDDDownload(TargetDirectory))
  1553. {
  1554. // See TCustomScpExplorerForm::QueueDDProcessDropped
  1555. if (FDDExtMapFile != NULL)
  1556. {
  1557. FDDFakeFileTarget = TargetDirectory;
  1558. }
  1559. else
  1560. {
  1561. DebugAssert(FInternalDDDownloadList->Count > 0);
  1562. DebugAssert(dwEffect == DROPEFFECT_COPY || dwEffect == DROPEFFECT_MOVE);
  1563. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  1564. TTransferType TransferType = dwEffect == DROPEFFECT_COPY ? ttCopy : ttMove;
  1565. int Options =
  1566. FLAGMASK(DraggingAllFilesFromDirView(osRemote, FInternalDDDownloadList), coAllFiles);
  1567. bool NoConfirmation = Paste ? false : (WinConfiguration->DDTransferConfirmation == asOff);
  1568. if (CopyParamDialog(tdToLocal, TransferType,
  1569. false, FInternalDDDownloadList, TargetDirectory, CopyParams, NoConfirmation, true, Options))
  1570. {
  1571. int Params =
  1572. (TransferType == ttMove ? cpDelete : 0);
  1573. DDDownload(FInternalDDDownloadList, TargetDirectory,
  1574. &CopyParams, Params);
  1575. Configuration->Usage->Inc(L"DownloadsDragDropInternal");
  1576. FInternalDDDownloadList->Clear();
  1577. }
  1578. }
  1579. DoOperation = false;
  1580. }
  1581. }
  1582. }
  1583. //---------------------------------------------------------------------------
  1584. void __fastcall TScpCommanderForm::RemoteFileControlDDFileOperationExecuted(
  1585. TObject * /*Sender*/, int dwEffect, UnicodeString /*SourcePath*/,
  1586. UnicodeString /*TargetPath*/)
  1587. {
  1588. if ((dwEffect == DROPEFFECT_MOVE) &&
  1589. IsFileControl(DropSourceControl, osLocal))
  1590. {
  1591. ReloadLocalDirectory();
  1592. }
  1593. }
  1594. //---------------------------------------------------------------------------
  1595. void __fastcall TScpCommanderForm::LocalDirViewEnter(TObject * /*Sender*/)
  1596. {
  1597. SideEnter(osLocal);
  1598. }
  1599. //---------------------------------------------------------------------------
  1600. void __fastcall TScpCommanderForm::LocalDriveViewEnter(TObject * /*Sender*/)
  1601. {
  1602. MakeNextInTabOrder(LocalDirView, LocalDriveView);
  1603. SideEnter(osLocal);
  1604. }
  1605. //---------------------------------------------------------------------------
  1606. void __fastcall TScpCommanderForm::SideEnter(TOperationSide Side)
  1607. {
  1608. if (Visible && (IsSideLocalBrowser(FCurrentSide) != IsSideLocalBrowser(Side)))
  1609. {
  1610. // this may get called yet before controls are initialized
  1611. CommandLineCombo->Strings->Clear();
  1612. FCommandLineComboPopulated = false;
  1613. }
  1614. TCustomScpExplorerForm::SideEnter(Side);
  1615. if (Visible)
  1616. {
  1617. UpdateControls();
  1618. UpdatePanelsPathLabelsStatus();
  1619. }
  1620. }
  1621. //---------------------------------------------------------------------------
  1622. void __fastcall TScpCommanderForm::UpdatePanelsPathLabelsStatus()
  1623. {
  1624. // TODO_OTHER_LOCAL
  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. }