ScpCommander.cpp 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554
  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. bool HasTerminal = (Terminal != NULL);
  891. RemoteDirView->Visible = HasTerminal;
  892. RemoteDriveView->Visible = HasTerminal;
  893. OtherLocalDirView->Visible = !HasTerminal;
  894. OtherLocalDriveView->Visible = !HasTerminal;
  895. bool LocalOnLeft = (Panel(true) == LocalPanel);
  896. LocalMenuButton->Caption = LoadStr(HasTerminal ? LOCAL_MENU_CAPTION : (LocalOnLeft ? LEFT_MENU_CAPTION : RIGHT_MENU_CAPTION));
  897. RemoteMenuButton->Caption = LoadStr(HasTerminal ? REMOTE_MENU_CAPTION : (LocalOnLeft ? RIGHT_MENU_CAPTION : LEFT_MENU_CAPTION));
  898. if (DirViewWasFocused)
  899. {
  900. if (DirView(osOther)->Enabled)
  901. {
  902. DirView(osOther)->SetFocus();
  903. }
  904. else
  905. {
  906. LocalDirView->SetFocus();
  907. }
  908. }
  909. if (DriveViewWasFocused)
  910. {
  911. if (DriveView(osOther)->Enabled)
  912. {
  913. DriveView(osOther)->SetFocus();
  914. }
  915. else
  916. {
  917. LocalDriveView->SetFocus();
  918. }
  919. }
  920. if (RemotePathLabel->FocusControl != DirView(osOther))
  921. {
  922. if (DebugAlwaysTrue(RemotePathLabel->FocusControl != NULL))
  923. {
  924. dynamic_cast<TCustomDirView *>(RemotePathLabel->FocusControl)->PathLabel = NULL;
  925. }
  926. DirView(osOther)->PathLabel = RemotePathLabel;
  927. RemotePathLabel->UnixPath = !IsSideLocalBrowser(osOther);
  928. DirView(osOther)->UpdateStatusBar();
  929. }
  930. }
  931. //---------------------------------------------------------------------------
  932. void __fastcall TScpCommanderForm::ChangePath(TOperationSide Side)
  933. {
  934. DebugAssert((Side == osLocal) || (Side == osRemote));
  935. TTBXComboBoxItem * PathComboBox;
  936. if (Side == osLocal)
  937. {
  938. PathComboBox = LocalPathComboBox;
  939. }
  940. else
  941. {
  942. PathComboBox = RemotePathComboBox;
  943. }
  944. ClickToolbarItem(PathComboBox, false);
  945. }
  946. //---------------------------------------------------------------------------
  947. TControl * __fastcall TScpCommanderForm::GetComponent(Byte Component)
  948. {
  949. switch (Component) {
  950. case fcToolBar2: return Toolbar2Toolbar; // name changed to enforce change of default visibility
  951. case fcStatusBar: return StatusBar;
  952. case fcLocalStatusBar: return LocalStatusBar;
  953. case fcRemoteStatusBar: return RemoteStatusBar;
  954. case fcCommandLinePanel: return CommandLineToolbar;
  955. case fcLocalTree: return LocalDriveView;
  956. case fcSessionToolbar: return SessionToolbar;
  957. case fcCustomCommandsBand: return CustomCommandsToolbar;
  958. case fcColorMenu: return reinterpret_cast<TControl*>(ColorMenuItem);
  959. case fcTransferDropDown: return reinterpret_cast<TControl*>(TransferDropDown);
  960. case fcTransferList: return reinterpret_cast<TControl*>(TransferList);
  961. case fcTransferLabel: return reinterpret_cast<TControl*>(TransferLabel);
  962. case fcLocalPopup: return reinterpret_cast<TControl *>(NonVisualDataModule->LocalFilePopup);
  963. case fcRemotePathComboBox: return reinterpret_cast<TControl*>(RemotePathComboBox);
  964. case fcCommanderMenuBand: return MenuToolbar;
  965. case fcCommanderSessionBand: return SessionToolbar;
  966. case fcCommanderPreferencesBand: return PreferencesToolbar;
  967. case fcCommanderSortBand: return SortToolbar;
  968. case fcCommanderCommandsBand: return CommandsToolbar;
  969. case fcCommanderUpdatesBand: return UpdatesToolbar;
  970. case fcCommanderTransferBand: return TransferToolbar;
  971. case fcCommanderCustomCommandsBand: return CustomCommandsToolbar;
  972. case fcCommanderLocalHistoryBand: return LocalHistoryToolbar;
  973. case fcCommanderLocalNavigationBand: return LocalNavigationToolbar;
  974. case fcCommanderLocalFileBand: return LocalFileToolbar;
  975. case fcCommanderLocalSelectionBand: return LocalSelectionToolbar;
  976. case fcCommanderRemoteHistoryBand: return RemoteHistoryToolbar;
  977. case fcCommanderRemoteNavigationBand: return RemoteNavigationToolbar;
  978. case fcCommanderRemoteFileBand: return RemoteFileToolbar;
  979. case fcCommanderRemoteSelectionBand: return RemoteSelectionToolbar;
  980. default: return TCustomScpExplorerForm::GetComponent(Component);
  981. }
  982. }
  983. //---------------------------------------------------------------------------
  984. void __fastcall TScpCommanderForm::FixControlsPlacement()
  985. {
  986. TCustomScpExplorerForm::FixControlsPlacement();
  987. QueueSeparatorPanel->Visible = QueuePanel->Visible;
  988. LocalPanelSplitter->Visible = LocalDriveView->Visible;
  989. TControl * ControlsOrder[] =
  990. { BottomDock, QueueSeparatorPanel, QueueSplitter, QueuePanel, StatusBar };
  991. SetVerticalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  992. TControl * LocalControlsOrder[] =
  993. { LocalTopDock, LocalPathLabel, LocalDriveView, LocalPanelSplitter,
  994. LocalDirView, LocalBottomDock, LocalStatusBar };
  995. SetVerticalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  996. SetHorizontalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  997. TControl * RemoteControlsOrder[] =
  998. { RemoteTopDock, RemotePathLabel, RemoteDrivePanel, RemotePanelSplitter,
  999. RemoteDirPanel, RemoteBottomDock, RemoteStatusBar };
  1000. SetVerticalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  1001. SetHorizontalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  1002. MakeFocusedItemVisible(LocalDirView);
  1003. MakeFocusedItemVisible(OtherLocalDirView);
  1004. }
  1005. //---------------------------------------------------------------------------
  1006. bool __fastcall TScpCommanderForm::GetHasDirView(TOperationSide Side)
  1007. {
  1008. return TCustomScpExplorerForm::GetHasDirView(Side) || (Side == osLocal);
  1009. }
  1010. //---------------------------------------------------------------------------
  1011. void __fastcall TScpCommanderForm::CompareDirectories()
  1012. {
  1013. LocalDirView->CompareFiles(DirView(osOther), false,
  1014. WinConfiguration->ScpCommander.CompareCriterias());
  1015. DirView(osOther)->CompareFiles(LocalDirView, false,
  1016. WinConfiguration->ScpCommander.CompareCriterias());
  1017. if (LocalDirView->SelCount + DirView(osOther)->SelCount == 0)
  1018. {
  1019. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  1020. MessageDialog(Message, qtInformation, qaOK, HELP_COMPARE_NO_DIFFERENCES);
  1021. }
  1022. }
  1023. //---------------------------------------------------------------------------
  1024. void __fastcall TScpCommanderForm::SynchronizeDirectories()
  1025. {
  1026. DebugAssert(!IsLocalBrowserMode());
  1027. UnicodeString LocalDirectory = LocalDirView->PathName;
  1028. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  1029. DoSynchronizeDirectories(LocalDirectory, RemoteDirectory, -1);
  1030. }
  1031. //---------------------------------------------------------------------------
  1032. void __fastcall TScpCommanderForm::FullSynchronizeDirectories()
  1033. {
  1034. DebugAssert(!IsLocalBrowserMode());
  1035. UnicodeString LocalDirectory = LocalDirView->PathName;
  1036. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  1037. bool SaveMode = !(GUIConfiguration->SynchronizeModeAuto < 0);
  1038. TSynchronizeMode Mode =
  1039. (SaveMode ? (TSynchronizeMode)GUIConfiguration->SynchronizeModeAuto :
  1040. ((FCurrentSide == osLocal) ? smRemote : smLocal));
  1041. int Params = GUIConfiguration->SynchronizeParams;
  1042. if (DoFullSynchronizeDirectories(LocalDirectory, RemoteDirectory, Mode, Params, SaveMode, -1) >= 0)
  1043. {
  1044. if (SaveMode)
  1045. {
  1046. GUIConfiguration->SynchronizeModeAuto = Mode;
  1047. }
  1048. }
  1049. }
  1050. //---------------------------------------------------------------------------
  1051. void __fastcall TScpCommanderForm::ExploreLocalDirectory(TOperationSide Side)
  1052. {
  1053. DebugAssert(IsSideLocalBrowser(Side));
  1054. OpenFolderInExplorer(DirView(Side)->Path);
  1055. }
  1056. //---------------------------------------------------------------------------
  1057. void __fastcall TScpCommanderForm::LocalDirViewExecFile(TObject *Sender,
  1058. TListItem *Item, bool &AllowExec)
  1059. {
  1060. DebugAssert(Item);
  1061. TDirView * ADirView = DebugNotNull(dynamic_cast<TDirView *>(Sender));
  1062. if ((UpperCase(PFileRec(Item->Data)->FileExt) == L"LNK") &&
  1063. DirectoryExists(ApiPath(ResolveFileShortCut(ADirView->ItemFullFileName(Item), true))))
  1064. {
  1065. AllowExec = true;
  1066. }
  1067. else
  1068. {
  1069. DoDirViewExecFile(Sender, Item, AllowExec);
  1070. }
  1071. }
  1072. //---------------------------------------------------------------------------
  1073. void __fastcall TScpCommanderForm::LocalFileControlDDDragEnter(TObject *Sender,
  1074. IDataObject *DataObj, int grfKeyState, TPoint &Point, int &dwEffect,
  1075. bool &Accept)
  1076. {
  1077. // LocalDirViewDDDragEnter is duplication of
  1078. // TCustomScpExplorerForm::DirViewDDDragEnter, but it differs in
  1079. // literal type of 'DataObj' parameter.Actual type is however same
  1080. FileControlDDDragEnter(Sender, DataObj, grfKeyState, Point, dwEffect, Accept);
  1081. }
  1082. //---------------------------------------------------------------------------
  1083. bool __fastcall TScpCommanderForm::PanelOperation(TOperationSide Side,
  1084. bool DragDrop)
  1085. {
  1086. // TODO
  1087. return TCustomScpExplorerForm::PanelOperation(Side, DragDrop) ||
  1088. (DropSourceControl == LocalDirView);
  1089. }
  1090. //---------------------------------------------------------------------------
  1091. void __fastcall TScpCommanderForm::FileOperationProgress(
  1092. TFileOperationProgressType & ProgressData)
  1093. {
  1094. // Heuristic: When operation finishes and DD targed is local dir view,
  1095. // we suppose that drag&drop download finished, so local dir view should be
  1096. // reloaded
  1097. // TODO
  1098. if (!ProgressData.InProgress && FProgressForm &&
  1099. IsFileControl(FDDTargetControl, osLocal) &&
  1100. ((ProgressData.Operation == ::foCopy) || (ProgressData.Operation == ::foMove)))
  1101. {
  1102. ReloadLocalDirectory();
  1103. }
  1104. TCustomScpExplorerForm::FileOperationProgress(ProgressData);
  1105. }
  1106. //---------------------------------------------------------------------------
  1107. UnicodeString __fastcall TScpCommanderForm::ChangeFilePath(UnicodeString Path, TOperationSide Side)
  1108. {
  1109. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  1110. UnicodeString Result;
  1111. while (!Path.IsEmpty())
  1112. {
  1113. int P = Path.Pos(Side == osLocal ? L'\\' : L'/');
  1114. if (P > 0)
  1115. {
  1116. Result += Terminal->ChangeFileName(&CopyParams, Path.SubString(1, P - 1), Side, false) +
  1117. (Side == osLocal ? L'/' : L'\\');
  1118. Path.Delete(1, P);
  1119. }
  1120. else
  1121. {
  1122. Result += Terminal->ChangeFileName(&CopyParams, Path, osLocal, false);
  1123. Path = L"";
  1124. }
  1125. }
  1126. return Result;
  1127. }
  1128. //---------------------------------------------------------------------------
  1129. void __fastcall TScpCommanderForm::CreateRemoteDirectory(const UnicodeString & Path)
  1130. {
  1131. UnicodeString Dir = UnixExtractFileDir(Path);
  1132. if (!IsUnixRootPath(Dir) && !Terminal->FileExists(Dir))
  1133. {
  1134. CreateRemoteDirectory(Dir);
  1135. }
  1136. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  1137. TCustomScpExplorerForm::CreateRemoteDirectory(Path, Properties);
  1138. }
  1139. //---------------------------------------------------------------------------
  1140. void __fastcall TScpCommanderForm::SynchronizeBrowsingLocal(
  1141. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  1142. {
  1143. DebugAssert(!IsLocalBrowserMode());
  1144. Terminal->ExceptionOnFail = true;
  1145. TStrings * Paths = new TStringList();
  1146. try
  1147. {
  1148. Paths->Add(IncludeTrailingBackslash(PrevPath));
  1149. Paths->Add(IncludeTrailingBackslash(LocalDirView->Path));
  1150. UnicodeString CommonPath;
  1151. if (ExtractCommonPath(Paths, CommonPath))
  1152. {
  1153. PrevPath = IncludeTrailingBackslash(PrevPath);
  1154. CommonPath = IncludeTrailingBackslash(CommonPath);
  1155. NewPath = RemoteDirView->Path;
  1156. while (!SamePaths(PrevPath, CommonPath))
  1157. {
  1158. if (NewPath == UnixExcludeTrailingBackslash(NewPath))
  1159. {
  1160. Abort();
  1161. }
  1162. NewPath = UnixExtractFilePath(UnixExcludeTrailingBackslash(NewPath));
  1163. PrevPath = ExtractFilePath(ExcludeTrailingBackslash(PrevPath));
  1164. }
  1165. NewPath = UnixIncludeTrailingBackslash(NewPath) +
  1166. ToUnixPath(LocalDirView->Path.SubString(PrevPath.Length() + 1,
  1167. LocalDirView->Path.Length() - PrevPath.Length()));
  1168. }
  1169. else
  1170. {
  1171. Abort();
  1172. }
  1173. if (Create)
  1174. {
  1175. CreateRemoteDirectory(UnixExcludeTrailingBackslash(NewPath));
  1176. }
  1177. RemoteDirView->Path = NewPath;
  1178. }
  1179. __finally
  1180. {
  1181. Terminal->ExceptionOnFail = false;
  1182. delete Paths;
  1183. }
  1184. }
  1185. //---------------------------------------------------------------------------
  1186. void __fastcall TScpCommanderForm::CreateLocalDirectory(const UnicodeString & Path)
  1187. {
  1188. DebugAssert(!IsLocalBrowserMode()); // Used for synchronized browsing only
  1189. UnicodeString Dir = ExtractFileDir(Path);
  1190. if (!Dir.IsEmpty() && !DirectoryExists(Dir))
  1191. {
  1192. CreateLocalDirectory(Dir);
  1193. }
  1194. LocalDirView->CreateDirectory(Path);
  1195. }
  1196. //---------------------------------------------------------------------------
  1197. void __fastcall TScpCommanderForm::SynchronizeBrowsingRemote(
  1198. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  1199. {
  1200. TStrings * Paths = new TStringList();
  1201. try
  1202. {
  1203. Paths->Add(UnixIncludeTrailingBackslash(PrevPath));
  1204. Paths->Add(UnixIncludeTrailingBackslash(RemoteDirView->Path));
  1205. UnicodeString CommonPath;
  1206. if (UnixExtractCommonPath(Paths, CommonPath))
  1207. {
  1208. PrevPath = UnixIncludeTrailingBackslash(PrevPath);
  1209. CommonPath = UnixIncludeTrailingBackslash(CommonPath);
  1210. UnicodeString NewLocalPath;
  1211. NewPath = ExcludeTrailingBackslash(LocalDirView->Path);
  1212. while (!UnixSamePath(PrevPath, CommonPath))
  1213. {
  1214. NewLocalPath = ExcludeTrailingBackslash(ExtractFileDir(NewPath));
  1215. if (NewLocalPath == NewPath)
  1216. {
  1217. Abort();
  1218. }
  1219. NewPath = NewLocalPath;
  1220. PrevPath = UnixExtractFilePath(UnixExcludeTrailingBackslash(PrevPath));
  1221. }
  1222. NewPath = IncludeTrailingBackslash(NewPath) +
  1223. ChangeFilePath(
  1224. RemoteDirView->Path.SubString(PrevPath.Length() + 1,
  1225. RemoteDirView->Path.Length() - PrevPath.Length()),
  1226. osRemote);
  1227. }
  1228. else
  1229. {
  1230. Abort();
  1231. }
  1232. }
  1233. __finally
  1234. {
  1235. delete Paths;
  1236. }
  1237. if (Create)
  1238. {
  1239. CreateLocalDirectory(ExcludeTrailingBackslash(NewPath));
  1240. }
  1241. LocalDirView->Path = NewPath;
  1242. }
  1243. //---------------------------------------------------------------------------
  1244. void __fastcall TScpCommanderForm::SynchronizeBrowsing(TCustomDirView * ADirView,
  1245. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  1246. {
  1247. if (ADirView == LocalDirView)
  1248. {
  1249. SynchronizeBrowsingLocal(PrevPath, NewPath, Create);
  1250. }
  1251. else
  1252. {
  1253. SynchronizeBrowsingRemote(PrevPath, NewPath, Create);
  1254. }
  1255. }
  1256. //---------------------------------------------------------------------------
  1257. void __fastcall TScpCommanderForm::SynchronizeBrowsing(TCustomDirView * ADirView)
  1258. {
  1259. UnicodeString PrevPath;
  1260. // cannot assign to UnicodeString before the class is constructed,
  1261. // if we do, the value get lost when UnicodeString constructor gets finally called,
  1262. // what results in memory leak in the best case
  1263. if (FConstructed)
  1264. {
  1265. PrevPath = FPrevPath[ADirView == LocalDirView];
  1266. FPrevPath[ADirView == LocalDirView] = ADirView->Path;
  1267. }
  1268. if (!FSynchronisingBrowse && NonVisualDataModule->SynchronizeBrowsingAction2->Checked &&
  1269. !PrevPath.IsEmpty() && PrevPath != ADirView->Path)
  1270. {
  1271. DebugAssert(!IsLocalBrowserMode());
  1272. TValueRestorer<bool> AllowTransferPresetAutoSelectRestorer(FAllowTransferPresetAutoSelect);
  1273. FAllowTransferPresetAutoSelect = false;
  1274. TValueRestorer<bool> SynchronisingBrowseRestorer(FSynchronisingBrowse);
  1275. FSynchronisingBrowse = true;
  1276. try
  1277. {
  1278. UnicodeString NewPath;
  1279. bool Error = false;
  1280. std::unique_ptr<TStrings> ErrorMoreMessages;
  1281. UnicodeString ErrorHelpKeyword;
  1282. try
  1283. {
  1284. SynchronizeBrowsing(ADirView, PrevPath, NewPath, false);
  1285. }
  1286. // EAbort means that we do not know how to synchronize browsing
  1287. // there's no fallback scenario for that
  1288. catch(EAbort &)
  1289. {
  1290. throw;
  1291. }
  1292. catch(Exception & E)
  1293. {
  1294. // what does this say?
  1295. if (Application->Terminated)
  1296. {
  1297. throw;
  1298. }
  1299. else
  1300. {
  1301. Error = true;
  1302. ErrorMoreMessages.reset(ExceptionToMoreMessages(&E));
  1303. ErrorHelpKeyword =
  1304. MergeHelpKeyword(HELP_SYNC_DIR_BROWSE_ERROR, GetExceptionHelpKeyword(&E));
  1305. }
  1306. }
  1307. // this was moved here out of the above catch clause,
  1308. // to avoid deep nesting, what seems to cause some stray access violations
  1309. if (Error)
  1310. {
  1311. if (MoreMessageDialog(FMTLOAD(SYNC_DIR_BROWSE_CREATE2, (NewPath)),
  1312. ErrorMoreMessages.get(), qtConfirmation, qaYes | qaNo,
  1313. ErrorHelpKeyword) == qaYes)
  1314. {
  1315. try
  1316. {
  1317. SynchronizeBrowsing(ADirView, PrevPath, NewPath, true);
  1318. }
  1319. catch(Exception & E)
  1320. {
  1321. if (!Application->Terminated)
  1322. {
  1323. Terminal->ShowExtendedException(&E);
  1324. }
  1325. throw;
  1326. }
  1327. }
  1328. else
  1329. {
  1330. NonVisualDataModule->SynchronizeBrowsingAction2->Checked = false;
  1331. }
  1332. }
  1333. }
  1334. catch(Exception & E)
  1335. {
  1336. NonVisualDataModule->SynchronizeBrowsingAction2->Checked = false;
  1337. // what does this say?
  1338. if (Application->Terminated)
  1339. {
  1340. throw;
  1341. }
  1342. else
  1343. {
  1344. MessageDialog(LoadStr(SYNC_DIR_BROWSE_ERROR), qtInformation, qaOK,
  1345. HELP_SYNC_DIR_BROWSE_ERROR);
  1346. }
  1347. }
  1348. // note the value restorers at the beginning of this block
  1349. }
  1350. }
  1351. //---------------------------------------------------------------------------
  1352. void __fastcall TScpCommanderForm::DoDirViewLoaded(TCustomDirView * ADirView)
  1353. {
  1354. TCustomScpExplorerForm::DoDirViewLoaded(ADirView);
  1355. UpdateControls();
  1356. SynchronizeBrowsing(ADirView);
  1357. }
  1358. //---------------------------------------------------------------------------
  1359. void __fastcall TScpCommanderForm::AddEditLink(TOperationSide Side, bool Add)
  1360. {
  1361. if (IsSideLocalBrowser(Side))
  1362. {
  1363. bool Edit = false;
  1364. UnicodeString FileName;
  1365. UnicodeString PointTo;
  1366. bool SymbolicLink = true;
  1367. TDirView * ADirView = DebugNotNull(dynamic_cast<TDirView *>(DirView(Side)));
  1368. if (ADirView->ItemFocused != NULL)
  1369. {
  1370. DebugAssert(ADirView->ItemFocused->Data);
  1371. PFileRec FileRec = (PFileRec)ADirView->ItemFocused->Data;
  1372. Edit = !Add && (UpperCase(FileRec->FileExt) == L"LNK");
  1373. if (Edit)
  1374. {
  1375. UnicodeString FullName = ADirView->ItemFullFileName(ADirView->ItemFocused);
  1376. FileName = FullName;
  1377. PointTo = ResolveFileShortCut(FullName, false);
  1378. if (PointTo.IsEmpty())
  1379. {
  1380. throw Exception(FMTLOAD(RESOLVE_SHORTCUT_ERROR, (FullName)));
  1381. }
  1382. }
  1383. else
  1384. {
  1385. PointTo = FileRec->FileName;
  1386. }
  1387. }
  1388. if (DoSymlinkDialog(FileName, PointTo, osLocal, SymbolicLink, Edit, false))
  1389. {
  1390. Configuration->Usage->Inc(L"LocalShortcutsCreated");
  1391. DebugAssert(SymbolicLink);
  1392. DebugAssert(!FileName.IsEmpty());
  1393. DebugAssert(!PointTo.IsEmpty());
  1394. if (ExtractFileDrive(FileName) == L"" && FileName[1] != L'\\')
  1395. {
  1396. FileName = IncludeTrailingBackslash(ADirView->PathName) + FileName;
  1397. }
  1398. if (ExtractFileDrive(PointTo) == L"" && PointTo[1] != L'\\')
  1399. {
  1400. PointTo = IncludeTrailingBackslash(ADirView->PathName) + PointTo;
  1401. }
  1402. if (ExtractFileExt(FileName) == L"")
  1403. {
  1404. FileName = FileName + L".lnk";
  1405. }
  1406. if (Edit)
  1407. {
  1408. DeleteFileChecked(FileName);
  1409. }
  1410. if (!CreateFileShortCut(PointTo, FileName, L""))
  1411. {
  1412. throw Exception(CREATE_SHORTCUT_ERROR);
  1413. }
  1414. }
  1415. }
  1416. else
  1417. {
  1418. TCustomScpExplorerForm::AddEditLink(Side, Add);
  1419. }
  1420. }
  1421. //---------------------------------------------------------------------------
  1422. void __fastcall TScpCommanderForm::DoOpenDirectoryDialog(TOpenDirectoryMode Mode,
  1423. TOperationSide Side)
  1424. {
  1425. bool UseLocationProfiles;
  1426. do
  1427. {
  1428. UseLocationProfiles = WinConfiguration->UseLocationProfiles;
  1429. // Location profiles dialog is not ready to be run without terminal
  1430. if (UseLocationProfiles && (Terminal != NULL))
  1431. {
  1432. TStrings * LocalDirectories = NULL;
  1433. TStrings * RemoteDirectories = NULL;
  1434. try
  1435. {
  1436. LocalDirectories = CreateVisitedDirectories(osLocal);
  1437. RemoteDirectories = CreateVisitedDirectories(osRemote);
  1438. UnicodeString Local = LocalDirView->PathName;
  1439. UnicodeString Remote = RemoteDirView->PathName;
  1440. if (LocationProfilesDialog(Mode, Side, Local, Remote, LocalDirectories,
  1441. RemoteDirectories, Terminal))
  1442. {
  1443. DoOpenBookmark(Local, Remote);
  1444. }
  1445. }
  1446. __finally
  1447. {
  1448. delete LocalDirectories;
  1449. delete RemoteDirectories;
  1450. }
  1451. }
  1452. else
  1453. {
  1454. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1455. TCustomScpExplorerForm::DoOpenDirectoryDialog(Mode, Side);
  1456. }
  1457. // for second and further rounds, always do browse only
  1458. Mode = odBrowse;
  1459. }
  1460. while (UseLocationProfiles != WinConfiguration->UseLocationProfiles);
  1461. }
  1462. //---------------------------------------------------------------------------
  1463. void __fastcall TScpCommanderForm::DoOpenBookmark(UnicodeString Local, UnicodeString Remote)
  1464. {
  1465. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1466. // make sure that whatever path is valid it is opened first and only
  1467. // after that an eventual error is reported
  1468. try
  1469. {
  1470. if (!Local.IsEmpty())
  1471. {
  1472. LocalDirView->Path = Local;
  1473. }
  1474. }
  1475. __finally
  1476. {
  1477. if (!Remote.IsEmpty())
  1478. {
  1479. // While we might get here when the session is closed (from location profiles),
  1480. // it's not a problem as the Path setter is noop then
  1481. RemoteDirView->Path = Remote;
  1482. }
  1483. }
  1484. }
  1485. //---------------------------------------------------------------------------
  1486. bool __fastcall TScpCommanderForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  1487. {
  1488. bool Result;
  1489. if (WinConfiguration->UseLocationProfiles && !IsLocalBrowserMode())
  1490. {
  1491. DoOpenBookmark(Bookmark->Local, Bookmark->Remote);
  1492. Result = true;
  1493. }
  1494. else
  1495. {
  1496. Result = TCustomScpExplorerForm::OpenBookmark(Side, Bookmark);
  1497. }
  1498. return Result;
  1499. }
  1500. //---------------------------------------------------------------------------
  1501. void __fastcall TScpCommanderForm::LocalDirViewDDTargetHasDropHandler(
  1502. TObject * Sender, TListItem * Item, int & /*Effect*/, bool & DropHandler)
  1503. {
  1504. // When drop target is not directory, it is probably file type, which have
  1505. // associated drop handler (such as EXE file). In this case we
  1506. // cannot allow drop when when using shellex,
  1507. // as drop handlers are disabled, so drop would error
  1508. // (see TShellExtension.DropHandler assignment in ConfigurationChanged),
  1509. if (WinConfiguration->DDFakeFile &&
  1510. !DebugNotNull(dynamic_cast<TDirView *>(Sender))->ItemIsDirectory(Item))
  1511. {
  1512. DropHandler = false;
  1513. }
  1514. }
  1515. //---------------------------------------------------------------------------
  1516. bool __fastcall TScpCommanderForm::DDGetTarget(
  1517. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  1518. {
  1519. bool Result;
  1520. if (!FDDFakeFileTarget.IsEmpty())
  1521. {
  1522. Directory = FDDFakeFileTarget;
  1523. FDDFakeFileTarget = L"";
  1524. Result = true;
  1525. CounterName = L"DownloadsDragDropInternal";
  1526. ForceQueue = false;
  1527. }
  1528. else
  1529. {
  1530. Result = TCustomScpExplorerForm::DDGetTarget(Directory, ForceQueue, CounterName);
  1531. }
  1532. return Result;
  1533. }
  1534. //---------------------------------------------------------------------------
  1535. void __fastcall TScpCommanderForm::DDFakeFileInitDrag(TFileList * FileList,
  1536. bool & Created)
  1537. {
  1538. FDDFakeFileTarget = L"";
  1539. TCustomScpExplorerForm::DDFakeFileInitDrag(FileList, Created);
  1540. }
  1541. //---------------------------------------------------------------------------
  1542. void __fastcall TScpCommanderForm::LocalFileControlDDFileOperation(
  1543. TObject * /*Sender*/, int dwEffect, UnicodeString SourcePath,
  1544. UnicodeString TargetPath, bool Paste, bool & DoOperation)
  1545. {
  1546. if (IsFileControl(DropSourceControl, osRemote) && !IsLocalBrowserMode())
  1547. {
  1548. UnicodeString TargetDirectory;
  1549. if (InternalDDDownload(TargetDirectory))
  1550. {
  1551. // See TCustomScpExplorerForm::QueueDDProcessDropped
  1552. if (FDDExtMapFile != NULL)
  1553. {
  1554. FDDFakeFileTarget = TargetDirectory;
  1555. }
  1556. else
  1557. {
  1558. DebugAssert(FInternalDDDownloadList->Count > 0);
  1559. DebugAssert(dwEffect == DROPEFFECT_COPY || dwEffect == DROPEFFECT_MOVE);
  1560. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  1561. TTransferType TransferType = dwEffect == DROPEFFECT_COPY ? ttCopy : ttMove;
  1562. int Options =
  1563. FLAGMASK(DraggingAllFilesFromDirView(osRemote, FInternalDDDownloadList), coAllFiles);
  1564. bool NoConfirmation = Paste ? false : (WinConfiguration->DDTransferConfirmation == asOff);
  1565. if (CopyParamDialog(tdToLocal, TransferType,
  1566. false, FInternalDDDownloadList, TargetDirectory, CopyParams, NoConfirmation, true, Options))
  1567. {
  1568. int Params =
  1569. (TransferType == ttMove ? cpDelete : 0);
  1570. DDDownload(FInternalDDDownloadList, TargetDirectory,
  1571. &CopyParams, Params);
  1572. Configuration->Usage->Inc(L"DownloadsDragDropInternal");
  1573. FInternalDDDownloadList->Clear();
  1574. }
  1575. }
  1576. DoOperation = false;
  1577. }
  1578. }
  1579. }
  1580. //---------------------------------------------------------------------------
  1581. void __fastcall TScpCommanderForm::RemoteFileControlDDFileOperationExecuted(
  1582. TObject * /*Sender*/, int dwEffect, UnicodeString /*SourcePath*/,
  1583. UnicodeString /*TargetPath*/)
  1584. {
  1585. if ((dwEffect == DROPEFFECT_MOVE) &&
  1586. IsFileControl(DropSourceControl, osLocal))
  1587. {
  1588. ReloadLocalDirectory();
  1589. }
  1590. }
  1591. //---------------------------------------------------------------------------
  1592. void __fastcall TScpCommanderForm::LocalDirViewEnter(TObject * /*Sender*/)
  1593. {
  1594. SideEnter(osLocal);
  1595. }
  1596. //---------------------------------------------------------------------------
  1597. void __fastcall TScpCommanderForm::LocalDriveViewEnter(TObject * /*Sender*/)
  1598. {
  1599. MakeNextInTabOrder(LocalDirView, LocalDriveView);
  1600. SideEnter(osLocal);
  1601. }
  1602. //---------------------------------------------------------------------------
  1603. void __fastcall TScpCommanderForm::SideEnter(TOperationSide Side)
  1604. {
  1605. if (Visible && (IsSideLocalBrowser(FCurrentSide) != IsSideLocalBrowser(Side)))
  1606. {
  1607. // this may get called yet before controls are initialized
  1608. CommandLineCombo->Strings->Clear();
  1609. FCommandLineComboPopulated = false;
  1610. }
  1611. TCustomScpExplorerForm::SideEnter(Side);
  1612. if (Visible)
  1613. {
  1614. UpdateControls();
  1615. UpdatePanelsPathLabelsStatus();
  1616. }
  1617. }
  1618. //---------------------------------------------------------------------------
  1619. void __fastcall TScpCommanderForm::UpdatePanelsPathLabelsStatus()
  1620. {
  1621. // TODO_OTHER_LOCAL
  1622. LocalPathLabel->UpdateStatus();
  1623. RemotePathLabel->UpdateStatus();
  1624. }
  1625. //---------------------------------------------------------------------------
  1626. void __fastcall TScpCommanderForm::OpenConsole(UnicodeString Command)
  1627. {
  1628. SaveCommandLine();
  1629. try
  1630. {
  1631. TCustomScpExplorerForm::OpenConsole(Command);
  1632. }
  1633. __finally
  1634. {
  1635. FCommandLineComboPopulated = false;
  1636. }
  1637. }
  1638. //---------------------------------------------------------------------------
  1639. void __fastcall TScpCommanderForm::SaveCommandLine()
  1640. {
  1641. if (FCommandLineComboPopulated)
  1642. {
  1643. CustomWinConfiguration->History[
  1644. !IsSideLocalBrowser(FCurrentSide) ? L"Commands" : L"LocalCommands"] =
  1645. CommandLineCombo->Strings;
  1646. }
  1647. }
  1648. //---------------------------------------------------------------------------
  1649. bool __fastcall TScpCommanderForm::ExecuteCommandLine()
  1650. {
  1651. UnicodeString Command = CommandLineCombo->Text;
  1652. bool Result =
  1653. !NonVisualDataModule->Busy &&
  1654. !Command.IsEmpty() &&
  1655. (IsSideLocalBrowser(FCurrentSide) ||
  1656. (Terminal->AllowedAnyCommand(Command) &&
  1657. EnsureCommandSessionFallback(fcAnyCommand)));
  1658. if (Result)
  1659. {
  1660. CommandLinePopulate();
  1661. SaveToHistory(CommandLineCombo->Strings, Command);
  1662. CommandLineCombo->Text = L"";
  1663. if (!IsSideLocalBrowser(FCurrentSide))
  1664. {
  1665. OpenConsole(Command);
  1666. }
  1667. else
  1668. {
  1669. ExecuteShellChecked(Command);
  1670. }
  1671. }
  1672. return Result;
  1673. }
  1674. //---------------------------------------------------------------------------
  1675. void __fastcall TScpCommanderForm::CommandLinePopulate()
  1676. {
  1677. if (!FCommandLineComboPopulated)
  1678. {
  1679. TStrings * CommandsHistory;
  1680. CommandsHistory = CustomWinConfiguration->History[
  1681. !IsSideLocalBrowser(FCurrentSide) ? L"Commands" : L"LocalCommands"];
  1682. if ((CommandsHistory != NULL) && (CommandsHistory->Count > 0))
  1683. {
  1684. CommandLineCombo->Strings = CommandsHistory;
  1685. }
  1686. else
  1687. {
  1688. CommandLineCombo->Strings->Clear();
  1689. }
  1690. FCommandLineComboPopulated = true;
  1691. }
  1692. }
  1693. //---------------------------------------------------------------------------
  1694. void __fastcall TScpCommanderForm::GoToCommandLine()
  1695. {
  1696. ComponentVisible[fcCommandLinePanel] = true;
  1697. if (CommandLineCombo->Enabled)
  1698. {
  1699. ClickToolbarItem(CommandLineCombo, true);
  1700. }
  1701. }
  1702. //---------------------------------------------------------------------------
  1703. void __fastcall TScpCommanderForm::GoToTree()
  1704. {
  1705. if (FCurrentSide == osLocal)
  1706. {
  1707. ComponentVisible[fcLocalTree] = true;
  1708. LocalDriveView->SetFocus();
  1709. }
  1710. else
  1711. {
  1712. TCustomScpExplorerForm::GoToTree();
  1713. }
  1714. }
  1715. //---------------------------------------------------------------------------
  1716. void __fastcall TScpCommanderForm::PanelExportStore(TOperationSide Side,
  1717. TPanelExport Export, TPanelExportDestination Destination,
  1718. TStrings * ExportData)
  1719. {
  1720. if (Destination == pedCommandLine)
  1721. {
  1722. ComponentVisible[fcCommandLinePanel] = true;
  1723. UnicodeString Buf;
  1724. for (int Index = 0; Index < ExportData->Count; Index++)
  1725. {
  1726. Buf += ExportData->Strings[Index] + L" ";
  1727. }
  1728. CommandLineCombo->Text = CommandLineCombo->Text + Buf;
  1729. }
  1730. else
  1731. {
  1732. TCustomScpExplorerForm::PanelExportStore(Side, Export, Destination, ExportData);
  1733. }
  1734. }
  1735. //---------------------------------------------------------------------------
  1736. int __fastcall TScpCommanderForm::GetStaticComponentsHeight()
  1737. {
  1738. return TCustomScpExplorerForm::GetStaticComponentsHeight() +
  1739. (BottomDock->Visible ? BottomDock->Height : 0) +
  1740. (QueueSeparatorPanel->Visible ? QueueSeparatorPanel->Height : 0) +
  1741. (StatusBar->Visible ? StatusBar->Height : 0);
  1742. }
  1743. //---------------------------------------------------------------------------
  1744. void __fastcall TScpCommanderForm::SysResizing(unsigned int Cmd)
  1745. {
  1746. TCustomScpExplorerForm::SysResizing(Cmd);
  1747. if ((Cmd == SC_MAXIMIZE) ||
  1748. ((Cmd == SC_DEFAULT) && (WindowState != wsMaximized)))
  1749. {
  1750. FNormalPanelsWidth = LocalPanel->Width + RemotePanel->Width;
  1751. }
  1752. else if ((Cmd == SC_RESTORE) ||
  1753. ((Cmd == SC_DEFAULT) && (WindowState == wsMaximized)))
  1754. {
  1755. if (FNormalPanelsWidth >= 0)
  1756. {
  1757. Panel(true)->Width = static_cast<int>(FLeftPanelWidth * FNormalPanelsWidth);
  1758. FNormalPanelsWidth = -1;
  1759. }
  1760. }
  1761. }
  1762. //---------------------------------------------------------------------------
  1763. void __fastcall TScpCommanderForm::Resize()
  1764. {
  1765. TCustomScpExplorerForm::Resize();
  1766. LeftPanelWidth = FLastLeftPanelWidth;
  1767. UpdateControls();
  1768. }
  1769. //---------------------------------------------------------------------------
  1770. void __fastcall TScpCommanderForm::PathLabelDblClick(TObject * Sender)
  1771. {
  1772. if (!NonVisualDataModule->Busy)
  1773. {
  1774. OpenDirectory(Sender == LocalPathLabel ? osLocal : osRemote);
  1775. }
  1776. }
  1777. //---------------------------------------------------------------------------
  1778. void __fastcall TScpCommanderForm::LocalPathLabelGetStatus(
  1779. TCustomPathLabel * /*Sender*/, bool & Active)
  1780. {
  1781. // WORKAROUND this strange form is here to make borland compiler work :-)
  1782. Active = Active || LocalDriveView->Focused();
  1783. }
  1784. //---------------------------------------------------------------------------
  1785. void __fastcall TScpCommanderForm::RemotePathLabelGetStatus(
  1786. TCustomPathLabel * /*Sender*/, bool & Active)
  1787. {
  1788. // WORKAROUND this strange form is here to make borland compiler work :-)
  1789. Active = Active || DriveView(osOther)->Focused();
  1790. }
  1791. //---------------------------------------------------------------------------
  1792. void __fastcall TScpCommanderForm::DoPathLabelPathClick(TOperationSide Side, const UnicodeString & Path)
  1793. {
  1794. if (!NonVisualDataModule->Busy)
  1795. {
  1796. TCustomDirView * ADirView = DirView(Side);
  1797. bool Same;
  1798. if (IsSideLocalBrowser(Side))
  1799. {
  1800. Same = SamePaths(Path, ADirView->Path);
  1801. }
  1802. else
  1803. {
  1804. Same = UnixSamePath(Path, ADirView->Path);
  1805. }
  1806. if (Same)
  1807. {
  1808. OpenDirectory(Side);
  1809. }
  1810. else
  1811. {
  1812. ADirView->Path = Path;
  1813. }
  1814. }
  1815. }
  1816. //---------------------------------------------------------------------------
  1817. void __fastcall TScpCommanderForm::LocalPathLabelPathClick(
  1818. TCustomPathLabel * /*Sender*/, UnicodeString Path)
  1819. {
  1820. DoPathLabelPathClick(osLocal, Path);
  1821. }
  1822. //---------------------------------------------------------------------------
  1823. void __fastcall TScpCommanderForm::RemotePathLabelPathClick(
  1824. TCustomPathLabel * /*Sender*/, UnicodeString Path)
  1825. {
  1826. DoPathLabelPathClick(osOther, Path);
  1827. }
  1828. //---------------------------------------------------------------------------
  1829. void __fastcall TScpCommanderForm::LocalDirViewFileIconForName(
  1830. TObject * /*Sender*/, TListItem * /*Item*/, UnicodeString & FileName)
  1831. {
  1832. UnicodeString PartialExt = Configuration->PartialExt;
  1833. if (AnsiSameText(ExtractFileExt(FileName), PartialExt))
  1834. {
  1835. FileName.SetLength(FileName.Length() - PartialExt.Length());
  1836. }
  1837. if (WinConfiguration->LocalIconsByExt)
  1838. {
  1839. FileName = ExtractFileName(FileName);
  1840. }
  1841. }
  1842. //---------------------------------------------------------------------------
  1843. void __fastcall TScpCommanderForm::LocalDirViewUpdateStatusBar(
  1844. TObject * /*Sender*/, const TStatusFileInfo & FileInfo)
  1845. {
  1846. UpdateFileStatusBar(LocalStatusBar, FileInfo, osLocal);
  1847. }
  1848. //---------------------------------------------------------------------------
  1849. void __fastcall TScpCommanderForm::RemoteDirViewUpdateStatusBar(
  1850. TObject * /*Sender*/, const TStatusFileInfo & FileInfo)
  1851. {
  1852. UpdateFileStatusBar(RemoteStatusBar, FileInfo, osRemote);
  1853. }
  1854. //---------------------------------------------------------------------------
  1855. void __fastcall TScpCommanderForm::OtherLocalDirViewUpdateStatusBar(TObject *, const TStatusFileInfo & FileInfo)
  1856. {
  1857. UpdateFileStatusBar(RemoteStatusBar, FileInfo, osOther);
  1858. }
  1859. //---------------------------------------------------------------------------
  1860. void __fastcall TScpCommanderForm::LocalStatusBarClick(TObject * /*Sender*/)
  1861. {
  1862. LocalDirView->SetFocus();
  1863. }
  1864. //---------------------------------------------------------------------------
  1865. UnicodeString __fastcall TScpCommanderForm::PathForCaption()
  1866. {
  1867. UnicodeString Result;
  1868. if (IsSideLocalBrowser(FCurrentSide))
  1869. {
  1870. // for consistency do not show even local path when there is no terminal
  1871. if (Terminal != NULL)
  1872. {
  1873. switch (WinConfiguration->PathInCaption)
  1874. {
  1875. case picShort:
  1876. {
  1877. Result = ExtractFileName(GetCurrentLocalBrowser()->PathName);
  1878. if (Result.IsEmpty())
  1879. {
  1880. Result = GetCurrentLocalBrowser()->PathName;
  1881. }
  1882. }
  1883. break;
  1884. case picFull:
  1885. Result = GetCurrentLocalBrowser()->PathName;
  1886. break;
  1887. }
  1888. }
  1889. }
  1890. else
  1891. {
  1892. Result = TCustomScpExplorerForm::PathForCaption();
  1893. }
  1894. return Result;
  1895. }
  1896. //---------------------------------------------------------------------------
  1897. void __fastcall TScpCommanderForm::GetTransferPresetAutoSelectData(
  1898. TCopyParamRuleData & Data)
  1899. {
  1900. TCustomScpExplorerForm::GetTransferPresetAutoSelectData(Data);
  1901. Data.LocalDirectory = LocalDirView->PathName;
  1902. }
  1903. //---------------------------------------------------------------------------
  1904. void __fastcall TScpCommanderForm::RemoteDirViewPathChange(TCustomDirView * /*Sender*/)
  1905. {
  1906. UpdateRemotePathComboBox(false);
  1907. ResetIncrementalSearch();
  1908. }
  1909. //---------------------------------------------------------------------------
  1910. void __fastcall TScpCommanderForm::UpdateImages()
  1911. {
  1912. TCustomScpExplorerForm::UpdateImages();
  1913. TImageList * ImageList = ShellImageListForControl(this, ilsSmall);
  1914. RemotePathComboBox->Images = ImageList;
  1915. RemotePathComboBox->SubMenuImages = ImageList;
  1916. LocalPathComboBox->Images = ImageList;
  1917. LocalPathComboBox->SubMenuImages = ImageList;
  1918. }
  1919. //---------------------------------------------------------------------------
  1920. void __fastcall TScpCommanderForm::LocalPathComboUpdateDrives()
  1921. {
  1922. FLocalSpecialPaths = 0;
  1923. TStrings* Strings = LocalPathComboBox->Strings;
  1924. Strings->BeginUpdate();
  1925. try
  1926. {
  1927. Strings->Clear();
  1928. FLocalPathComboBoxPaths->Clear();
  1929. Strings->Add(LoadStr(SPECIAL_FOLDER_MY_DOCUMENTS));
  1930. FLocalPathComboBoxPaths->AddObject(GetPersonalFolder(),
  1931. (TObject *)DriveInfo->SpecialFolder[CSIDL_PERSONAL]->ImageIndex);
  1932. FLocalSpecialPaths++;
  1933. Strings->Add(LoadStr(SPECIAL_FOLDER_DESKTOP));
  1934. FLocalPathComboBoxPaths->AddObject(GetDesktopFolder(),
  1935. (TObject *)DriveInfo->SpecialFolder[CSIDL_DESKTOP]->ImageIndex);
  1936. FLocalSpecialPaths++;
  1937. std::unique_ptr<TStrings> Drives(LocalDriveView->GetDrives());
  1938. for (int Index = 0; Index < Drives->Count; Index++)
  1939. {
  1940. UnicodeString Drive = Drives->Strings[Index];
  1941. if (DriveInfo->Get(Drive)->Valid)
  1942. {
  1943. UnicodeString Caption = DriveInfo->GetPrettyName(Drive);
  1944. if (DriveInfo->IsRealDrive(Drive))
  1945. {
  1946. Caption.Insert(L"&", 0);
  1947. }
  1948. Strings->Add(Caption);
  1949. UnicodeString RootPath = DriveInfo->GetDriveRoot(Drive);
  1950. int ImageIndex = DriveInfo->GetImageIndex(Drive);
  1951. FLocalPathComboBoxPaths->AddObject(RootPath, reinterpret_cast<TObject *>(ImageIndex));
  1952. }
  1953. }
  1954. }
  1955. __finally
  1956. {
  1957. Strings->EndUpdate();
  1958. }
  1959. if (IsLocalBrowserMode())
  1960. {
  1961. UpdateRemotePathComboBox(false);
  1962. }
  1963. }
  1964. //---------------------------------------------------------------------------
  1965. void __fastcall TScpCommanderForm::LocalPathComboUpdate(TCustomDirView * ADirView, TTBXComboBoxItem * PathComboBox)
  1966. {
  1967. // this may get called even after destructor finishes
  1968. // (e.g. from SetDockAllowDrag invoked [indirectly] from StoreParams)
  1969. if (FLocalPathComboBoxPaths != NULL)
  1970. {
  1971. DebugAssert(FLocalPathComboBoxPaths->Count == PathComboBox->Strings->Count);
  1972. int Index = 0;
  1973. while ((Index < FLocalPathComboBoxPaths->Count) &&
  1974. !SamePaths(FLocalPathComboBoxPaths->Strings[Index],
  1975. ADirView->Path.SubString(1, FLocalPathComboBoxPaths->Strings[Index].Length())))
  1976. {
  1977. Index++;
  1978. }
  1979. // what to do if not?
  1980. if (Index < FLocalPathComboBoxPaths->Count)
  1981. {
  1982. PathComboBox->ItemIndex = Index;
  1983. }
  1984. }
  1985. }
  1986. //---------------------------------------------------------------------------
  1987. void __fastcall TScpCommanderForm::DoLocalDirViewPathChange(TCustomDirView * Sender, TTBXComboBoxItem * PathComboBox)
  1988. {
  1989. LocalPathComboUpdate(Sender, PathComboBox);
  1990. ResetIncrementalSearch();
  1991. if (IsUncPath(Sender->Path))
  1992. {
  1993. Configuration->Usage->Inc(L"BrowsedUncPath");
  1994. }
  1995. }
  1996. //---------------------------------------------------------------------------
  1997. void __fastcall TScpCommanderForm::LocalDirViewPathChange(TCustomDirView * Sender)
  1998. {
  1999. DoLocalDirViewPathChange(Sender, LocalPathComboBox);
  2000. }
  2001. //---------------------------------------------------------------------------
  2002. void __fastcall TScpCommanderForm::LocalPathComboBoxCancel(TObject * /*Sender*/)
  2003. {
  2004. LocalPathComboUpdate(LocalDirView, LocalPathComboBox);
  2005. }
  2006. //---------------------------------------------------------------------------
  2007. void __fastcall TScpCommanderForm::DoLocalPathComboBoxAdjustImageIndex(
  2008. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex, int & ImageIndex)
  2009. {
  2010. // this may get called even before constructor starts
  2011. // (e.g. from FixControlsPlacement)
  2012. if (FLocalPathComboBoxPaths != NULL)
  2013. {
  2014. TTBXComboBoxItem * PathComboBox = DebugNotNull(dynamic_cast<TTBXComboBoxItem *>(Sender));
  2015. DebugAssert(FLocalPathComboBoxPaths->Count == PathComboBox->Strings->Count);
  2016. DebugAssert(AIndex < FLocalPathComboBoxPaths->Count);
  2017. if (AIndex < 0)
  2018. {
  2019. AIndex = PathComboBox->ItemIndex;
  2020. }
  2021. if (AIndex >= 0)
  2022. {
  2023. ImageIndex = int(FLocalPathComboBoxPaths->Objects[AIndex]);
  2024. }
  2025. }
  2026. }
  2027. //---------------------------------------------------------------------------
  2028. void __fastcall TScpCommanderForm::LocalPathComboBoxAdjustImageIndex(
  2029. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  2030. int & ImageIndex)
  2031. {
  2032. DoLocalPathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  2033. }
  2034. //---------------------------------------------------------------------------
  2035. void __fastcall TScpCommanderForm::DoLocalPathComboBoxItemClick(TDirView * ADirView, TTBXComboBoxItem * PathComboBox)
  2036. {
  2037. DebugAssert(FLocalPathComboBoxPaths->Count == PathComboBox->Strings->Count);
  2038. DebugAssert((PathComboBox->ItemIndex >= 0) && (PathComboBox->ItemIndex < FLocalPathComboBoxPaths->Count));
  2039. UnicodeString Path = FLocalPathComboBoxPaths->Strings[PathComboBox->ItemIndex];
  2040. if (PathComboBox->ItemIndex >= FLocalSpecialPaths)
  2041. {
  2042. ADirView->ExecuteDrive(DriveInfo->GetDriveKey(Path));
  2043. }
  2044. else
  2045. {
  2046. ADirView->Path = Path;
  2047. }
  2048. }
  2049. //---------------------------------------------------------------------------
  2050. void __fastcall TScpCommanderForm::LocalPathComboBoxItemClick(TObject *)
  2051. {
  2052. DoLocalPathComboBoxItemClick(LocalDirView, LocalPathComboBox);
  2053. }
  2054. //---------------------------------------------------------------------------
  2055. void __fastcall TScpCommanderForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  2056. {
  2057. TCustomScpExplorerForm::ToolbarItemResize(Item, Width);
  2058. if ((Item == LocalPathComboBox) ||
  2059. (Item == RemotePathComboBox) ||
  2060. (Item == CommandLineCombo))
  2061. {
  2062. dynamic_cast<TTBXComboBoxItem *>(Item)->MinListWidth = Width - 4;
  2063. }
  2064. }
  2065. //---------------------------------------------------------------------------
  2066. void __fastcall TScpCommanderForm::CommandLineComboPopup(
  2067. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  2068. {
  2069. CommandLinePopulate();
  2070. }
  2071. //---------------------------------------------------------------------------
  2072. void __fastcall TScpCommanderForm::CommandLineComboBeginEdit(
  2073. TTBEditItem * /*Sender*/, TTBEditItemViewer * /*Viewer*/, TEdit *EditControl)
  2074. {
  2075. InstallPathWordBreakProc(EditControl);
  2076. FCommandLineComboEdit = EditControl;
  2077. FToolbarEditOldWndProc = EditControl->WindowProc;
  2078. EditControl->WindowProc = CommandLineComboEditWndProc;
  2079. }
  2080. //---------------------------------------------------------------------------
  2081. void __fastcall TScpCommanderForm::ExitToolbar()
  2082. {
  2083. CurrentPanel()->SetFocus();
  2084. }
  2085. //---------------------------------------------------------------------------
  2086. void __fastcall TScpCommanderForm::CommandLineComboEditWndProc(TMessage & Message)
  2087. {
  2088. bool Handled = false;
  2089. if (Message.Msg == WM_CHAR)
  2090. {
  2091. switch (reinterpret_cast<TWMChar &>(Message).CharCode)
  2092. {
  2093. case VK_ESCAPE:
  2094. CommandLineCombo->Text = L"";
  2095. ExitToolbar();
  2096. Handled = true;
  2097. break;
  2098. case VK_TAB:
  2099. CommandLineCombo->Text = FCommandLineComboEdit->Text;
  2100. ExitToolbar();
  2101. Handled = true;
  2102. break;
  2103. case VK_RETURN:
  2104. CommandLineCombo->Text = FCommandLineComboEdit->Text;
  2105. ExitToolbar();
  2106. if (!ExecuteCommandLine())
  2107. {
  2108. // re-enter command line
  2109. // (most probably exited by now as message dialog was shown)
  2110. GoToCommandLine();
  2111. }
  2112. Handled = true;
  2113. break;
  2114. }
  2115. }
  2116. if (!Handled)
  2117. {
  2118. FToolbarEditOldWndProc(Message);
  2119. }
  2120. }
  2121. //---------------------------------------------------------------------------
  2122. void __fastcall TScpCommanderForm::LocalDriveViewRefreshDrives(TObject * /*Sender*/)
  2123. {
  2124. LocalPathComboUpdateDrives();
  2125. LocalPathComboUpdate(LocalDirView, LocalPathComboBox);
  2126. if (IsLocalBrowserMode())
  2127. {
  2128. LocalPathComboUpdate(OtherLocalDirView, RemotePathComboBox);
  2129. }
  2130. }
  2131. //---------------------------------------------------------------------------
  2132. void __fastcall TScpCommanderForm::HomeDirectory(TOperationSide Side)
  2133. {
  2134. bool SynchronizeBrowsing = NonVisualDataModule->SynchronizeBrowsingAction2->Checked;
  2135. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  2136. TCustomScpExplorerForm::HomeDirectory(Side);
  2137. if (SynchronizeBrowsing)
  2138. {
  2139. TCustomScpExplorerForm::HomeDirectory(GetOtherSize(Side));
  2140. }
  2141. }
  2142. //---------------------------------------------------------------------------
  2143. void __fastcall TScpCommanderForm::QueueSubmenuItemPopup(
  2144. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  2145. {
  2146. NonVisualDataModule->QueueSpeedComboBoxItemUpdate(QueueSpeedComboBoxItem);
  2147. }
  2148. //---------------------------------------------------------------------------
  2149. void __fastcall TScpCommanderForm::DoFocusRemotePath(TTerminal * Terminal, const UnicodeString & Path)
  2150. {
  2151. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  2152. TCustomScpExplorerForm::DoFocusRemotePath(Terminal, Path);
  2153. }
  2154. //---------------------------------------------------------------------------
  2155. TOperationSide __fastcall TScpCommanderForm::GetOtherSize(TOperationSide Side)
  2156. {
  2157. Side = GetSide(Side);
  2158. return ReverseOperationSide(Side);
  2159. }
  2160. //---------------------------------------------------------------------------
  2161. void __fastcall TScpCommanderForm::HistoryGo(TOperationSide Side, int Index)
  2162. {
  2163. TOperationSide OtherSide = GetOtherSize(Side);
  2164. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked &&
  2165. ((Index < 0) ? (-Index < DirView(OtherSide)->BackCount) : (Index < DirView(OtherSide)->ForwardCount)))
  2166. {
  2167. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  2168. TCustomScpExplorerForm::HistoryGo(Side, Index);
  2169. TCustomScpExplorerForm::HistoryGo(OtherSide, Index);
  2170. }
  2171. else
  2172. {
  2173. TCustomScpExplorerForm::HistoryGo(Side, Index);
  2174. }
  2175. }
  2176. //---------------------------------------------------------------------------
  2177. void __fastcall TScpCommanderForm::DirViewHistoryGo(
  2178. TCustomDirView * Sender, int Index, bool & Cancel)
  2179. {
  2180. TOperationSide Side = (Sender == DirView(osRemote) ? osRemote : osLocal);
  2181. HistoryGo(Side, Index);
  2182. Cancel = true;
  2183. }
  2184. //---------------------------------------------------------------------------
  2185. bool __fastcall TScpCommanderForm::EligibleForImageDisplayMode(TTBCustomItem * Item)
  2186. {
  2187. return
  2188. TCustomScpExplorerForm::EligibleForImageDisplayMode(Item) &&
  2189. ((Item->Parent == NULL) || (Item->Parent->ParentComponent != Toolbar2Toolbar));
  2190. }
  2191. //---------------------------------------------------------------------------
  2192. bool __fastcall TScpCommanderForm::UpdateToolbarDisplayMode()
  2193. {
  2194. bool Result = TCustomScpExplorerForm::UpdateToolbarDisplayMode();
  2195. if (Result)
  2196. {
  2197. // command line combo width needs to be updated as caption visibility has changed
  2198. ToolBarResize(CommandLineToolbar);
  2199. }
  2200. return Result;
  2201. }
  2202. //---------------------------------------------------------------------------
  2203. void __fastcall TScpCommanderForm::QueueLabelUpdateStatus()
  2204. {
  2205. TCustomScpExplorerForm::QueueLabelUpdateStatus();
  2206. // this is here to deactivate panels path labels when moving focus from
  2207. // directory tree to queue
  2208. UpdatePanelsPathLabelsStatus();
  2209. }
  2210. //---------------------------------------------------------------------------
  2211. void __fastcall TScpCommanderForm::DoLocalDirViewContextPopup(TOperationSide Side, TPoint & MousePos, bool & Handled)
  2212. {
  2213. if (!WinConfiguration->ScpCommander.SystemContextMenu && !FForceSystemContextMenu)
  2214. {
  2215. DirViewContextPopupDefaultItem(Side, NonVisualDataModule->LocalOpenMenuItem, dcaOpen);
  2216. DirViewContextPopupDefaultItem(Side, NonVisualDataModule->LocalEditMenuItem, dcaEdit);
  2217. DirViewContextPopupDefaultItem(Side, NonVisualDataModule->LocalCopyMenuItem, dcaCopy);
  2218. DirViewContextPopup(Side, fcLocalPopup, MousePos);
  2219. Handled = true;
  2220. }
  2221. }
  2222. //---------------------------------------------------------------------------
  2223. void __fastcall TScpCommanderForm::LocalDirViewContextPopup(TObject *, TPoint & MousePos, bool & Handled)
  2224. {
  2225. DoLocalDirViewContextPopup(osLocal, MousePos, Handled);
  2226. }
  2227. //---------------------------------------------------------------------------
  2228. void __fastcall TScpCommanderForm::OtherLocalDirViewContextPopup(TObject *, TPoint & MousePos, bool & Handled)
  2229. {
  2230. DoLocalDirViewContextPopup(osOther, MousePos, Handled);
  2231. }
  2232. //---------------------------------------------------------------------------
  2233. void __fastcall TScpCommanderForm::DisplaySystemContextMenu()
  2234. {
  2235. TAutoFlag Flag(FForceSystemContextMenu);
  2236. if ((FLastContextPopupScreenPoint.x >= 0) && (FLastContextPopupScreenPoint.Y >= 0))
  2237. {
  2238. DirView(osCurrent)->DisplayContextMenu(FLastContextPopupScreenPoint);
  2239. }
  2240. else
  2241. {
  2242. DirView(osCurrent)->DisplayContextMenuInSitu();
  2243. }
  2244. }
  2245. //---------------------------------------------------------------------------
  2246. void __fastcall TScpCommanderForm::LocalStatusBarPanelClick(TTBXCustomStatusBar * /*Sender*/,
  2247. TTBXStatusPanel * Panel)
  2248. {
  2249. FileStatusBarPanelClick(Panel, osLocal);
  2250. }
  2251. //---------------------------------------------------------------------------
  2252. void __fastcall TScpCommanderForm::RemoteStatusBarPanelClick(TTBXCustomStatusBar * /*Sender*/,
  2253. TTBXStatusPanel *Panel)
  2254. {
  2255. FileStatusBarPanelClick(Panel, osRemote);
  2256. }
  2257. //---------------------------------------------------------------------------
  2258. void __fastcall TScpCommanderForm::GoToAddress()
  2259. {
  2260. OpenDirectory(GetSide(osCurrent));
  2261. }
  2262. //---------------------------------------------------------------------------
  2263. void __fastcall TScpCommanderForm::RemotePathLabelMaskClick(TObject * /*Sender*/)
  2264. {
  2265. Filter(osRemote);
  2266. }
  2267. //---------------------------------------------------------------------------
  2268. void __fastcall TScpCommanderForm::LocalPathLabelMaskClick(TObject * /*Sender*/)
  2269. {
  2270. Filter(osLocal);
  2271. }
  2272. //---------------------------------------------------------------------------
  2273. void __fastcall TScpCommanderForm::LocalOpenDirButtonPopup(TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  2274. {
  2275. CreateOpenDirMenu(LocalOpenDirButton, osLocal);
  2276. }
  2277. //---------------------------------------------------------------------------
  2278. void __fastcall TScpCommanderForm::RemoteOpenDirButtonPopup(TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  2279. {
  2280. CreateOpenDirMenu(RemoteOpenDirButton, osRemote);
  2281. }
  2282. //---------------------------------------------------------------------------
  2283. void __fastcall TScpCommanderForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  2284. {
  2285. if (IsSideLocalBrowser(Side))
  2286. {
  2287. TInstantOperationVisualizer Visualizer;
  2288. dynamic_cast<TDirView *>(DirView(Side))->CopyToClipBoard(OnFocused);
  2289. }
  2290. else
  2291. {
  2292. TCustomScpExplorerForm::CopyFilesToClipboard(Side, OnFocused);
  2293. }
  2294. }
  2295. //---------------------------------------------------------------------------
  2296. void __fastcall TScpCommanderForm::PasteFromClipBoard()
  2297. {
  2298. if (DoesClipboardContainOurFiles() && (IsSideLocalBrowser(osCurrent)))
  2299. {
  2300. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  2301. {
  2302. ClipboardDownload(DirView(osCurrent)->Path, !WinConfiguration->ConfirmTransferring, false);
  2303. }
  2304. }
  2305. else
  2306. {
  2307. TCustomScpExplorerForm::PasteFromClipBoard();
  2308. }
  2309. }
  2310. //---------------------------------------------------------------------------
  2311. void __fastcall TScpCommanderForm::FileColorsChanged()
  2312. {
  2313. TCustomScpExplorerForm::FileColorsChanged();
  2314. DoFileColorsChanged(LocalDirView);
  2315. DoFileColorsChanged(OtherLocalDirView);
  2316. }
  2317. //---------------------------------------------------------------------------
  2318. void __fastcall TScpCommanderForm::BrowseFile()
  2319. {
  2320. DebugAssert(!IsLocalBrowserMode());
  2321. TCustomScpExplorerForm::BrowseFile();
  2322. if (LocalDirView->ItemFocused != NULL)
  2323. {
  2324. LocalDirView->ItemFocused->Selected = true;
  2325. }
  2326. TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
  2327. // Select the panel that has the file, with preference on the remote panel
  2328. if (RemoteDirView->ItemFocused->Selected)
  2329. {
  2330. ScpCommander.CurrentPanel = osRemote;
  2331. }
  2332. else if (LocalDirView->ItemFocused->Selected)
  2333. {
  2334. ScpCommander.CurrentPanel = osLocal;
  2335. }
  2336. WinConfiguration->ScpCommander = ScpCommander;
  2337. }
  2338. //---------------------------------------------------------------------------
  2339. void __fastcall TScpCommanderForm::ThemeChanged()
  2340. {
  2341. TCustomScpExplorerForm::ThemeChanged();
  2342. LocalDirView->Perform(WM_THEMECHANGED, 0, 0);
  2343. OtherLocalDirView->Perform(WM_THEMECHANGED, 0, 0);
  2344. }
  2345. //---------------------------------------------------------------------------
  2346. void __fastcall TScpCommanderForm::OtherLocalDirViewEnter(TObject *)
  2347. {
  2348. // Actually identical to LocalDirViewEnter
  2349. SideEnter(osOther);
  2350. }
  2351. //---------------------------------------------------------------------------
  2352. void __fastcall TScpCommanderForm::OtherLocalDriveViewEnter(TObject *)
  2353. {
  2354. MakeNextInTabOrder(OtherLocalDirView, OtherLocalDriveView);
  2355. SideEnter(osOther);
  2356. }
  2357. //---------------------------------------------------------------------------
  2358. void __fastcall TScpCommanderForm::DoRemotePathComboBoxAdjustImageIndex(
  2359. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex, int & ImageIndex)
  2360. {
  2361. if (!IsLocalBrowserMode())
  2362. {
  2363. TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  2364. }
  2365. else
  2366. {
  2367. DoLocalPathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  2368. }
  2369. }
  2370. //---------------------------------------------------------------------------
  2371. void __fastcall TScpCommanderForm::DoRemotePathComboBoxCancel(TObject * Sender)
  2372. {
  2373. if (!IsLocalBrowserMode())
  2374. {
  2375. TCustomScpExplorerForm::DoRemotePathComboBoxCancel(Sender);
  2376. }
  2377. else
  2378. {
  2379. LocalPathComboUpdate(OtherLocalDirView, RemotePathComboBox);
  2380. }
  2381. }
  2382. //---------------------------------------------------------------------------
  2383. void __fastcall TScpCommanderForm::OtherLocalDirViewPathChange(TCustomDirView * Sender)
  2384. {
  2385. DebugAssert(IsLocalBrowserMode());
  2386. DoLocalDirViewPathChange(Sender, RemotePathComboBox);
  2387. }
  2388. //---------------------------------------------------------------------------
  2389. void __fastcall TScpCommanderForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  2390. {
  2391. if (!IsLocalBrowserMode())
  2392. {
  2393. TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(Sender);
  2394. }
  2395. else
  2396. {
  2397. DoLocalPathComboBoxItemClick(OtherLocalDirView, RemotePathComboBox);
  2398. }
  2399. }
  2400. //---------------------------------------------------------------------------
  2401. void __fastcall TScpCommanderForm::UpdateRemotePathComboBox(bool TextOnly)
  2402. {
  2403. if (!IsLocalBrowserMode())
  2404. {
  2405. TCustomScpExplorerForm::UpdateRemotePathComboBox(TextOnly);
  2406. }
  2407. else
  2408. {
  2409. if (!TextOnly)
  2410. {
  2411. RemotePathComboBox->Strings->Assign(LocalPathComboBox->Strings);
  2412. }
  2413. LocalPathComboUpdate(OtherLocalDirView, RemotePathComboBox);
  2414. }
  2415. }