ScpCommander.cpp 106 KB

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