ScpCommander.cpp 102 KB

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