ScpCommander.cpp 107 KB

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