ScpCommander.cpp 108 KB

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