ScpCommander.cpp 108 KB

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