1
0

ScpCommander.cpp 107 KB

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