ScpCommander.cpp 107 KB

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