ScpCommander.cpp 106 KB

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