ScpCommander.cpp 101 KB

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