ScpCommander.cpp 98 KB

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