ScpCommander.cpp 101 KB

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