ScpCommander.cpp 103 KB

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