1
0

ScpCommander.cpp 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "ScpCommander.h"
  5. #include <Common.h>
  6. #include <CoreMain.h>
  7. #include <Interface.h>
  8. #include <TextsCore.h>
  9. #include <TextsWin.h>
  10. #include <HelpWin.h>
  11. #include <VCLCommon.h>
  12. #include <GUITools.h>
  13. #include <DragDrop.hpp>
  14. #include <StrUtils.hpp>
  15. #include <IOUtils.hpp>
  16. #include "Glyphs.h"
  17. #include "NonVisual.h"
  18. #include "Tools.h"
  19. #include "WinConfiguration.h"
  20. #include "TerminalManager.h"
  21. #include "Bookmarks.h"
  22. //---------------------------------------------------------------------------
  23. #pragma package(smart_init)
  24. #pragma link "CustomDirView"
  25. #pragma link "CustomScpExplorer"
  26. #pragma link "CustomUnixDirView"
  27. #pragma link "IEListView"
  28. #pragma link "NortonLikeListView"
  29. #pragma link "UnixDirView"
  30. #pragma link "DirView"
  31. #pragma link "PathLabel"
  32. #pragma link "HistoryComboBox"
  33. #pragma link "CustomDriveView"
  34. #pragma link "DriveView"
  35. #pragma link "UnixDriveView"
  36. #pragma link "TB2Dock"
  37. #pragma link "TB2Item"
  38. #pragma link "TB2Toolbar"
  39. #pragma link "TBX"
  40. #pragma link "TB2ExtItems"
  41. #pragma link "TBXExtItems"
  42. #pragma link "TBXLists"
  43. #pragma link "TBXStatusBars"
  44. #pragma link "TBXToolPals"
  45. #pragma link "ThemePageControl"
  46. #pragma resource "*.dfm"
  47. //---------------------------------------------------------------------------
  48. class TSynchronizedBrowsingGuard
  49. {
  50. public:
  51. TSynchronizedBrowsingGuard()
  52. {
  53. FWasSynchronisingBrowsing = NonVisualDataModule->SynchronizeBrowsingAction2->Checked;
  54. NonVisualDataModule->SynchronizeBrowsingAction2->Checked = false;
  55. }
  56. ~TSynchronizedBrowsingGuard()
  57. {
  58. NonVisualDataModule->SynchronizeBrowsingAction2->Checked = FWasSynchronisingBrowsing;
  59. }
  60. private:
  61. bool FWasSynchronisingBrowsing;
  62. };
  63. //---------------------------------------------------------------------------
  64. __fastcall TScpCommanderForm::TScpCommanderForm(TComponent* Owner)
  65. : TCustomScpExplorerForm(Owner)
  66. {
  67. FConstructed = true;
  68. FCurrentSide = osLocal;
  69. FLastLeftPanelWidth = LeftPanelWidth;
  70. FNormalPanelsWidth = -1;
  71. FSynchronisingBrowse = false;
  72. FFirstTerminal = true;
  73. FInternalDDDownloadList = new TStringList();
  74. FLocalPathComboBoxPaths = new TStringList();
  75. LocalPathComboUpdateDrives();
  76. LocalBackButton->LinkSubitems = HistoryMenu(osLocal, true)->Items;
  77. LocalForwardButton->LinkSubitems = HistoryMenu(osLocal, false)->Items;
  78. RemoteBackButton->LinkSubitems = HistoryMenu(osRemote, true)->Items;
  79. RemoteForwardButton->LinkSubitems = HistoryMenu(osRemote, false)->Items;
  80. TopDock->PopupMenu = NonVisualDataModule->CommanderBarPopup;
  81. CopyPopup(StatusBar, TopDock);
  82. CopyPopup(QueueDock, TopDock);
  83. CopyPopup(QueueLabel, TopDock);
  84. CopyPopup(BottomDock, TopDock);
  85. CopyPopup(QueueSeparatorPanel, TopDock);
  86. CopyPopup(QueueFileList, TopDock);
  87. CopyPopup(QueueFileListSplitter, TopDock);
  88. LocalTopDock->PopupMenu = NonVisualDataModule->LocalPanelPopup;
  89. CopyPopup(LocalPathLabel, LocalTopDock);
  90. CopyPopup(LocalStatusBar, LocalTopDock);
  91. CopyPopup(LocalDriveView, LocalTopDock);
  92. CopyPopup(OtherLocalDriveView, LocalTopDock);
  93. CopyPopup(LocalBottomDock, LocalTopDock);
  94. RemoteTopDock->PopupMenu = NonVisualDataModule->RemotePanelPopup;
  95. CopyPopup(RemotePathLabel, RemoteTopDock);
  96. CopyPopup(RemoteStatusBar, RemoteTopDock);
  97. CopyPopup(RemoteDriveView, RemoteTopDock);
  98. CopyPopup(RemoteBottomDock, RemoteTopDock);
  99. SetShortcuts();
  100. Splitter->ShowHint = True;
  101. LocalPanelSplitter->ShowHint = true;
  102. reinterpret_cast<TLabel*>(Splitter)->OnDblClick = SplitterDblClick;
  103. reinterpret_cast<TLabel*>(LocalPanelSplitter)->OnDblClick = PanelSplitterDblClick;
  104. reinterpret_cast<TLabel*>(RemotePanelSplitter)->OnDblClick = PanelSplitterDblClick;
  105. CommandLineCombo->Text = L"";
  106. FCommandLineComboPopulated = false;
  107. for (int i = 0; i < Toolbar2Toolbar->Items->Count; i++)
  108. {
  109. UpdateToolbar2ItemCaption(Toolbar2Toolbar->Items->Items[i]);
  110. }
  111. UseDesktopFont(LocalDirView);
  112. UseDesktopFont(LocalDriveView);
  113. UseDesktopFont(LocalPathLabel);
  114. UseDesktopFont(RemotePathLabel);
  115. UseDesktopFont(LocalStatusBar);
  116. UseDesktopFont(StatusBar);
  117. UseDesktopFont(OtherLocalDirView);
  118. UseDesktopFont(OtherLocalDriveView);
  119. OtherLocalDirView->Align = RemoteDirView->Align;
  120. OtherLocalDriveView->Align = RemoteDriveView->Align;
  121. NonVisualDataModule->QueueSpeedComboBoxItem(QueueSpeedComboBoxItem);
  122. // particularly to reorder panels on right-to-left bidi mode
  123. ConfigurationChanged();
  124. }
  125. //---------------------------------------------------------------------------
  126. __fastcall TScpCommanderForm::~TScpCommanderForm()
  127. {
  128. delete FInternalDDDownloadList;
  129. SAFE_DESTROY(FLocalPathComboBoxPaths);
  130. }
  131. //---------------------------------------------------------------------------
  132. void __fastcall TScpCommanderForm::UpdateToolbar2ItemCaption(TTBCustomItem * Item)
  133. {
  134. Item->Caption =
  135. ShortCutToText(Item->ShortCut) + L" " +
  136. StripEllipsis(StripHotkey(Item->Caption));
  137. }
  138. //---------------------------------------------------------------------------
  139. void __fastcall TScpCommanderForm::RestoreFormParams()
  140. {
  141. DebugAssert(WinConfiguration);
  142. TCustomScpExplorerForm::RestoreFormParams();
  143. RestoreForm(WinConfiguration->ScpCommander.WindowParams, this);
  144. }
  145. //---------------------------------------------------------------------------
  146. void __fastcall TScpCommanderForm::RestorePanelParams(
  147. TCustomDirView * DirView, TControl * DriveControl, TTBXStatusBar * StatusBar,
  148. const TScpCommanderPanelConfiguration & PanelConfiguration)
  149. {
  150. DirView->ColProperties->ParamsStr = PanelConfiguration.DirViewParams;
  151. StatusBar->Visible = PanelConfiguration.StatusBar;
  152. DriveControl->Visible = PanelConfiguration.DriveView;
  153. if (DriveControl->Align == alTop)
  154. {
  155. DriveControl->Height = LoadDimension(PanelConfiguration.DriveViewHeight, PanelConfiguration.DriveViewHeightPixelsPerInch, this);
  156. }
  157. else
  158. {
  159. DriveControl->Width = LoadDimension(PanelConfiguration.DriveViewWidth, PanelConfiguration.DriveViewWidthPixelsPerInch, this);
  160. }
  161. }
  162. //---------------------------------------------------------------------------
  163. void __fastcall TScpCommanderForm::RestoreParams()
  164. {
  165. DebugAssert(Configuration);
  166. TCustomScpExplorerForm::RestoreParams();
  167. LeftPanelWidth = WinConfiguration->ScpCommander.LocalPanelWidth;
  168. LoadToolbarsLayoutStr(WinConfiguration->ScpCommander.ToolbarsLayout, WinConfiguration->ScpCommander.ToolbarsButtons);
  169. if (IsUWP())
  170. {
  171. UpdatesToolbar->Visible = false;
  172. }
  173. SessionsPageControl->Visible = WinConfiguration->ScpCommander.SessionsTabs;
  174. StatusBar->Visible = WinConfiguration->ScpCommander.StatusBar;
  175. RestorePanelParams(LocalDirView, LocalDriveView, LocalStatusBar, WinConfiguration->ScpCommander.LocalPanel);
  176. RestorePanelParams(RemoteDirView, RemoteDrivePanel, RemoteStatusBar, WinConfiguration->ScpCommander.RemotePanel);
  177. OtherLocalDirView->ColProperties->ParamsStr = WinConfiguration->ScpCommander.OtherLocalPanelDirViewParams;
  178. FPanelsRestored = true;
  179. // just to make sure
  180. LocalDirView->DirColProperties->ExtVisible = false;
  181. RemoteDirView->UnixColProperties->ExtVisible = false;
  182. OtherLocalDirView->DirColProperties->ExtVisible = false;
  183. }
  184. //---------------------------------------------------------------------------
  185. void __fastcall TScpCommanderForm::StorePanelParams(
  186. TCustomDirView * DirView, TControl * DriveControl, TTBXStatusBar * StatusBar,
  187. TScpCommanderPanelConfiguration & PanelConfiguration)
  188. {
  189. PanelConfiguration.DirViewParams = DirView->ColProperties->ParamsStr;
  190. PanelConfiguration.StatusBar = StatusBar->Visible;
  191. PanelConfiguration.DriveView = DriveControl->Visible;
  192. if (DriveControl->Align == alTop)
  193. {
  194. PanelConfiguration.DriveViewHeight = DriveControl->Height;
  195. PanelConfiguration.DriveViewHeightPixelsPerInch = GetControlPixelsPerInch(this);
  196. }
  197. else
  198. {
  199. PanelConfiguration.DriveViewWidth = DriveControl->Width;
  200. PanelConfiguration.DriveViewWidthPixelsPerInch = GetControlPixelsPerInch(this);
  201. }
  202. }
  203. //---------------------------------------------------------------------------
  204. void __fastcall TScpCommanderForm::StoreParams()
  205. {
  206. DebugAssert(WinConfiguration);
  207. WinConfiguration->BeginUpdate();
  208. try
  209. {
  210. SaveCommandLine();
  211. TScpCommanderConfiguration CommanderConfiguration = WinConfiguration->ScpCommander;
  212. CommanderConfiguration.ToolbarsLayout = GetToolbarsLayoutStr();
  213. CommanderConfiguration.ToolbarsButtons = GetToolbarsButtonsStr();
  214. CommanderConfiguration.LocalPanelWidth = LeftPanelWidth;
  215. CommanderConfiguration.SessionsTabs = SessionsPageControl->Visible;
  216. CommanderConfiguration.StatusBar = StatusBar->Visible;
  217. CommanderConfiguration.CurrentPanel = FCurrentSide;
  218. StorePanelParams(LocalDirView, LocalDriveView, LocalStatusBar, CommanderConfiguration.LocalPanel);
  219. StorePanelParams(RemoteDirView, RemoteDrivePanel, RemoteStatusBar, CommanderConfiguration.RemotePanel);
  220. CommanderConfiguration.OtherLocalPanelDirViewParams = OtherLocalDirView->ColProperties->ParamsStr;
  221. CommanderConfiguration.LocalPanel.LastPath = LocalDirView->Path;
  222. CommanderConfiguration.OtherLocalPanelLastPath = OtherLocalDirView->Path;
  223. CommanderConfiguration.WindowParams = StoreForm(this);
  224. WinConfiguration->ScpCommander = CommanderConfiguration;
  225. TCustomScpExplorerForm::StoreParams();
  226. }
  227. __finally
  228. {
  229. WinConfiguration->EndUpdate();
  230. }
  231. }
  232. //---------------------------------------------------------------------------
  233. void __fastcall TScpCommanderForm::UpdateSession(TManagedTerminal * Session)
  234. {
  235. TCustomScpExplorerForm::UpdateSession(Session);
  236. DebugAssert(LocalDirView != NULL);
  237. SAFE_DESTROY(Session->LocalExplorerState);
  238. SAFE_DESTROY(Session->OtherLocalExplorerState);
  239. if (WinConfiguration->PreservePanelState)
  240. {
  241. Session->LocalExplorerState = LocalDirView->SaveState();
  242. if (IsLocalBrowserMode())
  243. {
  244. Session->OtherLocalExplorerState = OtherLocalDirView->SaveState();
  245. }
  246. }
  247. }
  248. //---------------------------------------------------------------------------
  249. void __fastcall TScpCommanderForm::UpdateSessionData(TSessionData * Data)
  250. {
  251. // Keep in sync with TSessionData::CopyStateData
  252. TCustomScpExplorerForm::UpdateSessionData(Data);
  253. DebugAssert(LocalDirView);
  254. Data->LocalDirectory = LocalDirView->PathName;
  255. if (IsLocalBrowserMode())
  256. {
  257. Data->OtherLocalDirectory = OtherLocalDirView->PathName;
  258. }
  259. // Setting both directories makes it a local browser
  260. DebugAssert(Data->IsLocalBrowser == IsLocalBrowserMode());
  261. Data->SynchronizeBrowsing = NonVisualDataModule->SynchronizeBrowsingAction2->Checked;
  262. }
  263. //---------------------------------------------------------------------------
  264. bool __fastcall TScpCommanderForm::InternalDDDownload(UnicodeString & TargetDirectory)
  265. {
  266. DebugAssert(IsFileControl(FDDTargetControl, osLocal));
  267. DebugAssert(!IsLocalBrowserMode());
  268. bool Result = false;
  269. if (FDDTargetControl == LocalDirView)
  270. {
  271. if (LocalDirView->DropTarget)
  272. {
  273. // when drop target is not directory, it is probably file type, which have
  274. // associated drop handler (such as ZIP file in WinXP). in this case we
  275. // must leave drop handling to destination application.
  276. // ! this check is duplicated in LocalDirViewDDTargetHasDropHandler()
  277. // for shellex downloads
  278. if (LocalDirView->ItemIsDirectory(LocalDirView->DropTarget))
  279. {
  280. TargetDirectory = LocalDirView->ItemFullFileName(LocalDirView->DropTarget);
  281. Result = true;
  282. }
  283. }
  284. else
  285. {
  286. TargetDirectory = DefaultDownloadTargetDirectory();
  287. Result = true;
  288. }
  289. }
  290. else if (FDDTargetControl == LocalDriveView)
  291. {
  292. DebugAssert(LocalDriveView->DropTarget != NULL);
  293. TargetDirectory = LocalDriveView->NodePathName(LocalDriveView->DropTarget);
  294. Result = true;
  295. }
  296. else
  297. {
  298. DebugFail();
  299. Abort();
  300. }
  301. return Result;
  302. }
  303. //---------------------------------------------------------------------------
  304. UnicodeString __fastcall TScpCommanderForm::DefaultDownloadTargetDirectory()
  305. {
  306. return IncludeTrailingBackslash(LocalDirView->Path);
  307. }
  308. //---------------------------------------------------------------------------
  309. bool __fastcall TScpCommanderForm::CopyParamDialog(TTransferDirection Direction,
  310. TTransferType Type, bool Temp, TStrings * FileList, UnicodeString & TargetDirectory,
  311. TGUICopyParamType & CopyParam, bool Confirm, bool DragDrop, int Options)
  312. {
  313. bool Result = false;
  314. // Temp means d&d here so far, may change in future!
  315. if (Temp && (Direction == tdToLocal) &&
  316. IsFileControl(FDDTargetControl, osLocal))
  317. {
  318. Result = InternalDDDownload(TargetDirectory);
  319. if (Result)
  320. {
  321. DebugAssert(FileList->Count > 0);
  322. FInternalDDDownloadList->Assign(FileList);
  323. }
  324. }
  325. else if (!Temp && TargetDirectory.IsEmpty())
  326. {
  327. if (Direction == tdToLocal)
  328. {
  329. TargetDirectory = DefaultDownloadTargetDirectory();
  330. }
  331. else
  332. {
  333. TargetDirectory = UnixIncludeTrailingBackslash(RemoteDirView->Path);
  334. }
  335. }
  336. if (!Result)
  337. {
  338. Result = TCustomScpExplorerForm::CopyParamDialog(Direction, Type, Temp,
  339. FileList, TargetDirectory, CopyParam, Confirm, DragDrop, Options);
  340. }
  341. return Result;
  342. }
  343. //---------------------------------------------------------------------------
  344. void __fastcall TScpCommanderForm::DoShow()
  345. {
  346. // Make sure the RemoteDirView is disabled (if not connected yet)
  347. // before the focusing below,
  348. // otherwise we disable the view while setting it focused
  349. // (UpdateControls gets called within the SetFocus),
  350. // leading to VCL focus inconsistency with Windows,
  351. // and the view [anything actually] not getting focused after the session
  352. // is finally connected
  353. UpdateControls();
  354. DoLocalDefaultDirectory(OtherLocalDirView, WinConfiguration->ScpCommander.OtherLocalPanelLastPath);
  355. // If we do not call SetFocus on any control before DoShow,
  356. // no control will get focused on Login dialog
  357. // (HACK seems like a bug in VCL)
  358. if ((WinConfiguration->ScpCommander.CurrentPanel == osLocal) || !DirView(osOther)->Enabled)
  359. {
  360. LocalDirView->SetFocus();
  361. }
  362. else
  363. {
  364. DirView(osOther)->SetFocus();
  365. }
  366. TCustomScpExplorerForm::DoShow();
  367. // Need to do do this before the main window really displays.
  368. // Also the NoSession test in TCustomScpExplorerForm::CMShowingChanged rely on this happening here.
  369. if (ManagedSession == NULL)
  370. {
  371. TTerminalManager::Instance()->NewLocalSession();
  372. }
  373. AddStartupSequence(L"O");
  374. }
  375. //---------------------------------------------------------------------------
  376. void __fastcall TScpCommanderForm::NeedSession(bool Startup)
  377. {
  378. if (ManagedSession == NULL)
  379. {
  380. // in the LastTerminalClosed, new session should have already been created by GetReplacementForLastSession
  381. DebugAssert(Startup);
  382. TTerminalManager::Instance()->NewLocalSession();
  383. }
  384. TCustomScpExplorerForm::NeedSession(Startup);
  385. }
  386. //---------------------------------------------------------------------------
  387. TManagedTerminal * TScpCommanderForm::GetReplacementForLastSession()
  388. {
  389. return TTerminalManager::Instance()->NewLocalBrowser();
  390. }
  391. //---------------------------------------------------------------------------
  392. void TScpCommanderForm::NewTab(TOperationSide Side, bool AllowReverse)
  393. {
  394. if (Side == osCurrent)
  395. {
  396. bool Remote = WinConfiguration->DefaultToNewRemoteTab;
  397. if (IsKeyPressed(VK_CONTROL) && AllowReverse)
  398. {
  399. Remote = !Remote;
  400. }
  401. Side = Remote ? osRemote : osLocal;
  402. }
  403. if (Side == osRemote)
  404. {
  405. TCustomScpExplorerForm::NewTab();
  406. }
  407. else
  408. {
  409. TTerminalManager::Instance()->NewLocalSession(LocalDirView->PathName, OtherLocalDirView->PathName);
  410. }
  411. }
  412. //---------------------------------------------------------------------------
  413. Boolean __fastcall TScpCommanderForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  414. {
  415. #define FLAG ((TActionFlag)(Action->Tag))
  416. return
  417. TCustomScpExplorerForm::AllowedAction(Action, Allowed) &&
  418. // always require Commander flag
  419. (FLAG & afCommander) &&
  420. // if action is execution or update, we don't require any other flag
  421. // if we check for shortcut, we require proper dirview to be selected
  422. ((Allowed != aaShortCut) ||
  423. ((FLAG & afLocal) && (FCurrentSide == osLocal)) ||
  424. ((FLAG & afRemote) && (FCurrentSide == osRemote))
  425. );
  426. #undef FLAG
  427. }
  428. //---------------------------------------------------------------------------
  429. TCustomDirView * __fastcall TScpCommanderForm::DirView(TOperationSide Side)
  430. {
  431. Side = GetSide(Side);
  432. if (Side == osLocal)
  433. {
  434. return LocalDirView;
  435. }
  436. else if (DebugAlwaysTrue(Side == osRemote) && IsLocalBrowserMode())
  437. {
  438. return OtherLocalDirView;
  439. }
  440. else
  441. {
  442. return TCustomScpExplorerForm::DirView(Side);
  443. }
  444. }
  445. //---------------------------------------------------------------------------
  446. bool TScpCommanderForm::IsLocalBrowserMode()
  447. {
  448. return OtherLocalDirView->Visible;
  449. }
  450. //---------------------------------------------------------------------------
  451. TCustomDriveView * __fastcall TScpCommanderForm::DriveView(TOperationSide Side)
  452. {
  453. Side = GetSide(Side);
  454. if (Side == osLocal)
  455. {
  456. return LocalDriveView;
  457. }
  458. else if (DebugAlwaysTrue(Side == osRemote) && IsLocalBrowserMode())
  459. {
  460. return OtherLocalDriveView;
  461. }
  462. else
  463. {
  464. return TCustomScpExplorerForm::DriveView(Side);
  465. }
  466. }
  467. //---------------------------------------------------------------------------
  468. bool TScpCommanderForm::SupportsLocalBrowser()
  469. {
  470. return true;
  471. }
  472. //---------------------------------------------------------------------------
  473. bool TScpCommanderForm::IsSideLocalBrowser(TOperationSide Side)
  474. {
  475. return (GetSide(Side) == osLocal) || IsLocalBrowserMode();
  476. }
  477. //---------------------------------------------------------------------------
  478. TCustomDirView * TScpCommanderForm::GetCurrentLocalBrowser()
  479. {
  480. TOperationSide Side = GetSide(osCurrent);
  481. if (Side == osLocal)
  482. {
  483. return LocalDirView;
  484. }
  485. else if (DebugAlwaysTrue(Side == osRemote) && IsLocalBrowserMode())
  486. {
  487. return OtherLocalDirView;
  488. }
  489. else
  490. {
  491. DebugFail();
  492. Abort();
  493. return NULL;
  494. }
  495. }
  496. //---------------------------------------------------------------------------
  497. bool __fastcall TScpCommanderForm::DirViewEnabled(TOperationSide Side)
  498. {
  499. if (IsSideLocalBrowser(Side))
  500. {
  501. return true;
  502. }
  503. else
  504. {
  505. return TCustomScpExplorerForm::DirViewEnabled(Side);
  506. }
  507. }
  508. //---------------------------------------------------------------------------
  509. bool __fastcall TScpCommanderForm::IsFileControl(TObject * Control,
  510. TOperationSide Side)
  511. {
  512. return
  513. ((Side == osLocal) &&
  514. ((Control == LocalDirView) || (Control == LocalDriveView))) ||
  515. TCustomScpExplorerForm::IsFileControl(Control, Side);
  516. }
  517. //---------------------------------------------------------------------------
  518. void __fastcall TScpCommanderForm::ReloadLocalDirectory(const UnicodeString Directory)
  519. {
  520. if (Directory.IsEmpty() || SamePaths(Directory, LocalDirView->Path))
  521. {
  522. LocalDirView->ReloadDirectory();
  523. LocalDriveView->ValidateDirectory(LocalDriveView->Selected);
  524. }
  525. // we may postpone reload, when hidden, as an optimization
  526. if (Directory.IsEmpty() || SamePaths(Directory, OtherLocalDirView->Path))
  527. {
  528. OtherLocalDirView->ReloadDirectory();
  529. OtherLocalDriveView->ValidateDirectory(OtherLocalDriveView->Selected);
  530. }
  531. TCustomScpExplorerForm::ReloadLocalDirectory();
  532. }
  533. //---------------------------------------------------------------------------
  534. void __fastcall TScpCommanderForm::BatchStart(void *& Storage)
  535. {
  536. Storage = new bool;
  537. *static_cast<bool*>(Storage) = LocalDirView->WatchForChanges;
  538. LocalDirView->WatchForChanges = false;
  539. LocalDriveView->WatchDirectory = false;
  540. OtherLocalDirView->WatchForChanges = false;
  541. OtherLocalDriveView->WatchDirectory = false;
  542. TCustomScpExplorerForm::BatchStart(Storage);
  543. }
  544. //---------------------------------------------------------------------------
  545. void __fastcall TScpCommanderForm::BatchEnd(void * Storage)
  546. {
  547. TCustomScpExplorerForm::BatchEnd(Storage);
  548. DebugAssert(Storage != NULL);
  549. LocalDirView->WatchForChanges = *static_cast<bool*>(Storage);
  550. LocalDriveView->WatchDirectory = LocalDirView->WatchForChanges;
  551. OtherLocalDirView->WatchForChanges = LocalDirView->WatchForChanges;
  552. OtherLocalDriveView->WatchDirectory = LocalDirView->WatchForChanges;
  553. delete Storage;
  554. }
  555. //---------------------------------------------------------------------------
  556. void __fastcall TScpCommanderForm::StartingWithoutSession()
  557. {
  558. TCustomScpExplorerForm::StartingWithoutSession();
  559. LocalDefaultDirectory();
  560. }
  561. //---------------------------------------------------------------------------
  562. void TScpCommanderForm::RestoreSessionLocalDirView(
  563. TDirView * ALocalDirView, const UnicodeString & LocalDirectory, TObject * State)
  564. {
  565. ALocalDirView->AnnounceState(State);
  566. try
  567. {
  568. // we will load completely different directory, so particularly
  569. // do not attempt to select previously selected directory
  570. ALocalDirView->ContinueSession(false);
  571. // reset home directory
  572. ALocalDirView->HomeDirectory = L"";
  573. if (!LocalDirectory.IsEmpty() &&
  574. (FFirstTerminal || !WinConfiguration->ScpCommander.PreserveLocalDirectory || ManagedSession->LocalBrowser))
  575. {
  576. try
  577. {
  578. ALocalDirView->Path = LocalDirectory;
  579. }
  580. catch(Exception & E)
  581. {
  582. if (!ManagedSession->SessionData->UpdateDirectories)
  583. {
  584. ManagedSession->ShowExtendedException(&E);
  585. }
  586. else
  587. {
  588. ALocalDirView->OpenFallbackPath(LocalDirectory);
  589. }
  590. }
  591. }
  592. }
  593. __finally
  594. {
  595. ALocalDirView->AnnounceState(NULL);
  596. }
  597. }
  598. //---------------------------------------------------------------------------
  599. void __fastcall TScpCommanderForm::SessionChanged(bool Replaced)
  600. {
  601. NonVisualDataModule->SynchronizeBrowsingAction2->Checked = false;
  602. TCustomScpExplorerForm::SessionChanged(Replaced);
  603. if (ManagedSession != NULL)
  604. {
  605. bool RestoreState =
  606. WinConfiguration->PreservePanelState &&
  607. (!WinConfiguration->ScpCommander.PreserveLocalDirectory || ManagedSession->LocalBrowser);
  608. RestoreSessionLocalDirView(
  609. LocalDirView, ManagedSession->StateData->LocalDirectory, ManagedSession->LocalExplorerState);
  610. if (ManagedSession->LocalBrowser)
  611. {
  612. RestoreSessionLocalDirView(
  613. OtherLocalDirView, ManagedSession->StateData->OtherLocalDirectory, ManagedSession->OtherLocalExplorerState);
  614. }
  615. FFirstTerminal = false;
  616. // Happens when opening a connection from a command-line (StartingWithoutSession was not called),
  617. // which does not have a local directory set yet.
  618. // Or when starting with vanila local browser.
  619. if (LocalDirView->Path.IsEmpty())
  620. {
  621. LocalDefaultDirectory();
  622. }
  623. if (WinConfiguration->DefaultDirIsHome &&
  624. !ManagedSession->SessionData->UpdateDirectories &&
  625. DebugAlwaysTrue(!ManagedSession->LocalBrowser))
  626. {
  627. LocalDirView->HomeDirectory = ManagedSession->SessionData->LocalDirectoryExpanded;
  628. }
  629. if (RestoreState)
  630. {
  631. LocalDirView->RestoreState(ManagedSession->LocalExplorerState);
  632. if (ManagedSession->LocalBrowser)
  633. {
  634. OtherLocalDirView->RestoreState(ManagedSession->OtherLocalExplorerState);
  635. }
  636. NonVisualDataModule->SynchronizeBrowsingAction2->Checked = ManagedSession->StateData->SynchronizeBrowsing;
  637. }
  638. if (ManagedSession->LocalBrowser)
  639. {
  640. // Particularly, when switching from a remote to a local-local session,
  641. // the other local dir view path may not change at all,
  642. // so the path combo box would retain the remote path.
  643. UpdateRemotePathComboBox(false);
  644. }
  645. }
  646. }
  647. //---------------------------------------------------------------------------
  648. void __fastcall TScpCommanderForm::DoLocalDefaultDirectory(TDirView * DirView, const UnicodeString & LastPath)
  649. {
  650. bool DocumentsDir = true;
  651. if (!LastPath.IsEmpty())
  652. {
  653. try
  654. {
  655. DirView->Path = LastPath;
  656. DocumentsDir = false;
  657. }
  658. catch (...)
  659. {
  660. }
  661. }
  662. if (DocumentsDir)
  663. {
  664. try
  665. {
  666. DirView->HomeDirectory = L"";
  667. UnicodeString HomeDrive = DriveInfo->GetDriveKey(DirView->HomeDirectory);
  668. if (DriveInfo->Get(HomeDrive)->DriveType == DRIVE_REMOTE)
  669. {
  670. DirView->Path = DriveInfo->AnyValidPath();
  671. }
  672. else
  673. {
  674. DirView->ExecuteHomeDirectory();
  675. }
  676. }
  677. catch(Exception & E)
  678. {
  679. ShowExtendedException(NULL, &E);
  680. DirView->Path = ExtractFilePath(Application->ExeName);
  681. }
  682. }
  683. }
  684. //---------------------------------------------------------------------------
  685. void __fastcall TScpCommanderForm::LocalDefaultDirectory()
  686. {
  687. DoLocalDefaultDirectory(LocalDirView, WinConfiguration->ScpCommander.LocalPanel.LastPath);
  688. }
  689. //---------------------------------------------------------------------------
  690. void __fastcall TScpCommanderForm::ConfigurationChanged()
  691. {
  692. TCustomScpExplorerForm::ConfigurationChanged();
  693. if (WinConfiguration->DefaultDirIsHome && (ManagedSession != NULL) &&
  694. !ManagedSession->SessionData->UpdateDirectories)
  695. {
  696. LocalDirView->HomeDirectory = ManagedSession->SessionData->LocalDirectoryExpanded;
  697. }
  698. else
  699. {
  700. LocalDirView->HomeDirectory = L"";
  701. }
  702. LocalDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  703. LocalDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  704. OtherLocalDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  705. OtherLocalDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  706. LocalDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  707. LocalDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  708. OtherLocalDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  709. OtherLocalDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  710. LocalDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  711. OtherLocalDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  712. LocalDirView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  713. LocalDriveView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  714. OtherLocalDirView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  715. OtherLocalDriveView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  716. LocalDirView->NortonLike = WinConfiguration->ScpCommander.NortonLikeMode;
  717. OtherLocalDirView->NortonLike = WinConfiguration->ScpCommander.NortonLikeMode;
  718. RemoteDirView->NortonLike = WinConfiguration->ScpCommander.NortonLikeMode;
  719. LocalDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  720. LocalDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  721. OtherLocalDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  722. OtherLocalDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  723. LocalDirView->AlwaysSortDirectoriesByName = WinConfiguration->AlwaysSortDirectoriesByName;
  724. OtherLocalDirView->AlwaysSortDirectoriesByName = WinConfiguration->AlwaysSortDirectoriesByName;
  725. LocalDirView->TimeoutShellIconRetrieval = WinConfiguration->TimeoutShellIconRetrieval;
  726. LocalDirView->UseIconUpdateThread = WinConfiguration->UseIconUpdateThread;
  727. OtherLocalDirView->TimeoutShellIconRetrieval = WinConfiguration->TimeoutShellIconRetrieval;
  728. OtherLocalDirView->UseIconUpdateThread = WinConfiguration->UseIconUpdateThread;
  729. UpdateRowSelect(LocalDirView);
  730. UpdateRowSelect(OtherLocalDirView);
  731. // See also LocalDirViewDDTargetHasDropHandler
  732. LocalDirView->DragDropFilesEx->ShellExtensions->DropHandler = !WinConfiguration->DDFakeFile;
  733. LocalDriveView->DragDropFilesEx->ShellExtensions->DropHandler = !WinConfiguration->DDFakeFile;
  734. OtherLocalDirView->DragDropFilesEx->ShellExtensions->DropHandler = !WinConfiguration->DDFakeFile;
  735. OtherLocalDriveView->DragDropFilesEx->ShellExtensions->DropHandler = !WinConfiguration->DDFakeFile;
  736. if (Panel(true)->Left > Panel(false)->Left)
  737. {
  738. DisableAlign();
  739. try
  740. {
  741. int AWidth = ClientWidth;
  742. Panel(false)->Align = alClient;
  743. // In bidi mode it gets swapped to alRight, what does not work with the rest of this logic
  744. Splitter->Align = alLeft;
  745. Panel(true)->Align = alLeft;
  746. TControl * ControlsOrder[] =
  747. { Panel(true), Splitter, Panel(false) };
  748. SetHorizontalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  749. Panel(true)->TabOrder = 0;
  750. Panel(false)->TabOrder = 1;
  751. ClientWidth = AWidth;
  752. LeftPanelWidth = FLastLeftPanelWidth;
  753. }
  754. __finally
  755. {
  756. EnableAlign();
  757. }
  758. int LocalIndex = MenuToolbar->Items->IndexOf(LocalMenuButton);
  759. int RemoteIndex = MenuToolbar->Items->IndexOf(RemoteMenuButton);
  760. MenuToolbar->Items->Move(LocalIndex, RemoteIndex);
  761. RemoteIndex = MenuToolbar->Items->IndexOf(RemoteMenuButton);
  762. MenuToolbar->Items->Move(RemoteIndex, LocalIndex);
  763. SWAP(TShortCut, NonVisualDataModule->LocalChangePathAction2->ShortCut, NonVisualDataModule->RemoteChangePathAction2->ShortCut);
  764. SWAP(UnicodeString, NonVisualDataModule->CommanderLocalPanelAction->Caption, NonVisualDataModule->CommanderRemotePanelAction->Caption);
  765. SWAP(UnicodeString, NonVisualDataModule->CommanderLocalPanelAction->Hint, NonVisualDataModule->CommanderRemotePanelAction->Hint);
  766. SWAP(int, NonVisualDataModule->LocalLocalCopyAction->ImageIndex, NonVisualDataModule->LocalOtherCopyAction->ImageIndex);
  767. SWAP(int, NonVisualDataModule->LocalLocalMoveAction->ImageIndex, NonVisualDataModule->LocalOtherMoveAction->ImageIndex);
  768. }
  769. if ((RemoteDrivePanel->Align == alLeft) != WinConfiguration->ScpCommander.TreeOnLeft)
  770. {
  771. TScpCommanderPanelConfiguration LocalPanel = WinConfiguration->ScpCommander.LocalPanel;
  772. TScpCommanderPanelConfiguration RemotePanel = WinConfiguration->ScpCommander.RemotePanel;
  773. bool TreeOnLeft = WinConfiguration->ScpCommander.TreeOnLeft;
  774. // save value only if it was set yet
  775. if (FPanelsRestored)
  776. {
  777. if (TreeOnLeft)
  778. {
  779. // want to be on left, so it is on top, saving height
  780. LocalPanel.DriveViewHeight = LocalDriveView->Height;
  781. RemotePanel.DriveViewHeight = RemoteDrivePanel->Height;
  782. }
  783. else
  784. {
  785. LocalPanel.DriveViewWidth = LocalDriveView->Width;
  786. RemotePanel.DriveViewWidth = RemoteDrivePanel->Width;
  787. }
  788. }
  789. TAlign NonClientAlign = (TreeOnLeft ? alLeft : alTop);
  790. // VCL adjusts cursors only between crVSplit and crHSplit,
  791. // See TSplitter.RequestAlign
  792. TCursor SplitterCursor = (TreeOnLeft ? crSizeWE : crSizeNS);
  793. LocalDriveView->Align = NonClientAlign;
  794. OtherLocalDriveView->Align = NonClientAlign;
  795. LocalPanelSplitter->Align = NonClientAlign;
  796. LocalPanelSplitter->Cursor = SplitterCursor;
  797. RemoteDrivePanel->Align = NonClientAlign;
  798. RemotePanelSplitter->Align = NonClientAlign;
  799. RemotePanelSplitter->Cursor = SplitterCursor;
  800. FixControlsPlacement();
  801. if (TreeOnLeft)
  802. {
  803. LocalDriveView->Width = LocalPanel.DriveViewWidth;
  804. RemoteDrivePanel->Width = RemotePanel.DriveViewWidth;
  805. }
  806. else
  807. {
  808. LocalDriveView->Height = LocalPanel.DriveViewHeight;
  809. RemoteDrivePanel->Height = RemotePanel.DriveViewHeight;
  810. }
  811. // in case it triggers config-changed event (does not),
  812. // make sure it does only after we apply the TreeOnLeft change to avoid endless recursion
  813. WinConfiguration->ScpCommander.LocalPanel = LocalPanel;
  814. WinConfiguration->ScpCommander.RemotePanel = RemotePanel;
  815. }
  816. if (FExplorerKeyboardShortcuts != WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  817. {
  818. SetShortcuts();
  819. }
  820. }
  821. //---------------------------------------------------------------------------
  822. void __fastcall TScpCommanderForm::SetShortcuts()
  823. {
  824. // set common norton shorcuts to our actions
  825. NonVisualDataModule->CommanderShortcuts();
  826. FExplorerKeyboardShortcuts = WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts;
  827. }
  828. //---------------------------------------------------------------------------
  829. TPanel * __fastcall TScpCommanderForm::Panel(bool Left)
  830. {
  831. bool SwappedPanels = WinConfiguration->ScpCommander.SwappedPanels;
  832. if (IsRightToLeft())
  833. {
  834. SwappedPanels = !SwappedPanels;
  835. }
  836. return (SwappedPanels == Left ? RemotePanel : LocalPanel);
  837. }
  838. //---------------------------------------------------------------------------
  839. TPanel * __fastcall TScpCommanderForm::CurrentPanel()
  840. {
  841. return (FCurrentSide == osLocal ? LocalPanel : RemotePanel);
  842. }
  843. //---------------------------------------------------------------------------
  844. void __fastcall TScpCommanderForm::SetLeftPanelWidth(double value)
  845. {
  846. double Total = LocalPanel->Width + RemotePanel->Width;
  847. FLeftPanelWidth = value;
  848. if (value * Total != Panel(true)->Width)
  849. {
  850. Panel(true)->Width = static_cast<int>(value * Total);
  851. UpdateControls();
  852. }
  853. }
  854. //---------------------------------------------------------------------------
  855. double __fastcall TScpCommanderForm::GetLeftPanelWidth()
  856. {
  857. return FLeftPanelWidth;
  858. }
  859. //---------------------------------------------------------------------------
  860. void __fastcall TScpCommanderForm::SplitterMoved(TObject * /*Sender*/)
  861. {
  862. double Left = Panel(true)->Width;
  863. double Total = LocalPanel->Width + RemotePanel->Width;
  864. FLeftPanelWidth = Left / Total;
  865. FLastLeftPanelWidth = LeftPanelWidth;
  866. UpdateControls();
  867. }
  868. //---------------------------------------------------------------------------
  869. void __fastcall TScpCommanderForm::SplitterCanResize(TObject * /*Sender*/,
  870. int &NewSize, bool & /*Accept*/)
  871. {
  872. // When splitter is drag so far to right, that width contraint of remote panel would
  873. // be violated, it doesn't stop, but extend form width.
  874. // Following prevents this behavior.
  875. if (ClientWidth - NewSize - Splitter->Width < Panel(false)->Constraints->MinWidth)
  876. NewSize = (ClientWidth - Panel(false)->Constraints->MinWidth - Splitter->Width);
  877. }
  878. //---------------------------------------------------------------------------
  879. void __fastcall TScpCommanderForm::SplitterDblClick(TObject * /*Sender*/)
  880. {
  881. LeftPanelWidth = 0.5;
  882. }
  883. //---------------------------------------------------------------------------
  884. void __fastcall TScpCommanderForm::PanelSplitterDblClick(TObject * Sender)
  885. {
  886. TSplitter * Splitter = dynamic_cast<TSplitter *>(Sender);
  887. DebugAssert(Splitter != NULL);
  888. TControl * DriveView;
  889. TControl * OtherDriveView;
  890. if (Splitter == LocalPanelSplitter)
  891. {
  892. DriveView = LocalDriveView;
  893. OtherDriveView = RemoteDrivePanel;
  894. }
  895. else
  896. {
  897. DriveView = RemoteDrivePanel;
  898. OtherDriveView = LocalDriveView;
  899. }
  900. bool TreeOnLeft = WinConfiguration->ScpCommander.TreeOnLeft;
  901. DebugAssert(DriveView->Visible);
  902. if (OtherDriveView->Visible)
  903. {
  904. if (TreeOnLeft)
  905. {
  906. DriveView->Width = OtherDriveView->Width;
  907. }
  908. else
  909. {
  910. DriveView->Height = OtherDriveView->Height;
  911. }
  912. }
  913. else
  914. {
  915. if (TreeOnLeft)
  916. {
  917. OtherDriveView->Width = DriveView->Width;
  918. }
  919. else
  920. {
  921. OtherDriveView->Height = DriveView->Height;
  922. }
  923. OtherDriveView->Visible = true;
  924. }
  925. FixControlsPlacement();
  926. }
  927. //---------------------------------------------------------------------------
  928. void __fastcall TScpCommanderForm::SetToolbar2ItemAction(TTBXItem * Item, TBasicAction * Action)
  929. {
  930. if (Item->Action != Action)
  931. {
  932. Item->Action = Action;
  933. UpdateToolbar2ItemCaption(Item);
  934. }
  935. }
  936. //---------------------------------------------------------------------------
  937. void __fastcall TScpCommanderForm::UpdateControls()
  938. {
  939. // Before TCustomScpExplorerForm disables them (when disconnecting)
  940. bool DirViewWasFocused = DirView(osOther)->Focused();
  941. bool DriveViewWasFocused = DriveView(osOther)->Focused();
  942. // When implicitly connecting a not-yet-connected session by switching to its tab opened with workspace,
  943. // Terminal property is still NULL, but ActiveTerminal is already set.
  944. // Had we used Terminal for the test, the window would switch to local-local mode temporarily while session is opening.
  945. bool HasTerminal = (TTerminalManager::Instance()->ActiveTerminal != NULL);
  946. // Set asap, so that TCustomScpExplorerForm already knows if we are in local-local mode.
  947. RemoteDirView->Visible = HasTerminal;
  948. RemoteDriveView->Visible = HasTerminal;
  949. OtherLocalDirView->Visible = !HasTerminal;
  950. OtherLocalDriveView->Visible = !HasTerminal;
  951. TCustomScpExplorerForm::UpdateControls();
  952. UnicodeString SplitterLongHint = Splitter->Hint;
  953. int P = SplitterLongHint.Pos(L"|");
  954. if (P == 0)
  955. {
  956. P = SplitterLongHint.Pos(L"\n");
  957. }
  958. SplitterLongHint.Delete(1, P);
  959. Splitter->Hint = FORMAT(L"%0.0f%%\n%s", (LeftPanelWidth*100, SplitterLongHint));
  960. UnicodeString ACommandLinePromptLabel = LoadStr(COMMAND_LINE_LABEL) + " " +
  961. (!IsSideLocalBrowser(FCurrentSide) ? L"$" : L">");
  962. if (CommandLinePromptLabel->Caption != ACommandLinePromptLabel)
  963. {
  964. CommandLinePromptLabel->Caption = ACommandLinePromptLabel;
  965. // command line combo width needs to be updated as caption width has probably changed
  966. ToolBarResize(CommandLineToolbar);
  967. }
  968. LocalDirView->DarkMode = WinConfiguration->UseDarkTheme();
  969. LocalDriveView->DarkMode = LocalDirView->DarkMode;
  970. OtherLocalDirView->DarkMode = LocalDirView->DarkMode;
  971. OtherLocalDriveView->DarkMode = LocalDirView->DarkMode;
  972. LocalDirView->Color = PanelColor();
  973. LocalDriveView->Color = LocalDirView->Color;
  974. OtherLocalDirView->Color = LocalDirView->Color;
  975. OtherLocalDriveView->Color = LocalDirView->Color;
  976. LocalDirView->Font->Color = GetWindowTextColor(LocalDirView->Color);
  977. LocalDriveView->Font->Color = LocalDirView->Font->Color;
  978. OtherLocalDirView->Font->Color = LocalDirView->Font->Color;
  979. OtherLocalDriveView->Font->Color = LocalDirView->Font->Color;
  980. if (IsLocalBrowserMode())
  981. {
  982. CurrentCopyItem->Visible = false;
  983. if (FCurrentSide == osLocal)
  984. {
  985. CurrentCopyToItem->Action = NonVisualDataModule->LocalLocalCopyAction;
  986. CurrentMoveToItem->Action = NonVisualDataModule->LocalLocalMoveAction;
  987. }
  988. else
  989. {
  990. CurrentCopyToItem->Action = NonVisualDataModule->LocalOtherCopyAction;
  991. CurrentMoveToItem->Action = NonVisualDataModule->LocalOtherMoveAction;
  992. }
  993. LocalCopyItem->Action = NonVisualDataModule->LocalLocalCopyAction;
  994. LocalMoveItem->Action = NonVisualDataModule->LocalLocalMoveAction;
  995. RemoteCopyItem->Action = NonVisualDataModule->LocalOtherCopyAction;
  996. RemoteMoveItem->Action = NonVisualDataModule->LocalOtherMoveAction;
  997. SetToolbar2ItemAction(CurrentCopyToolbar2Item, CurrentCopyToItem->Action);
  998. SetToolbar2ItemAction(CurrentMoveToolbar2Item, CurrentMoveToItem->Action);
  999. }
  1000. else
  1001. {
  1002. CurrentCopyItem->Visible = true;
  1003. CurrentCopyToItem->Action = NonVisualDataModule->RemoteCopyToAction;
  1004. CurrentMoveToItem->Action = NonVisualDataModule->RemoteMoveToAction;
  1005. if (IsSideLocalBrowser(FCurrentSide))
  1006. {
  1007. CurrentCopyItem->Action = NonVisualDataModule->LocalCopyAction;
  1008. CurrentMoveItem->Action = NonVisualDataModule->LocalMoveAction;
  1009. CurrentCopyNonQueueItem->Action = NonVisualDataModule->LocalCopyNonQueueAction;
  1010. CurrentCopyQueueItem->Action = NonVisualDataModule->LocalCopyQueueAction;
  1011. }
  1012. else
  1013. {
  1014. CurrentCopyItem->Action = NonVisualDataModule->RemoteCopyAction;
  1015. CurrentMoveItem->Action = NonVisualDataModule->RemoteMoveAction;
  1016. CurrentCopyNonQueueItem->Action = NonVisualDataModule->RemoteCopyNonQueueAction;
  1017. CurrentCopyQueueItem->Action = NonVisualDataModule->RemoteCopyQueueAction;
  1018. }
  1019. LocalCopyItem->Action = NonVisualDataModule->LocalCopyAction;
  1020. LocalMoveItem->Action = NonVisualDataModule->LocalMoveAction;
  1021. RemoteCopyItem->Action = NonVisualDataModule->RemoteCopyAction;
  1022. RemoteMoveItem->Action = NonVisualDataModule->RemoteMoveAction;
  1023. SetToolbar2ItemAction(CurrentCopyToolbar2Item, CurrentCopyItem->Action);
  1024. SetToolbar2ItemAction(CurrentMoveToolbar2Item, CurrentMoveItem->Action);
  1025. }
  1026. CommandLineCombo->Enabled = IsSideLocalBrowser(FCurrentSide) || CanConsole();
  1027. CommandLinePromptLabel->Enabled = CommandLineCombo->Enabled;
  1028. // Ad hoc hack to disable the drop down menu, when all its items (and all other buttons on the toolbar) are disabled,
  1029. // otherwise it shines too much on the toolbar.
  1030. RemoteNewSubmenuItem->Enabled = DirViewEnabled(osRemote);
  1031. bool LocalOnLeft = (Panel(true) == LocalPanel);
  1032. LocalMenuButton->Caption = LoadStr(HasTerminal ? LOCAL_MENU_CAPTION : (LocalOnLeft ? LEFT_MENU_CAPTION : RIGHT_MENU_CAPTION));
  1033. RemoteMenuButton->Caption = LoadStr(HasTerminal ? REMOTE_MENU_CAPTION : (LocalOnLeft ? RIGHT_MENU_CAPTION : LEFT_MENU_CAPTION));
  1034. if (DirViewWasFocused)
  1035. {
  1036. if (DirView(osOther)->Enabled)
  1037. {
  1038. DirView(osOther)->SetFocus();
  1039. }
  1040. else
  1041. {
  1042. LocalDirView->SetFocus();
  1043. }
  1044. }
  1045. if (DriveViewWasFocused)
  1046. {
  1047. if (DriveView(osOther)->Enabled)
  1048. {
  1049. DriveView(osOther)->SetFocus();
  1050. }
  1051. else if (LocalDriveView->Visible)
  1052. {
  1053. LocalDriveView->SetFocus();
  1054. }
  1055. else
  1056. {
  1057. // Switching to a disconnected session with local drive view hidden - fallback to the local dir view (should always be visible)
  1058. DebugAssert(LocalDirView->Visible);
  1059. LocalDirView->SetFocus();
  1060. }
  1061. }
  1062. if (RemotePathLabel->FocusControl != DirView(osOther))
  1063. {
  1064. if (DebugAlwaysTrue(RemotePathLabel->FocusControl != NULL))
  1065. {
  1066. dynamic_cast<TCustomDirView *>(RemotePathLabel->FocusControl)->PathLabel = NULL;
  1067. }
  1068. DirView(osOther)->PathLabel = RemotePathLabel;
  1069. RemotePathLabel->UnixPath = !IsSideLocalBrowser(osOther);
  1070. DirView(osOther)->UpdateStatusBar();
  1071. }
  1072. }
  1073. //---------------------------------------------------------------------------
  1074. void __fastcall TScpCommanderForm::ChangePath(TOperationSide Side)
  1075. {
  1076. DebugAssert((Side == osLocal) || (Side == osRemote));
  1077. TTBXComboBoxItem * PathComboBox;
  1078. if (Side == osLocal)
  1079. {
  1080. PathComboBox = LocalPathComboBox;
  1081. }
  1082. else
  1083. {
  1084. PathComboBox = RemotePathComboBox;
  1085. }
  1086. ClickToolbarItem(PathComboBox, false);
  1087. }
  1088. //---------------------------------------------------------------------------
  1089. TControl * __fastcall TScpCommanderForm::GetComponent(Byte Component)
  1090. {
  1091. switch (Component) {
  1092. case fcToolBar2: return Toolbar2Toolbar; // name changed to enforce change of default visibility
  1093. case fcStatusBar: return StatusBar;
  1094. case fcLocalStatusBar: return LocalStatusBar;
  1095. case fcRemoteStatusBar: return RemoteStatusBar;
  1096. case fcCommandLinePanel: return CommandLineToolbar;
  1097. case fcLocalTree: return LocalDriveView;
  1098. case fcSessionToolbar: return SessionToolbar2;
  1099. case fcCustomCommandsBand: return CustomCommandsToolbar;
  1100. case fcColorMenu: return reinterpret_cast<TControl*>(ColorMenuItem);
  1101. case fcTransferDropDown: return reinterpret_cast<TControl*>(TransferDropDown);
  1102. case fcTransferList: return reinterpret_cast<TControl*>(TransferList);
  1103. case fcTransferLabel: return reinterpret_cast<TControl*>(TransferLabel);
  1104. case fcLocalPopup: return reinterpret_cast<TControl *>(NonVisualDataModule->LocalFilePopup);
  1105. case fcRemotePathComboBox: return reinterpret_cast<TControl*>(RemotePathComboBox);
  1106. case fcMenu: return MenuToolbar;
  1107. case fcCommanderMenuBand: return MenuToolbar;
  1108. case fcCommanderSessionBand: return SessionToolbar2;
  1109. case fcCommanderPreferencesBand: return PreferencesToolbar;
  1110. case fcCommanderSortBand: return SortToolbar;
  1111. case fcCommanderCommandsBand: return CommandsToolbar;
  1112. case fcCommanderUpdatesBand: return UpdatesToolbar;
  1113. case fcCommanderTransferBand: return TransferToolbar;
  1114. case fcCommanderCustomCommandsBand: return CustomCommandsToolbar;
  1115. case fcCommanderLocalHistoryBand: return LocalHistoryToolbar;
  1116. case fcCommanderLocalNavigationBand: return LocalNavigationToolbar;
  1117. case fcCommanderLocalFileBand: return LocalFileToolbar;
  1118. case fcCommanderLocalSelectionBand: return LocalSelectionToolbar;
  1119. case fcCommanderRemoteHistoryBand: return RemoteHistoryToolbar;
  1120. case fcCommanderRemoteNavigationBand: return RemoteNavigationToolbar;
  1121. case fcCommanderRemoteFileBand: return RemoteFileToolbar;
  1122. case fcCommanderRemoteSelectionBand: return RemoteSelectionToolbar;
  1123. default: return TCustomScpExplorerForm::GetComponent(Component);
  1124. }
  1125. }
  1126. //---------------------------------------------------------------------------
  1127. void __fastcall TScpCommanderForm::FixControlsPlacement()
  1128. {
  1129. TCustomScpExplorerForm::FixControlsPlacement();
  1130. QueueSeparatorPanel->Visible = QueuePanel->Visible;
  1131. LocalPanelSplitter->Visible = LocalDriveView->Visible;
  1132. TControl * ControlsOrder[] =
  1133. { BottomDock, QueueSeparatorPanel, QueueSplitter, QueuePanel, StatusBar };
  1134. SetVerticalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  1135. TControl * LocalControlsOrder[] =
  1136. { LocalTopDock, LocalPathLabel, LocalDriveView, LocalPanelSplitter,
  1137. LocalDirView, LocalBottomDock, LocalStatusBar };
  1138. SetVerticalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  1139. SetHorizontalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  1140. TControl * RemoteControlsOrder[] =
  1141. { RemoteTopDock, RemotePathLabel, RemoteDrivePanel, RemotePanelSplitter,
  1142. RemoteDirPanel, RemoteBottomDock, RemoteStatusBar };
  1143. SetVerticalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  1144. SetHorizontalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  1145. MakeFocusedItemVisible(LocalDirView);
  1146. MakeFocusedItemVisible(OtherLocalDirView);
  1147. }
  1148. //---------------------------------------------------------------------------
  1149. bool __fastcall TScpCommanderForm::GetHasDirView(TOperationSide Side)
  1150. {
  1151. return TCustomScpExplorerForm::GetHasDirView(Side) || (Side == osLocal);
  1152. }
  1153. //---------------------------------------------------------------------------
  1154. void __fastcall TScpCommanderForm::CompareDirectories()
  1155. {
  1156. LocalDirView->CompareFiles(DirView(osOther), false,
  1157. WinConfiguration->ScpCommander.CompareCriterias());
  1158. DirView(osOther)->CompareFiles(LocalDirView, false,
  1159. WinConfiguration->ScpCommander.CompareCriterias());
  1160. if (LocalDirView->SelCount + DirView(osOther)->SelCount == 0)
  1161. {
  1162. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  1163. MessageDialog(Message, qtInformation, qaOK, HELP_COMPARE_NO_DIFFERENCES);
  1164. }
  1165. }
  1166. //---------------------------------------------------------------------------
  1167. void __fastcall TScpCommanderForm::SynchronizeDirectories()
  1168. {
  1169. DebugAssert(!IsLocalBrowserMode());
  1170. UnicodeString LocalDirectory = LocalDirView->PathName;
  1171. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  1172. DoSynchronizeDirectories(LocalDirectory, RemoteDirectory, -1);
  1173. }
  1174. //---------------------------------------------------------------------------
  1175. void __fastcall TScpCommanderForm::FullSynchronizeDirectories()
  1176. {
  1177. DebugAssert(!IsLocalBrowserMode());
  1178. UnicodeString LocalDirectory = LocalDirView->PathName;
  1179. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  1180. bool SaveMode = !(GUIConfiguration->SynchronizeModeAuto < 0);
  1181. TSynchronizeMode Mode =
  1182. (SaveMode ? (TSynchronizeMode)GUIConfiguration->SynchronizeModeAuto :
  1183. ((FCurrentSide == osLocal) ? smRemote : smLocal));
  1184. int Params = GUIConfiguration->SynchronizeParams;
  1185. if (DoFullSynchronizeDirectories(LocalDirectory, RemoteDirectory, Mode, Params, SaveMode, -1) >= 0)
  1186. {
  1187. if (SaveMode)
  1188. {
  1189. GUIConfiguration->SynchronizeModeAuto = Mode;
  1190. }
  1191. }
  1192. }
  1193. //---------------------------------------------------------------------------
  1194. void __fastcall TScpCommanderForm::ExploreLocalDirectory(TOperationSide Side)
  1195. {
  1196. DebugAssert(IsSideLocalBrowser(Side));
  1197. OpenFolderInExplorer(DirView(Side)->Path);
  1198. }
  1199. //---------------------------------------------------------------------------
  1200. void __fastcall TScpCommanderForm::LocalDirViewExecFile(TObject *Sender,
  1201. TListItem *Item, bool &AllowExec)
  1202. {
  1203. DebugAssert(Item);
  1204. TDirView * ADirView = DebugNotNull(dynamic_cast<TDirView *>(Sender));
  1205. if ((UpperCase(PFileRec(Item->Data)->FileExt) == L"LNK") &&
  1206. DirectoryExists(ApiPath(ResolveFileShortCut(ADirView->ItemFullFileName(Item), true))))
  1207. {
  1208. AllowExec = true;
  1209. }
  1210. else
  1211. {
  1212. DoDirViewExecFile(Sender, Item, AllowExec);
  1213. }
  1214. }
  1215. //---------------------------------------------------------------------------
  1216. void __fastcall TScpCommanderForm::LocalFileControlDDDragEnter(TObject *Sender,
  1217. IDataObject *DataObj, int grfKeyState, TPoint &Point, int &dwEffect,
  1218. bool &Accept)
  1219. {
  1220. // LocalDirViewDDDragEnter is duplication of
  1221. // TCustomScpExplorerForm::DirViewDDDragEnter, but it differs in
  1222. // literal type of 'DataObj' parameter. The actual type is however the same.
  1223. FileControlDDDragEnter(Sender, DataObj, grfKeyState, Point, dwEffect, Accept);
  1224. }
  1225. //---------------------------------------------------------------------------
  1226. bool __fastcall TScpCommanderForm::PanelOperation(TOperationSide Side,
  1227. bool DragDrop)
  1228. {
  1229. return TCustomScpExplorerForm::PanelOperation(Side, DragDrop) ||
  1230. (DropSourceControl == LocalDirView);
  1231. }
  1232. //---------------------------------------------------------------------------
  1233. void __fastcall TScpCommanderForm::FileOperationProgress(
  1234. TFileOperationProgressType & ProgressData)
  1235. {
  1236. // Heuristic: When operation finishes and DD target is local dir view,
  1237. // we suppose that drag&drop download finished, so local dir view should be
  1238. // reloaded
  1239. if (!ProgressData.InProgress && FProgressForm &&
  1240. IsFileControl(FDDTargetControl, osLocal) &&
  1241. ProgressData.IsTransfer())
  1242. {
  1243. ReloadLocalDirectory();
  1244. }
  1245. TCustomScpExplorerForm::FileOperationProgress(ProgressData);
  1246. }
  1247. //---------------------------------------------------------------------------
  1248. UnicodeString __fastcall TScpCommanderForm::ChangeFilePath(UnicodeString Path, TOperationSide Side)
  1249. {
  1250. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  1251. UnicodeString Result;
  1252. while (!Path.IsEmpty())
  1253. {
  1254. int P = Path.Pos(Side == osLocal ? L'\\' : L'/');
  1255. if (P > 0)
  1256. {
  1257. Result += Terminal->ChangeFileName(&CopyParams, Path.SubString(1, P - 1), Side, false) +
  1258. (Side == osLocal ? L'/' : L'\\');
  1259. Path.Delete(1, P);
  1260. }
  1261. else
  1262. {
  1263. Result += Terminal->ChangeFileName(&CopyParams, Path, osLocal, false);
  1264. Path = L"";
  1265. }
  1266. }
  1267. return Result;
  1268. }
  1269. //---------------------------------------------------------------------------
  1270. void __fastcall TScpCommanderForm::CreateRemoteDirectory(const UnicodeString & Path)
  1271. {
  1272. UnicodeString Dir = UnixExtractFileDir(Path);
  1273. if (!IsUnixRootPath(Dir) && !Terminal->FileExists(Dir))
  1274. {
  1275. CreateRemoteDirectory(Dir);
  1276. }
  1277. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  1278. TCustomScpExplorerForm::CreateRemoteDirectory(Path, Properties);
  1279. }
  1280. //---------------------------------------------------------------------------
  1281. void __fastcall TScpCommanderForm::SynchronizeBrowsingLocal(
  1282. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  1283. {
  1284. DebugAssert(!IsLocalBrowserMode());
  1285. Terminal->ExceptionOnFail = true;
  1286. TStrings * Paths = new TStringList();
  1287. try
  1288. {
  1289. Paths->Add(IncludeTrailingBackslash(PrevPath));
  1290. Paths->Add(IncludeTrailingBackslash(LocalDirView->Path));
  1291. UnicodeString CommonPath;
  1292. if (ExtractCommonPath(Paths, CommonPath))
  1293. {
  1294. PrevPath = IncludeTrailingBackslash(PrevPath);
  1295. CommonPath = IncludeTrailingBackslash(CommonPath);
  1296. NewPath = RemoteDirView->Path;
  1297. while (!SamePaths(PrevPath, CommonPath))
  1298. {
  1299. if (NewPath == UnixExcludeTrailingBackslash(NewPath))
  1300. {
  1301. Abort();
  1302. }
  1303. NewPath = UnixExtractFilePath(UnixExcludeTrailingBackslash(NewPath));
  1304. PrevPath = ExtractFilePath(ExcludeTrailingBackslash(PrevPath));
  1305. }
  1306. NewPath = UnixIncludeTrailingBackslash(NewPath) +
  1307. ToUnixPath(LocalDirView->Path.SubString(PrevPath.Length() + 1,
  1308. LocalDirView->Path.Length() - PrevPath.Length()));
  1309. }
  1310. else
  1311. {
  1312. Abort();
  1313. }
  1314. if (Create)
  1315. {
  1316. CreateRemoteDirectory(UnixExcludeTrailingBackslash(NewPath));
  1317. }
  1318. RemoteDirView->Path = NewPath;
  1319. }
  1320. __finally
  1321. {
  1322. Terminal->ExceptionOnFail = false;
  1323. delete Paths;
  1324. }
  1325. }
  1326. //---------------------------------------------------------------------------
  1327. void __fastcall TScpCommanderForm::CreateLocalDirectory(const UnicodeString & Path)
  1328. {
  1329. DebugAssert(!IsLocalBrowserMode()); // Used for synchronized browsing only
  1330. UnicodeString Dir = ExtractFileDir(Path);
  1331. if (!Dir.IsEmpty() && !DirectoryExists(Dir))
  1332. {
  1333. CreateLocalDirectory(Dir);
  1334. }
  1335. LocalDirView->CreateDirectory(Path);
  1336. }
  1337. //---------------------------------------------------------------------------
  1338. void __fastcall TScpCommanderForm::SynchronizeBrowsingRemote(
  1339. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  1340. {
  1341. TStrings * Paths = new TStringList();
  1342. try
  1343. {
  1344. Paths->Add(UnixIncludeTrailingBackslash(PrevPath));
  1345. Paths->Add(UnixIncludeTrailingBackslash(RemoteDirView->Path));
  1346. UnicodeString CommonPath;
  1347. if (UnixExtractCommonPath(Paths, CommonPath))
  1348. {
  1349. PrevPath = UnixIncludeTrailingBackslash(PrevPath);
  1350. CommonPath = UnixIncludeTrailingBackslash(CommonPath);
  1351. UnicodeString NewLocalPath;
  1352. NewPath = ExcludeTrailingBackslash(LocalDirView->Path);
  1353. while (!UnixSamePath(PrevPath, CommonPath))
  1354. {
  1355. NewLocalPath = ExcludeTrailingBackslash(ExtractFileDir(NewPath));
  1356. if (NewLocalPath == NewPath)
  1357. {
  1358. Abort();
  1359. }
  1360. NewPath = NewLocalPath;
  1361. PrevPath = UnixExtractFilePath(UnixExcludeTrailingBackslash(PrevPath));
  1362. }
  1363. NewPath = IncludeTrailingBackslash(NewPath) +
  1364. ChangeFilePath(
  1365. RemoteDirView->Path.SubString(PrevPath.Length() + 1,
  1366. RemoteDirView->Path.Length() - PrevPath.Length()),
  1367. osRemote);
  1368. }
  1369. else
  1370. {
  1371. Abort();
  1372. }
  1373. }
  1374. __finally
  1375. {
  1376. delete Paths;
  1377. }
  1378. if (Create)
  1379. {
  1380. CreateLocalDirectory(ExcludeTrailingBackslash(NewPath));
  1381. }
  1382. LocalDirView->Path = NewPath;
  1383. }
  1384. //---------------------------------------------------------------------------
  1385. void __fastcall TScpCommanderForm::SynchronizeBrowsing(TCustomDirView * ADirView,
  1386. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  1387. {
  1388. if (ADirView == LocalDirView)
  1389. {
  1390. SynchronizeBrowsingLocal(PrevPath, NewPath, Create);
  1391. }
  1392. else
  1393. {
  1394. SynchronizeBrowsingRemote(PrevPath, NewPath, Create);
  1395. }
  1396. }
  1397. //---------------------------------------------------------------------------
  1398. void __fastcall TScpCommanderForm::SynchronizeBrowsing(TCustomDirView * ADirView)
  1399. {
  1400. UnicodeString PrevPath;
  1401. // cannot assign to UnicodeString before the class is constructed,
  1402. // if we do, the value get lost when UnicodeString constructor gets finally called,
  1403. // what results in memory leak in the best case
  1404. if (FConstructed)
  1405. {
  1406. PrevPath = FPrevPath[ADirView == LocalDirView];
  1407. FPrevPath[ADirView == LocalDirView] = ADirView->Path;
  1408. }
  1409. if (!FSynchronisingBrowse && NonVisualDataModule->SynchronizeBrowsingAction2->Checked &&
  1410. !PrevPath.IsEmpty() && PrevPath != ADirView->Path)
  1411. {
  1412. DebugAssert(!IsLocalBrowserMode());
  1413. TValueRestorer<bool> AllowTransferPresetAutoSelectRestorer(FAllowTransferPresetAutoSelect);
  1414. FAllowTransferPresetAutoSelect = false;
  1415. TValueRestorer<bool> SynchronisingBrowseRestorer(FSynchronisingBrowse);
  1416. 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(FLocalPathComboBoxPaths->Count == PathComboBox->Strings->Count);
  2179. DebugAssert(AIndex < FLocalPathComboBoxPaths->Count);
  2180. if (AIndex < 0)
  2181. {
  2182. AIndex = PathComboBox->ItemIndex;
  2183. }
  2184. if (AIndex >= 0)
  2185. {
  2186. ImageIndex = int(FLocalPathComboBoxPaths->Objects[AIndex]);
  2187. }
  2188. }
  2189. }
  2190. //---------------------------------------------------------------------------
  2191. void __fastcall TScpCommanderForm::LocalPathComboBoxAdjustImageIndex(
  2192. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  2193. int & ImageIndex)
  2194. {
  2195. DoLocalPathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  2196. }
  2197. //---------------------------------------------------------------------------
  2198. void __fastcall TScpCommanderForm::DoLocalPathComboBoxItemClick(TDirView * ADirView, TTBXComboBoxItem * PathComboBox)
  2199. {
  2200. DebugAssert(FLocalPathComboBoxPaths->Count == PathComboBox->Strings->Count);
  2201. DebugAssert((PathComboBox->ItemIndex >= 0) && (PathComboBox->ItemIndex < FLocalPathComboBoxPaths->Count));
  2202. UnicodeString Path = FLocalPathComboBoxPaths->Strings[PathComboBox->ItemIndex];
  2203. try
  2204. {
  2205. if (PathComboBox->ItemIndex >= FLocalSpecialPaths)
  2206. {
  2207. UnicodeString Drive = DriveInfo->GetDriveKey(Path);
  2208. TDirView * CurrentDirView = dynamic_cast<TDirView *>(DirView(osCurrent));
  2209. if (IsLocalBrowserMode() && (ADirView != CurrentDirView) &&
  2210. SamePaths(DriveInfo->GetDriveKey(CurrentDirView->PathName), Drive))
  2211. {
  2212. ADirView->Path = CurrentDirView->PathName;
  2213. }
  2214. else
  2215. {
  2216. ADirView->ExecuteDrive(Drive);
  2217. }
  2218. }
  2219. else
  2220. {
  2221. ADirView->Path = Path;
  2222. }
  2223. }
  2224. catch (...)
  2225. {
  2226. // Changing the path failed, reset the combo box back.
  2227. // Does not recurse, so infinite recursion should not happen.
  2228. DoLocalPathComboBoxItemClick(ADirView, PathComboBox);
  2229. throw;
  2230. }
  2231. }
  2232. //---------------------------------------------------------------------------
  2233. void __fastcall TScpCommanderForm::LocalPathComboBoxItemClick(TObject *)
  2234. {
  2235. DoLocalPathComboBoxItemClick(LocalDirView, LocalPathComboBox);
  2236. }
  2237. //---------------------------------------------------------------------------
  2238. void __fastcall TScpCommanderForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  2239. {
  2240. TCustomScpExplorerForm::ToolbarItemResize(Item, Width);
  2241. if ((Item == LocalPathComboBox) ||
  2242. (Item == RemotePathComboBox) ||
  2243. (Item == CommandLineCombo))
  2244. {
  2245. dynamic_cast<TTBXComboBoxItem *>(Item)->MinListWidth = Width - 4;
  2246. }
  2247. }
  2248. //---------------------------------------------------------------------------
  2249. void __fastcall TScpCommanderForm::CommandLineComboPopup(
  2250. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  2251. {
  2252. CommandLinePopulate();
  2253. }
  2254. //---------------------------------------------------------------------------
  2255. void __fastcall TScpCommanderForm::CommandLineComboBeginEdit(
  2256. TTBEditItem * /*Sender*/, TTBEditItemViewer * /*Viewer*/, TEdit *EditControl)
  2257. {
  2258. InstallPathWordBreakProc(EditControl);
  2259. FCommandLineComboEdit = EditControl;
  2260. FToolbarEditOldWndProc = EditControl->WindowProc;
  2261. EditControl->WindowProc = CommandLineComboEditWndProc;
  2262. }
  2263. //---------------------------------------------------------------------------
  2264. void __fastcall TScpCommanderForm::ExitToolbar()
  2265. {
  2266. CurrentPanel()->SetFocus();
  2267. }
  2268. //---------------------------------------------------------------------------
  2269. void __fastcall TScpCommanderForm::CommandLineComboEditWndProc(TMessage & Message)
  2270. {
  2271. bool Handled = false;
  2272. if (Message.Msg == WM_CHAR)
  2273. {
  2274. switch (reinterpret_cast<TWMChar &>(Message).CharCode)
  2275. {
  2276. case VK_ESCAPE:
  2277. CommandLineCombo->Text = L"";
  2278. ExitToolbar();
  2279. Handled = true;
  2280. break;
  2281. case VK_TAB:
  2282. CommandLineCombo->Text = FCommandLineComboEdit->Text;
  2283. ExitToolbar();
  2284. Handled = true;
  2285. break;
  2286. case VK_RETURN:
  2287. CommandLineCombo->Text = FCommandLineComboEdit->Text;
  2288. ExitToolbar();
  2289. if (!ExecuteCommandLine())
  2290. {
  2291. // re-enter command line
  2292. // (most probably exited by now as message dialog was shown)
  2293. GoToCommandLine();
  2294. }
  2295. Handled = true;
  2296. break;
  2297. }
  2298. }
  2299. if (!Handled)
  2300. {
  2301. FToolbarEditOldWndProc(Message);
  2302. }
  2303. }
  2304. //---------------------------------------------------------------------------
  2305. void __fastcall TScpCommanderForm::LocalDriveViewRefreshDrives(TObject * /*Sender*/)
  2306. {
  2307. LocalPathComboUpdateDrives();
  2308. LocalPathComboUpdate(LocalDirView, LocalPathComboBox);
  2309. if (IsLocalBrowserMode())
  2310. {
  2311. LocalPathComboUpdate(OtherLocalDirView, RemotePathComboBox);
  2312. }
  2313. }
  2314. //---------------------------------------------------------------------------
  2315. void __fastcall TScpCommanderForm::HomeDirectory(TOperationSide Side)
  2316. {
  2317. bool SynchronizeBrowsing = NonVisualDataModule->SynchronizeBrowsingAction2->Checked;
  2318. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  2319. TCustomScpExplorerForm::HomeDirectory(Side);
  2320. if (SynchronizeBrowsing)
  2321. {
  2322. TCustomScpExplorerForm::HomeDirectory(GetOtherSize(Side));
  2323. }
  2324. }
  2325. //---------------------------------------------------------------------------
  2326. void __fastcall TScpCommanderForm::QueueSubmenuItemPopup(
  2327. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  2328. {
  2329. NonVisualDataModule->QueueSpeedComboBoxItemUpdate(QueueSpeedComboBoxItem);
  2330. }
  2331. //---------------------------------------------------------------------------
  2332. void __fastcall TScpCommanderForm::DoFocusRemotePath(TTerminal * Terminal, const UnicodeString & Path)
  2333. {
  2334. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  2335. TCustomScpExplorerForm::DoFocusRemotePath(Terminal, Path);
  2336. }
  2337. //---------------------------------------------------------------------------
  2338. TOperationSide __fastcall TScpCommanderForm::GetOtherSize(TOperationSide Side)
  2339. {
  2340. Side = GetSide(Side);
  2341. return ReverseOperationSide(Side);
  2342. }
  2343. //---------------------------------------------------------------------------
  2344. void __fastcall TScpCommanderForm::HistoryGo(TOperationSide Side, int Index)
  2345. {
  2346. TOperationSide OtherSide = GetOtherSize(Side);
  2347. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked &&
  2348. ((Index < 0) ? (-Index < DirView(OtherSide)->BackCount) : (Index < DirView(OtherSide)->ForwardCount)))
  2349. {
  2350. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  2351. TCustomScpExplorerForm::HistoryGo(Side, Index);
  2352. TCustomScpExplorerForm::HistoryGo(OtherSide, Index);
  2353. }
  2354. else
  2355. {
  2356. TCustomScpExplorerForm::HistoryGo(Side, Index);
  2357. }
  2358. }
  2359. //---------------------------------------------------------------------------
  2360. void __fastcall TScpCommanderForm::DirViewHistoryGo(
  2361. TCustomDirView * Sender, int Index, bool & Cancel)
  2362. {
  2363. TOperationSide Side = (Sender == DirView(osRemote) ? osRemote : osLocal);
  2364. HistoryGo(Side, Index);
  2365. Cancel = true;
  2366. }
  2367. //---------------------------------------------------------------------------
  2368. bool __fastcall TScpCommanderForm::EligibleForImageDisplayMode(TTBCustomItem * Item)
  2369. {
  2370. return
  2371. TCustomScpExplorerForm::EligibleForImageDisplayMode(Item) &&
  2372. ((Item->Parent == NULL) || (Item->Parent->ParentComponent != Toolbar2Toolbar));
  2373. }
  2374. //---------------------------------------------------------------------------
  2375. bool __fastcall TScpCommanderForm::UpdateToolbarDisplayMode()
  2376. {
  2377. bool Result = TCustomScpExplorerForm::UpdateToolbarDisplayMode();
  2378. if (Result)
  2379. {
  2380. // command line combo width needs to be updated as caption visibility has changed
  2381. ToolBarResize(CommandLineToolbar);
  2382. }
  2383. return Result;
  2384. }
  2385. //---------------------------------------------------------------------------
  2386. void __fastcall TScpCommanderForm::QueueLabelUpdateStatus()
  2387. {
  2388. TCustomScpExplorerForm::QueueLabelUpdateStatus();
  2389. // this is here to deactivate panels path labels when moving focus from
  2390. // directory tree to queue
  2391. UpdatePanelsPathLabelsStatus();
  2392. }
  2393. //---------------------------------------------------------------------------
  2394. void __fastcall TScpCommanderForm::DoLocalDirViewContextPopup(TOperationSide Side, TPoint & MousePos, bool & Handled)
  2395. {
  2396. if (!WinConfiguration->ScpCommander.SystemContextMenu && !FForceSystemContextMenu)
  2397. {
  2398. DirViewContextPopupDefaultItem(Side, NonVisualDataModule->LocalOpenMenuItem, rdcaOpen, rdcaChangeDir);
  2399. DirViewContextPopupDefaultItem(Side, NonVisualDataModule->LocalEditMenuItem, rdcaEdit, rdcaNone);
  2400. if (IsLocalBrowserMode())
  2401. {
  2402. DirViewContextPopupDefaultItem(Side, NonVisualDataModule->LocalLocalCopyMenuItem, rdcaCopy, rdcaNone);
  2403. }
  2404. else
  2405. {
  2406. DirViewContextPopupDefaultItem(Side, NonVisualDataModule->LocalCopyMenuItem, rdcaCopy, rdcaNone);
  2407. }
  2408. DirViewContextPopup(Side, fcLocalPopup, MousePos);
  2409. Handled = true;
  2410. }
  2411. }
  2412. //---------------------------------------------------------------------------
  2413. void __fastcall TScpCommanderForm::LocalDirViewContextPopup(TObject *, TPoint & MousePos, bool & Handled)
  2414. {
  2415. DoLocalDirViewContextPopup(osLocal, MousePos, Handled);
  2416. }
  2417. //---------------------------------------------------------------------------
  2418. void __fastcall TScpCommanderForm::OtherLocalDirViewContextPopup(TObject *, TPoint & MousePos, bool & Handled)
  2419. {
  2420. DoLocalDirViewContextPopup(osOther, MousePos, Handled);
  2421. }
  2422. //---------------------------------------------------------------------------
  2423. void __fastcall TScpCommanderForm::DisplaySystemContextMenu()
  2424. {
  2425. TAutoFlag Flag(FForceSystemContextMenu);
  2426. if ((FLastContextPopupScreenPoint.x >= 0) && (FLastContextPopupScreenPoint.Y >= 0))
  2427. {
  2428. DirView(osCurrent)->DisplayContextMenu(FLastContextPopupScreenPoint);
  2429. }
  2430. else
  2431. {
  2432. DirView(osCurrent)->DisplayContextMenuInSitu();
  2433. }
  2434. }
  2435. //---------------------------------------------------------------------------
  2436. void __fastcall TScpCommanderForm::LocalStatusBarPanelClick(TTBXCustomStatusBar * /*Sender*/,
  2437. TTBXStatusPanel * Panel)
  2438. {
  2439. FileStatusBarPanelClick(Panel, osLocal);
  2440. }
  2441. //---------------------------------------------------------------------------
  2442. void __fastcall TScpCommanderForm::RemoteStatusBarPanelClick(TTBXCustomStatusBar * /*Sender*/,
  2443. TTBXStatusPanel *Panel)
  2444. {
  2445. FileStatusBarPanelClick(Panel, osRemote);
  2446. }
  2447. //---------------------------------------------------------------------------
  2448. void __fastcall TScpCommanderForm::GoToAddress()
  2449. {
  2450. OpenDirectory(GetSide(osCurrent));
  2451. }
  2452. //---------------------------------------------------------------------------
  2453. void __fastcall TScpCommanderForm::RemotePathLabelMaskClick(TObject * /*Sender*/)
  2454. {
  2455. Filter(osRemote);
  2456. }
  2457. //---------------------------------------------------------------------------
  2458. void __fastcall TScpCommanderForm::LocalPathLabelMaskClick(TObject * /*Sender*/)
  2459. {
  2460. Filter(osLocal);
  2461. }
  2462. //---------------------------------------------------------------------------
  2463. void __fastcall TScpCommanderForm::LocalOpenDirButtonPopup(TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  2464. {
  2465. CreateOpenDirMenu(LocalOpenDirButton, osLocal);
  2466. }
  2467. //---------------------------------------------------------------------------
  2468. void __fastcall TScpCommanderForm::RemoteOpenDirButtonPopup(TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  2469. {
  2470. CreateOpenDirMenu(RemoteOpenDirButton, osRemote);
  2471. }
  2472. //---------------------------------------------------------------------------
  2473. void __fastcall TScpCommanderForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  2474. {
  2475. if (IsSideLocalBrowser(Side))
  2476. {
  2477. TInstantOperationVisualizer Visualizer;
  2478. dynamic_cast<TDirView *>(DirView(Side))->CopyToClipBoard(OnFocused);
  2479. }
  2480. else
  2481. {
  2482. TCustomScpExplorerForm::CopyFilesToClipboard(Side, OnFocused);
  2483. }
  2484. }
  2485. //---------------------------------------------------------------------------
  2486. void __fastcall TScpCommanderForm::PasteFromClipBoard()
  2487. {
  2488. if (DoesClipboardContainOurFiles() && (IsSideLocalBrowser(osCurrent)))
  2489. {
  2490. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  2491. {
  2492. ClipboardDownload(DirView(osCurrent)->Path, !WinConfiguration->ConfirmTransferring, false);
  2493. }
  2494. }
  2495. else
  2496. {
  2497. TCustomScpExplorerForm::PasteFromClipBoard();
  2498. }
  2499. }
  2500. //---------------------------------------------------------------------------
  2501. void __fastcall TScpCommanderForm::FileColorsChanged()
  2502. {
  2503. TCustomScpExplorerForm::FileColorsChanged();
  2504. DoFileColorsChanged(LocalDirView);
  2505. DoFileColorsChanged(OtherLocalDirView);
  2506. }
  2507. //---------------------------------------------------------------------------
  2508. void __fastcall TScpCommanderForm::BrowseFile()
  2509. {
  2510. DebugAssert(!IsLocalBrowserMode());
  2511. TCustomScpExplorerForm::BrowseFile();
  2512. if (LocalDirView->ItemFocused != NULL)
  2513. {
  2514. LocalDirView->ItemFocused->Selected = true;
  2515. }
  2516. TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
  2517. // Select the panel that has the file, with preference on the remote panel
  2518. if (RemoteDirView->ItemFocused->Selected)
  2519. {
  2520. ScpCommander.CurrentPanel = osRemote;
  2521. }
  2522. else if (LocalDirView->ItemFocused->Selected)
  2523. {
  2524. ScpCommander.CurrentPanel = osLocal;
  2525. }
  2526. WinConfiguration->ScpCommander = ScpCommander;
  2527. }
  2528. //---------------------------------------------------------------------------
  2529. void __fastcall TScpCommanderForm::ThemeChanged()
  2530. {
  2531. TCustomScpExplorerForm::ThemeChanged();
  2532. LocalDirView->Perform(WM_THEMECHANGED, 0, 0);
  2533. OtherLocalDirView->Perform(WM_THEMECHANGED, 0, 0);
  2534. }
  2535. //---------------------------------------------------------------------------
  2536. void __fastcall TScpCommanderForm::OtherLocalDirViewEnter(TObject *)
  2537. {
  2538. // Actually identical to LocalDirViewEnter
  2539. SideEnter(osOther);
  2540. }
  2541. //---------------------------------------------------------------------------
  2542. void __fastcall TScpCommanderForm::OtherLocalDriveViewEnter(TObject *)
  2543. {
  2544. MakeNextInTabOrder(OtherLocalDirView, OtherLocalDriveView);
  2545. SideEnter(osOther);
  2546. }
  2547. //---------------------------------------------------------------------------
  2548. void __fastcall TScpCommanderForm::DoRemotePathComboBoxAdjustImageIndex(
  2549. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex, int & ImageIndex)
  2550. {
  2551. if (!IsLocalBrowserMode())
  2552. {
  2553. TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  2554. }
  2555. else
  2556. {
  2557. DoLocalPathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  2558. }
  2559. }
  2560. //---------------------------------------------------------------------------
  2561. void __fastcall TScpCommanderForm::DoRemotePathComboBoxCancel(TObject * Sender)
  2562. {
  2563. if (!IsLocalBrowserMode())
  2564. {
  2565. TCustomScpExplorerForm::DoRemotePathComboBoxCancel(Sender);
  2566. }
  2567. else
  2568. {
  2569. LocalPathComboUpdate(OtherLocalDirView, RemotePathComboBox);
  2570. }
  2571. }
  2572. //---------------------------------------------------------------------------
  2573. void __fastcall TScpCommanderForm::OtherLocalDirViewPathChange(TCustomDirView * Sender)
  2574. {
  2575. // should happen only when called from TScpCommanderForm::DoShow while starting connected
  2576. if (IsLocalBrowserMode())
  2577. {
  2578. DebugUsedParam(Sender);
  2579. DebugAssert(Sender == OtherLocalDirView);
  2580. UpdateRemotePathComboBox(!FSessionChanging);
  2581. }
  2582. }
  2583. //---------------------------------------------------------------------------
  2584. void __fastcall TScpCommanderForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  2585. {
  2586. if (!IsLocalBrowserMode())
  2587. {
  2588. TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(Sender);
  2589. }
  2590. else
  2591. {
  2592. DoLocalPathComboBoxItemClick(OtherLocalDirView, RemotePathComboBox);
  2593. }
  2594. }
  2595. //---------------------------------------------------------------------------
  2596. void __fastcall TScpCommanderForm::UpdateRemotePathComboBox(bool TextOnly)
  2597. {
  2598. if (!IsLocalBrowserMode())
  2599. {
  2600. TCustomScpExplorerForm::UpdateRemotePathComboBox(TextOnly);
  2601. }
  2602. else
  2603. {
  2604. if (!TextOnly)
  2605. {
  2606. RemotePathComboBox->Strings->Assign(LocalPathComboBox->Strings);
  2607. }
  2608. LocalPathComboUpdate(OtherLocalDirView, RemotePathComboBox);
  2609. }
  2610. }
  2611. //---------------------------------------------------------------------------
  2612. void __fastcall TScpCommanderForm::LocalDriveViewNeedHiddenDirectories(TObject *)
  2613. {
  2614. if (DebugAlwaysTrue(!WinConfiguration->ShowHiddenFiles))
  2615. {
  2616. ToggleShowHiddenFiles();
  2617. }
  2618. }
  2619. //---------------------------------------------------------------------------
  2620. void TScpCommanderForm::LocalLocalCopy(
  2621. ::TFileOperation Operation, TOperationSide Side, bool OnFocused, bool NoConfirmation, bool DragDrop, unsigned int Flags)
  2622. {
  2623. std::unique_ptr<TFileOperator> FileOperator(new TFileOperator(NULL));
  2624. bool Move;
  2625. switch (Operation)
  2626. {
  2627. case ::foCopy:
  2628. FileOperator->Operation = Fileoperator::foCopy;
  2629. Move = false;
  2630. break;
  2631. case ::foMove:
  2632. FileOperator->Operation = Fileoperator::foMove;
  2633. Move = true;
  2634. break;
  2635. default:
  2636. DebugFail();
  2637. Abort();
  2638. }
  2639. TOperationSide OtherSide = GetOtherSide(GetSide(Side));
  2640. TCustomDirView * SourceDirView = DirView(Side);
  2641. UnicodeString DestinationDir = DirView(OtherSide)->PathName;
  2642. SourceDirView->CreateFileList(OnFocused, true, FileOperator->OperandFrom);
  2643. int OutputOptions =
  2644. FLAGMASK(GetDoNotShowCopyDialogDefault(DragDrop), clooDoNotShowAgain);
  2645. bool MultipleFiles = (FileOperator->OperandFrom->Count > 1);
  2646. int Options =
  2647. FLAGMASK(FLAGSET(Flags, cocShortCutHint), cloShortCutHint) |
  2648. FLAGMASK(MultipleFiles, cloMultipleFiles);
  2649. UnicodeString FileMask = AnyMask;
  2650. bool Confirmed =
  2651. NoConfirmation ||
  2652. DoCopyLocalDialog(Move, Options, DestinationDir, FileMask, OutputOptions);
  2653. if (Confirmed)
  2654. {
  2655. HandleDoNotShowCopyDialogAgain(DragDrop, FLAGSET(OutputOptions, clooDoNotShowAgain));
  2656. FileOperator->Flags = FileOperator->Flags << foMultiDestFiles;
  2657. if (!WinConfiguration->ConfirmOverwriting)
  2658. {
  2659. FileOperator->Flags = FileOperator->Flags << foNoConfirmation;
  2660. }
  2661. if (Move)
  2662. {
  2663. Configuration->Usage->Inc(L"LocalLocalMovesCommand");
  2664. }
  2665. else
  2666. {
  2667. Configuration->Usage->Inc(L"LocalLocalCopiesCommand");
  2668. }
  2669. for (int Index = 0; Index < FileOperator->OperandFrom->Count; Index++)
  2670. {
  2671. UnicodeString SourcePath = FileOperator->OperandFrom->Strings[Index];
  2672. UnicodeString FileName = TPath::GetFileName(SourcePath);
  2673. FileName = MaskFileName(FileName, FileMask);
  2674. UnicodeString DestinationPath = TPath::Combine(DestinationDir, FileName);
  2675. FileOperator->OperandTo->Add(DestinationPath);
  2676. }
  2677. SourceDirView->ClearSelection();
  2678. {
  2679. TAutoBatch AutoBatch(this);
  2680. FileOperator->Execute();
  2681. }
  2682. ReloadLocalDirectory(DestinationDir);
  2683. if (Operation == ::foMove)
  2684. {
  2685. UnicodeString SourceDir = SourceDirView->PathName;
  2686. if (!SamePaths(SourceDir, DestinationDir))
  2687. {
  2688. ReloadLocalDirectory(SourceDir);
  2689. }
  2690. }
  2691. }
  2692. }
  2693. //---------------------------------------------------------------------------
  2694. UnicodeString TScpCommanderForm::GetLocalBrowserSessionTitle(TManagedTerminal * ASession)
  2695. {
  2696. UnicodeString Result;
  2697. if (ASession->SessionData->HasSessionName())
  2698. {
  2699. Result = ASession->SessionData->SessionName;
  2700. }
  2701. else
  2702. {
  2703. DebugAssert(ASession->LocalBrowser);
  2704. UnicodeString Path1;
  2705. UnicodeString Path2;
  2706. TTerminalManager * Manager = TTerminalManager::Instance();
  2707. // might use GetSessionPath here
  2708. if ((ASession == ManagedSession) &&
  2709. // prevent tab title flicker, when switching to local-local tab, as the path changes in individual local panels
  2710. !FSessionChanging)
  2711. {
  2712. Path1 = LocalDirView->PathName;
  2713. Path2 = OtherLocalDirView->PathName;
  2714. }
  2715. else
  2716. {
  2717. Path1 = ASession->StateData->LocalDirectory;
  2718. Path2 = ASession->StateData->OtherLocalDirectory;
  2719. }
  2720. // See also TSessionData::GetDefaultSessionName()
  2721. Path1 = Manager->GetPathForSessionTabName(ExtractShortName(Path1, false));
  2722. Path2 = Manager->GetPathForSessionTabName(ExtractShortName(Path2, false));
  2723. Result = Path1 + TitleSeparator + Path2;
  2724. }
  2725. return Result;
  2726. }
  2727. //---------------------------------------------------------------------------
  2728. int TScpCommanderForm::GetNewTabActionImageIndex()
  2729. {
  2730. return WinConfiguration->DefaultToNewRemoteTab ?
  2731. TCustomScpExplorerForm::GetNewTabActionImageIndex() : NonVisualDataModule->NewLocalTabAction->ImageIndex;
  2732. }
  2733. //---------------------------------------------------------------------------
  2734. int TScpCommanderForm::GetNewTabTabImageIndex(TOperationSide Side)
  2735. {
  2736. if (Side == osCurrent)
  2737. {
  2738. Side = WinConfiguration->DefaultToNewRemoteTab ? osRemote : osLocal;
  2739. }
  2740. return TCustomScpExplorerForm::GetNewTabTabImageIndex(Side);
  2741. }
  2742. //---------------------------------------------------------------------------
  2743. UnicodeString TScpCommanderForm::GetTabHintDetails(TManagedTerminal * ASession)
  2744. {
  2745. UnicodeString Result;
  2746. if (!ASession->LocalBrowser)
  2747. {
  2748. Result = GetTabHintSessionDetails(ASession);
  2749. }
  2750. if (!ASession->LocalBrowser && !ASession->Active)
  2751. {
  2752. Result += LoadStr(STATUS_NOT_CONNECTED2);
  2753. }
  2754. else
  2755. {
  2756. UnicodeString Local = GetSessionPath(ASession, osLocal);
  2757. UnicodeString Other = GetSessionPath(ASession, osOther);
  2758. // Contrary to Panel(), the IsRightToLeft() is not considered here,
  2759. // as I assume they expect the right panel first, as they read from the right.
  2760. UnicodeString Sep = L"\n";
  2761. if (!WinConfiguration->ScpCommander.SwappedPanels)
  2762. {
  2763. Result += Local + Sep + Other;
  2764. }
  2765. else
  2766. {
  2767. Result += Other + Sep + Local;
  2768. }
  2769. }
  2770. return Result;
  2771. }
  2772. //---------------------------------------------------------------------------
  2773. UnicodeString TScpCommanderForm::GetNewTabHintDetails()
  2774. {
  2775. UnicodeString Result;
  2776. if (WinConfiguration->DefaultToNewRemoteTab)
  2777. {
  2778. Result = TCustomScpExplorerForm::GetNewTabHintDetails();
  2779. Result = FMTLOAD(NEW_REMOTE_TAB_CTRL_HINT, (Result));
  2780. }
  2781. else
  2782. {
  2783. Result = LoadStr(NEW_LOCAL_TAB_HINT);
  2784. }
  2785. return Result;
  2786. }
  2787. //---------------------------------------------------------------------------
  2788. bool TScpCommanderForm::SupportedSession(TSessionData *)
  2789. {
  2790. return true;
  2791. }