ScpCommander.cpp 102 KB

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